FoxPro and .NET Interop
Call DLL with wwDotNetBridge
Gravatar is a globally recognized avatar based on your email address. Call DLL with wwDotNetBridge
  Harry
  All
  Jul 1, 2021 @ 08:38am

I have been tasked with changing some old VFP code to use a library called HEDSS-AWS-SES.dll with two dependencies (AWSSDK.Core.dll and AWSSDK.SimpleEmail.dll). It is designed to send mail via Amazon SES. I assume it does more than that but my only concern is calling it and running an internal function called SendEmail(). I'm trying to use wwDotNetBridge to load it but have had no luck. Am I going down the wrong road or is the problem with the library? Here is my VFP code:

LOCAL loBridge as wwDotNetBridge
loBridge = CreateObject("wwDotNetBridge","V4")

*** Load assembly - no error here (I have also tried loading the dependent files)
IF !loBridge.LoadAssembly("HEDSS-AWS-SES.dll")
   WAIT wind loBridge.cErrorMsg
ENDIF

LOCAL loSesMail as HEDSS-AWS-SES.EmailService.Instance

*- But, CreateInstance errs with:
*- "Type not loaded. Please call LoadAssembly first."
loSesMail = loBridge.CreateInstance("HEDSS-AWS-SES.EmailService.Instance")
IF loBridge.lError
   WAIT wind loBridge.cErrorMsg
ENDIF

The guy who wrote it says that calling it is as simple as:

var email = new Email("Test Recipient", "myemail@gmail.com", "Cool Subject", "<p>This test email was sent from Healthcare Environment</p>", "This test email was sent from HCE", false);

var response = EmailService.Instance.SendEmail(email);

 
Gravatar is a globally recognized avatar based on your email address. re: Call DLL with wwDotNetBridge
  Rick Strahl
  Harry
  Jul 1, 2021 @ 09:54am

Well you need to find out what hte signature of the component is. It looks like the example you've been given passes in a bunch of parameters into the constructor of the object, so you need to pass those same parameters when you call CreateInstance().

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Call DLL with wwDotNetBridge
  Harry
  Rick Strahl
  Jul 1, 2021 @ 04:31pm

Rick, are you saying that I need to pass the actual values of the parameters to CreateInstance() or names of the properties or the types or what? I have been away from this stuff for a while so it's a bit greek to me. CreateInstance() does not accept enough parameters to accomodate the function in question.

Gravatar is a globally recognized avatar based on your email address. re: Call DLL with wwDotNetBridge
  Rick Strahl
  Harry
  Jul 1, 2021 @ 04:48pm

Sorry CreateInstance only supports 5 parameters.

wwDotnetBridge::CreateInstance

But... you should check the signatures available. Most .NET Components have other constructor overloads that have fewer parameters (or none) that can be used.

Gravatar is a globally recognized avatar based on your email address. re: Call DLL with wwDotNetBridge
  Harry
  Harry
  Jul 1, 2021 @ 07:38pm

You are correct that there are multiple constructor overloads available, but CreateInstance() still errs.

Gravatar is a globally recognized avatar based on your email address. re: Call DLL with wwDotNetBridge
  Rick Strahl
  Harry
  Jul 1, 2021 @ 09:39pm

Don't know without more info. Most likely the type info is wrong. Check the error message after the call.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: Call DLL with wwDotNetBridge
  Harry
  Rick Strahl
  Jul 2, 2021 @ 09:38am

Well, I had a mistake in SET PATH so the DLL was not actually loading. Oddly, it did not throw an error. However, after I corrected the path reference, during LoadAssembly() I get the error "Cannot find entry point SetClrVersion in the DLL.". If I ignore the error Windows tries to install ".NET Framework 3.5" but fails. It looks to me like it is installed...

Gravatar is a globally recognized avatar based on your email address. re: Call DLL with wwDotNetBridge
  Rick Strahl
  Harry
  Jul 2, 2021 @ 02:56pm

Sorry I don't know... without looking at the actual component.

From the sounds of it there's likely a required dependency that's not available. If it's trying to install .NET 3.5 that's referencing something that's not in v4+ (and I can't think of what that might be).

You might also want to make sure you're running a current version of wwDotnetBridge. If you're using a really old version that's expecting to run on Framework 2.0 that might also trigger that download request because Windows 10 doesn't install .NET Framework 2.0 any longer.

© 1996-2021