Showing posts with label COM. Show all posts
Showing posts with label COM. Show all posts

Friday, August 26, 2011

Say, you need to return an array of strings from a COM "interop" object implemented on C# to be able then access to its items from a code on VBScript.

The only correct way to do that is make the method to return the VARIANT which is an array of VARIANTs, not strings.
In other words, the return value of the VBScript's VarType() function has to be 0x200C, not 0x2008 ! Only then VBScript will be able to access the array's members.

In the C# terms, you need to make the code look like follows:


public Object f() { // the function returns (VARIANT *)
Object[] a = new Object[3]; // which is an array of VARIANTs
a[0] = "a"; // each of them contains a string
a[1] = "b";
a[2] = "c";
return a;
}

Friday, April 8, 2011

COM to .NET

How to make a .NET class library be accessible as a COM object?
  1. Create a new .net class library project for the wrapper
  2. Declare the class as "ComVisible":
    using System.Runtime.InteropServices;
    [ComVisible( true )] public class ClassName
  3. Generate the Keyfile:
    C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin\sn.exe -k "keyfile.snk"
  4. Set the project property to sign the library using the generated keyfile
  5. Generate the Registry entry with the path to the library .dll as the "codebase":
    regasm.exe %TRGDIR%\LibName.dll /codebase
    Specify also the /tlb option if the library is to be imported by the C++ #import directive
  6. Check the registry has the ProgId: LibName.ClassName and refers to the CLSID which has the "codebase" path to the LibName.dll

Wednesday, July 28, 2010

MSXML error

Suddenly an attempt to instantiate a "Msxml2.ServerXMLHTTP" object on a workstation begin to lead to the "ClassFactory cannot supply requested class" message.
Just "Msxml2.XMLHTTP" works though.