Working with a VB COM Component

D

David C

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._PetroToolsJobs.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?
 
W

Willy Denoyette [MVP]

David C said:
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._PetroToolsJobs.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?
 
W

Willy Denoyette [MVP]

David C said:
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._PetroToolsJobs.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.
 
D

David C

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...
 
W

Willy Denoyette [MVP]

David C said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top