Error calling DLL code from VBScript

Back again with a specific bug...

I have customized the Save Event in the frmBatch object in the Process Receipt of Good form:

Sub Form_Save(oDM, bSave)
    Dim objApp, result
    Set objApp = CreateObject("LMNO.PrintNewLabel.FormSave")
    result = objApp.PrintBatchLabels
    msgbox result
    bSave = true
End Sub

So I have created (what I believe to be) a .NET COM assembly using this page (the only thing PrintBatchLabels() does is return true), and have run regasm.exe on the DLL. I have tried placing the .dll file in both C:\Windows\SysWOW64\ and C:\Program Files (x86)\Sage Software\Sage MAS 500 Client\ (Running Sage 500 ERP 2014 July 2015 Update (Version 7.60.7.0) on Windows 10 Pro x64 v1607), but with both locations I get this error upon Save:

clsFormCustRT.OnSave:
-2147024894 Method '~' of object '~' failed

(I am trying to avoid adding the DLL to the GAC.) What am I missing here?

  • 0
    Here is a link to a Microsoft article to how to late bind to an object using VB .NET. They use Excel in their example, but you can use the same principal to see if you can late bind to your COM Compliant assembly. msdn.microsoft.com/.../0tcf61s1(v=vs.140).aspx
  • 0 in reply to LouDavis
    I'm a little confused here - are you saying my DLL is not set up to "late bind" correctly?

    I actually just did another test with my DLL nowhere in a Sage exe location, and I get the same error. Looks like the system can't find my DLL. What is the right dir to put the DLL in - or am I forced to install it in the GAC?
  • 0 in reply to cgtyoder
    You are confusing COM Objects with Assemblies. Placing your Assembly in the GAC will not make it visible to COM and vbScript. As mentioned before vbScript doesn't work with .NET Assemblies. It can only work with COM objects. However, since vbScript is a cutdown version of Visual Basic 6, you can't set references to COM objects to do early binding. To instantiate a COM object in vbScript you have to use Late Binding (www.net-informations.com/.../binding.htm). As I am guessing you don't have Visual Basic 6 handy to test instantiating your COM-Compliant .NET Assembly, I figured that the article on how to do late binding in .NET might help you troubleshoot the issue a bit easier than using vbScript. Another way to test if your .NET Assembly is truly COM Compliant might be to try to instantiate as a COM object in a .NET program using early binding. Here's an article on how you can possibly do that msdn.microsoft.com/.../ms973800.aspx
  • 0 in reply to LouDavis

    Lou, thanks for the info. I did find where to stash the DLL so Sage 500 could find it. Since it's being called by the Enter Receipt of Goods form, that translates to the poztl001.exe executable, located in C:\Program Files (x86)\Sage Software\Sage MAS 500 Client\PO\. Once I dropped it in that dir, the call to PrintBatchLabels() was made successfully, and I have full .NET functionality (e.g. creating new windows, etc). Thanks again for the pointers.