Access a custom .NET DLL in VBScript

前端 未结 5 1047
耶瑟儿~
耶瑟儿~ 2020-12-14 13:09

I wrote a DLL in .NET and I want to access it in VBScript. I don\'t want to add it to the assembly directory.

Is there a way to point too the DLL and create an inst

5条回答
  •  悲&欢浪女
    2020-12-14 13:29

    I just had to do this myself, my findings were:

    Making types visible to COM:

    1. Ensure your class is public, non-static and has a public default constructor i.e. not arguments.
    2. Ensure your method is public, non-static.
    3. Ensure you have the following set on your assembly - typically in AssemblyInfo.cs

      [assembly: ComVisible(true)]
      
    4. After building your DLL, from SDK command line run:

      regasm yourdll.dll
      

      This should respond:

      Types registered successfully

      If you get

      RegAsm: warning RA0000: No types were registered

      then you need to set ComVisible or have no public, non-static types.

    From PowerShell

    $a = New-Object -comobject Your.Utils.Logging
    $a.WriteError2("Application", "hello",1,1)
    

    From vbs

    Set logger = CreateObject("Your.Utils.Logging")
    logger.WriteError2 "Application", "hello from vbs",1,1 
    

提交回复
热议问题