Do you need to access .NET code from Visual FoxPro 9? Then check out wwDotnetBridge and get ready to interface with just about any .NET component from your FoxPro code. wwDotnetBridge is a free and open source library to host the .NET Runtime in Visual FoxPro 9.0 and provide helper services to access .NET components directly. Using wwDotnetBridge you can host the .NET runtime and access .NET components without requiring COM registration and access many features of .NET that are unavailable using 'standard' .NET COM Interop.
wwDotnetBridge is available as an open source project with full source code on GitHub. Alternatively if you require a commercial license, require full featured support, or simply want to show your support for this project, you can also purchase commercial version as part of the West Wind Internet and Client Tools library or the West Wind Web Service Proxy Generator both of which include wwDotnetBridge.
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