none
Accessing 64 bit dll from vbscript

    Question

  • Hi all,

    a development requirement has been assigned to me, in that requirement, a vbscript should consume a 64bit .net dll.

    The script works in 32 bits, and the first problem is registering the 64bit dll.

    The second problem is use a vbs Createobject statement, to instantiate  the dll.

    Both problems return error.

    Can anybody help me?

    jam

    Thursday, January 26, 2017 1:14 PM

All replies

  • Hi,

    Follow these steps:

    1) Create a Class Library named ClassLibrary1.dll with this code:

    namespace ClassLibrary1
    {
       [System.Runtime.InteropServices.ComVisible(true)]
       [System.Runtime.InteropServices.ProgId("ClassLibrary1.Class1")]
       public class Class1
        {
          public void f1()
          {
             System.Windows.Forms.MessageBox.Show(System.IntPtr.Size.ToString());
          }
        }
    }

    2) In Project properties, Build tab, set Platform Target = x64 and ensure that "Register for COM Interop" checkbox is NOT checked (we will register the dll manually for 64-bit in step 6)

    3) In Project properties, Signing tab, sign the assembly with a new or existing .snk file

    4) Build the dll

    5) Open a Command Prompt with admin rights

    6) Execute this to register the dll as a 64-bit COM component:

    "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\regasm.exe" /codebase "<path>\classlibrary1.dll"

    You should get a message "Types registered successfully"

    7) Create a test.vbs script with this code:

    Dim o
    Set o = CreateObject("ClassLibrary1.Class1")
    Call o.f1

    8) Execute it with the VBScript 64-bit (which uses the folder system32; for 32-bit it would use the folder  syswow64):

    C:\windows\system32\cscript.exe <path>\test.vbs

    You should get a MessageBox with the value 8, which means that the pointer size of the dll is 64 bit


    My portal and blog about VSX: http://www.visualstudioextensibility.com<br/> Twitter: https://twitter.com/VSExtensibility<br/> MZ-Tools productivity extension for Visual Studio: https://www.mztools.com


    Thursday, January 26, 2017 3:59 PM