Interop - Best way to expose existing .Net classes, etc RRS feed

  • Question

  • Hi all.  Sorry if this is covered already - but I can't find any reference to it.  I've been working on exposing a (vb).Net  component to COM.  The ABC's of it are well documented enough.  Here's the hitch...

    The components being encapsulated are expecting (for example) a .Net Struct (System.Windows.Forms.Message) to be passed in.

    How can one best deal with this situation?

    Thanks greatly in advance!
    Wednesday, December 2, 2009 10:44 PM


  • System.Windows.Forms.Message can be used referencing the tlb registered with the .net framework install.  Have the COM app add one of the two:

    1)  [If your .Net application is compiled against .Net 2.0 and later]  System_Windows_Forms (found at %WINDIR%/Microsoft.Net/Framework/v2.0.5.0727/System.Windows.Forms.tlb)
    2)  [If your .Net applciation is compiled against .Net 1.0 or 1.1]  System.Windows.Forms (found at %WINDIR%/Microsoft.Net/Framework/v1.1.4322/System.Windows.Forms.tlb)

    The following is if you are passing a user-defined type to a method:
    1)  Validate type elligibility:  http://msdn.microsoft.com/en-us/library/aa720445(VS.71).aspx
    2)  Use RegAsm (using your VS Command prompt found in Start >> Programs >> Visual Studio >> Visual Studio Tools) to generate/register a tlb.
    Example:    regasm C:\SomeDirectory\MyManagedUserDefinedObject.dll /tlb:NameOfCOMComponent.tlb

    • Proposed as answer by Geert van Horrik Monday, December 7, 2009 12:36 PM
    • Marked as answer by eryang Tuesday, December 8, 2009 10:52 AM
    Thursday, December 3, 2009 12:52 AM