wwDotnetBridge

.NET Interop for Visual FoxPro made easy

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:

  • Access most .NET Components directly
  • Requires no COM Registration for .NET Objects
  • Create types with parameterized constructors
  • Support for many natively unsupported .NET types and values
  • Access static method/members, structs, binary data, guids, DbNulls
  • Call overloaded methods
  • Automatically fixes up problematic
  • .NET Types Provides easy Array access with
  • ComArray helper class
  • ComValue structure to help with
  • .NET TypeConversions
  • Ability to keep values entirely in .NET with ComValue
  • Assign values directly to properties without passing through FoxPro
  • Multi-threading library built-in

A few quick Examples

Here is what .NET access from FoxPro with wwDotnetBridge looks like.

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
        
You can also call static methods in the core .NET runtime libraries without having to load anything explicitly:
loBridge = CreateObject("wwDotNetBridge","V4")
? loBridge.InvokeStaticMethod("System.Net.NetworkInformation.NetworkInterface",;
                              "GetIsNetworkAvailable")
You can access enums and walk through collections, even generic collections. The following example demonstrates how to write to the Windows Event Log:
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
And this is only a small portion of what's available. You can find out more by checking out the white paper that explains COM Interop with .NET and how wwDotnetBridge greatly improves what's possible when accessing .NET code.

© West Wind Technologies, 2007-2013
Version 5.65
Sept. 25th, 2012
Get the code from
You can download a complete Zip file, browse the source online, or use GIT to Clone the repository to your local machine.
This 40 page white paper covers basic COM Interop from FoxPro to .NET and demonstrates how wwDotnetBridge improves upon native COM interop by opening up most of .NET to your FoxPro applications.
This library is now open source under MIT license and free to use and modify in your applications as you see fit.
Internet & Client Tools
If you prefer a commercially licensed and fully supported version of wwDotnetBridge, or if you simply want to support the development of this product, you can also purchase a license for the West Wind Internet and Client Tools or West Wind Web Connection, which also include wwDotnetBridge.
to register your copy.
The full documentation for these tools are available online. You can also find this documentation provided as a CHM file with the full download of the library.
Got a problem or can't figure out how something works? Try our support forum. We're here to help you get started and want to hear if something doesn't work as expected or - gulp - doesn't work correctly. We welcome your questions and feedback which in turn helps us provide a better product. See you there.