Do you need to access .NET code from Visual FoxPro 9? Then let wwDotnetBridge help you to interface with just about any .NET component from your FoxPro code. wwDotnetBridge is a free and open source .NET Runtime hosting engine and .NET access helper for Visual FoxPro. It allows hosting of the .NET runtime in your FoxPro applications, and can access .NET components without having to register those components for COM first. This opens up most of the .NET framework and .NET 3rd party libraries to your code.
This library provides the following enhancements over plain COM Interop:
This example loads a third party .NET assembly (OpenPop) and loops through a POP3 mailbox using FoxPro code:
*** Load library and initialize wwDotnetBridge do wwDotNetBridge LOCAL loBridge as wwDotNetBridge loBridge = CreateObject("wwDotNetBridge") *** Load an assembly from disk loBridge.LoadAssembly("bin\OpenPop.dll") *** Create an instance of a class - note: No COM registration loPop = loBridge.CreateInstance("OpenPop.Pop3.Pop3Client") *** This won't work due to overloads * loPop.Connect("pop3.server.net",587,.f.) *** So, call indirectly instead ? loBridge.InvokeMethod(loPop,"Connect","pop3.server.net",110,.f.) *** Most methods/members do work directly ? loPop.Authenticate("jb007","seekrit") lnCount = loPop.GetMessageCount() ? StringFormat("{0} Messages",lnCount) *** NOTE: OpenPop is 1 based because pop3 is 1 based! ** show last messages FOR lnX = lnCount TO 1 STEP -1 loHeader = loPop.GetMessageHeaders(lnx) ? loHeader.From.DisplayName ? " " + loHeader.Subject ? IF lnX < lnCount - 10 EXIT ENDIF ENDFOR
loBridge = CreateObject("wwDotNetBridge","V4") ? loBridge.InvokeStaticMethod("System.Net.NetworkInformation.NetworkInterface",; "GetIsNetworkAvailable")
loBridge = CreateObject("wwDotNetBridge","V4") lcSource = "FoxProEvents" lcLogType = "Application" IF !loBridge.Invokestaticmethod("System.Diagnostics.EventLog",; "SourceExists","FoxProEvents") loBridge.Invokestaticmethod("System.Diagnostics.EventLog",; "CreateEventSource",; "FoxProEvents","Application") ENDIF *** Write out default message - Information * public static void WriteEntry(string source, string message) loBridge.Invokestaticmethod("System.Diagnostics.EventLog",; "WriteEntry",lcSource,; "Logging from FoxPro " + TRANSFORM(DATETIME()) ) *** To use a special event log type we need to specify an enum *** Because this method is heavily overloaded it doesn't work *** Instead create a ComValue object from enum and pass that loValue = loBridge.CreateComValue() loValue.SetEnum("System.Diagnostics.EventLogEntryType.Error") loBridge.Invokestaticmethod("System.Diagnostics.EventLog",; "WriteEntry",; lcSource,; "Logging error from FoxPro " + TRANSFORM(DATETIME()),; loValue, 10 ) *** *** Now Display Event Log Entries *** loEventLog = loBridge.Createinstance("System.Diagnostics.EventLog") loEventLog.Source = lcSource loEventLog.Log = "Application" *** Turn Eventlog Entries into a ComArray Class *** Indirect access automatically turns .NET array into ComArray loEvents = loBridge.GetProperty(loEventLog,"Entries") ? "Entries: " + loEvents.Count lnTo = MIN(loEvents.Count,10) FOR lnX = loEvents.Count-1 TO loEvents.Count-lnTo STEP -1 loEvent = loEvents.Item(lnX) && ComArray Items method ? loEvent.message ? ENDFOR