wwDotnetBridge

.NET Interop for Visual FoxPro made easy

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.

Free and Open Source or Commercial

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.

wwDotnetBridge Features

  • Host the .NET Runtime directly inside of Visual FoxPro
  • Instantiate most .NET components directly
  • Requires no COM Registration for .NET objects instantiation
  • 100% compatible with 'standard' COM Interop functionality
    just use wwDotnetBridge features for additional functionality
  • Create types with parameterized constructors
  • Call overloaded methods with their orignal names (no COM renaming)
  • Assign values directly to properties inside of .NET without passing through FoxPro
  • Support for many natively unsupported .NET types and values
    • Call and access static method, members and enums
    • Access value types and structs
    • Access Generic .NET types
    • AcAccess and convert binary data, guids, DbNulls, various number formats
    • ComValue class helps with .NET type conversions
  • Provides clean .NET Array and Collection Support
  • Arrays are auto-converted to ComArrays
  • Receive, update and pass arrays between FoxPro and .NET
  • ComArray provides easy element creation and manipulation
  • ComArray doesn't marshall the array to FoxPro - array stays in .NET
  • Multi-threading library built-in
What wwDotnetBridge isn't
  • A tool to use .NET visual components

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, 2004-2024
Version 5.67
Oct. 15th, 2013
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.