Working with a VB COM Component

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • David C

    Working with a VB COM Component

    This is my first time having to integrate a COM component into my
    dotnet project. The COM component is from a VB developer, so I have
    no control over his code.

    I am having the following issues after importing the COM object into
    Visual Studio (2003, not 2005).

    When I create an instance of a class (Jobs jobs = new Jobs()), I get
    the following error message.

    COM object with CLSID {6FC1CF2C-BC59-4B78-AF18-B162F2D12CA6} is either
    not valid or not registered.

    Also, I expected the property I needed (Let's call this UserID) to be
    a string. But its datatype is System.IntPtr. Huh? What is that?
    But then when I force a string and compile just to see, I get the
    following compilation error.

    Property, indexer, or event 'UserId' is not supported by the language;
    try directly calling accessor method
    'OdysseyCO._Pet roToolsJobs.set _UserId(ref string)'

    Now that's interesting. So I followed the recommendation and
    tried .set_UserId(ref string). .set_UserId does not show up in my
    intellisense, but the code compiles!

    So unless there are other things I should try (can't imagine there are
    any), what should I tell the VB developer?

  • Willy Denoyette [MVP]

    #2
    Re: Working with a VB COM Component

    "David C" <profnachos@gma il.comwrote in message
    news:1174809711 .795443.311750@ d57g2000hsg.goo glegroups.com.. .
    This is my first time having to integrate a COM component into my
    dotnet project. The COM component is from a VB developer, so I have
    no control over his code.
    >
    I am having the following issues after importing the COM object into
    Visual Studio (2003, not 2005).
    >
    When I create an instance of a class (Jobs jobs = new Jobs()), I get
    the following error message.
    >
    COM object with CLSID {6FC1CF2C-BC59-4B78-AF18-B162F2D12CA6} is either
    not valid or not registered.
    >
    Also, I expected the property I needed (Let's call this UserID) to be
    a string. But its datatype is System.IntPtr. Huh? What is that?
    But then when I force a string and compile just to see, I get the
    following compilation error.
    >
    Property, indexer, or event 'UserId' is not supported by the language;
    try directly calling accessor method
    'OdysseyCO._Pet roToolsJobs.set _UserId(ref string)'
    >
    Now that's interesting. So I followed the recommendation and
    tried .set_UserId(ref string). .set_UserId does not show up in my
    intellisense, but the code compiles!
    >
    So unless there are other things I should try (can't imagine there are
    any), what should I tell the VB developer?
    >

    Comment

    • Willy Denoyette [MVP]

      #3
      Re: Working with a VB COM Component

      "David C" <profnachos@gma il.comwrote in message
      news:1174809711 .795443.311750@ d57g2000hsg.goo glegroups.com.. .
      This is my first time having to integrate a COM component into my
      dotnet project. The COM component is from a VB developer, so I have
      no control over his code.
      >
      I am having the following issues after importing the COM object into
      Visual Studio (2003, not 2005).
      >
      When I create an instance of a class (Jobs jobs = new Jobs()), I get
      the following error message.
      >
      COM object with CLSID {6FC1CF2C-BC59-4B78-AF18-B162F2D12CA6} is either
      not valid or not registered.
      >
      Also, I expected the property I needed (Let's call this UserID) to be
      a string. But its datatype is System.IntPtr. Huh? What is that?
      But then when I force a string and compile just to see, I get the
      following compilation error.
      >
      Property, indexer, or event 'UserId' is not supported by the language;
      try directly calling accessor method
      'OdysseyCO._Pet roToolsJobs.set _UserId(ref string)'
      >
      Now that's interesting. So I followed the recommendation and
      tried .set_UserId(ref string). .set_UserId does not show up in my
      intellisense, but the code compiles!
      >
      So unless there are other things I should try (can't imagine there are
      any), what should I tell the VB developer?
      >

      How does the COM interface and coclass definition looks like when using oleview.exe on the
      typelib?
      Are you sure you have registered the correct dll before importing? Try to re-register the
      dll using regsvr32.exe

      Willy.

      Comment

      • David C

        #4
        Re: Working with a VB COM Component

        >
        How does the COM interface and coclass definition looks like when using oleview.exe on the
        typelib?
        I did look at it using oleview and the class I am interested in should
        have a property called UserID, but it is listed as a method. This is
        what it looks like.

        [id(0x6803000e), propput]
        void UserId([in, out] BSTR* rhs);

        I don't have the slightest idea what I am looking at. I asked the VB
        developer to just make it a string property (UserID, that is), but I
        don't know what oleview is telling me.
        Are you sure you have registered the correct dll before importing? Try to re-register the
        dll using regsvr32.exe
        After I posted, I did just that and I am not getting the "COM
        object ....not registered" error any more. I thought I could treat
        the interlop assembly like any other .NET assemblies, but I guess
        not. The memories of DLL registration hell coming back...


        Comment

        • Willy Denoyette [MVP]

          #5
          Re: Working with a VB COM Component

          "David C" <profnachos@gma il.comwrote in message
          news:1174901433 .342875.234280@ n76g2000hsh.goo glegroups.com.. .
          >
          >>
          >How does the COM interface and coclass definition looks like when using oleview.exe on
          >the
          >typelib?
          >
          I did look at it using oleview and the class I am interested in should
          have a property called UserID, but it is listed as a method. This is
          what it looks like.
          >
          [id(0x6803000e), propput]
          void UserId([in, out] BSTR* rhs);
          >
          I don't have the slightest idea what I am looking at. I asked the VB
          developer to just make it a string property (UserID, that is), but I
          don't know what oleview is telling me.
          >
          >Are you sure you have registered the correct dll before importing? Try to re-register the
          >dll using regsvr32.exe
          >
          After I posted, I did just that and I am not getting the "COM
          object ....not registered" error any more. I thought I could treat
          the interlop assembly like any other .NET assemblies, but I guess
          not. The memories of DLL registration hell coming back...
          A COM dll stay's a COM dll, and must be registered, this has nothing to do with .NET. Note,
          that I don't know how you were able to set a reference to a non-registered COM DLL though,
          you must have done something wrong.
          The UserId property is passing a BSTR (Basic String), which will be marshaled as a CLI
          Object.String by the COM interop marshaler when returned from COM. That means that a
          'string' is the correct type for the property in C#.


          Willy.



          Comment

          • David C

            #6
            Re: Working with a VB COM Component

            >
            A COM dll stay's a COM dll, and must be registered, this has nothing to do with .NET. Note,
            that I don't know how you were able to set a reference to a non-registered COM DLL though,
            you must have done something wrong.
            I did Project->Add Reference. Clicked on the Com tab, clicked
            "Browse" and found the COM dll and just imported it that way. From
            there, I was able to use it.
            The UserId property is passing a BSTR (Basic String), which will be marshaled as a CLI
            Object.String by the COM interop marshaler when returned from COM. That means that a
            'string' is the correct type for the property in C#.
            >
            MyClass.UserId does not compile. I cannot read it or assign a value
            to it. And in .NET, the data type is System.Inptr, not string.


            Comment

            Working...