Click to See Complete Forum and Search --> : how to implement the VB6 CreateObject in C#


Lafdis
May 11th, 2005, 09:04 AM
Hi,

i want to reimplement the following code written in VB6 with C#

"Set objConnection = CreateObject("MY_TLIB.connection", IpAddress) "
where :

MY_TLIB.connection ist the transformed typelib from VB6 into C# with tlbimp.exe
objConnection is of type MY_TLIB.connection
IpAdress ist the String containing the IP-Adress of the server, i want to connect to.

I have tried it with this code but it does not work:

Type t = Type.GetTypeFromProgID("MY_TLIB.connection", "theIPAddress");
Object o = Activator.CreateInstance(t);

What is wrong?

klintan
May 11th, 2005, 03:48 PM
which exception do you get?

Lafdis
May 12th, 2005, 02:49 AM
Hi Klintan,

i got this exeption : Invalid class string

Do you have any idea, what's wrong?

Thank you

Bye

klintan
May 12th, 2005, 03:22 AM
I have not done something similar so I am just guessing...

from the error message you are getting, I assume that the GetTypeFromProgID method fails, the reason could be:

ProgID should also include version, e.g. MY_TLIB.connection.1

Since you are doing DCOM maybe you have some security problem?

Lafdis
May 12th, 2005, 04:03 AM
Hi again,

the generated .dll with tlbimp.exe from MYTLB.tlb is "Interop.MYTLB_R_2.dll". I have now suppressed the version string "R_2" in the call

Type.GetTypeFromProgID("MYTLB.connection","serverName", true);

... and it works!


Bye