cominterop runtime callable wrapper

  • Thread starter Thread starter Ariel Gimenez
  • Start date Start date
A

Ariel Gimenez

Hi, maybe some of you can give me a hand with this,
I have a dll written in VB 6 but i havent the source code of it.
In Visual Basic 6 this dll instanciates with createobject and the method was
accesed in this way:

mydll.method "1", "2", "3", True

Now in Asp.net when i add the reference and try to call it this way:

mydll.method("1","2","3",true);

It fails telling me that the parameters are by reference!!!! and some of the
parameters appears in the intellisense as ref object!!!!
The TLBIMp is wrong?

thanks
 
Ariel,

No, it is not wrong. If in a method definition there are no modifiers,
then VB will pass them by reference. So, to call them, you have to use:

string pstr1 = "1", pstr2 = "2", pstr3 = "3";
bool pbln1 = true;

// Make the call.
mydll.method(ref pstr1, ref pstr2, ref pstr3, ref pbln1);

That is assuming that the parameters are typed, and not variants. If
they are variants, then you will have to declare pstr1, pstr2, pstr3, and
pbln1 as objects, and cast to/from the object. In this case, you might want
to write wrapper objects that are type-safe, so that you don't have to deal
with casts every time.

Hope this helps.
 
Thanks Nicholas!

Your solution works fine to me!!!!

Nicholas Paldino said:
Ariel,

No, it is not wrong. If in a method definition there are no modifiers,
then VB will pass them by reference. So, to call them, you have to use:

string pstr1 = "1", pstr2 = "2", pstr3 = "3";
bool pbln1 = true;

// Make the call.
mydll.method(ref pstr1, ref pstr2, ref pstr3, ref pbln1);

That is assuming that the parameters are typed, and not variants. If
they are variants, then you will have to declare pstr1, pstr2, pstr3, and
pbln1 as objects, and cast to/from the object. In this case, you might want
to write wrapper objects that are type-safe, so that you don't have to deal
with casts every time.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Ariel Gimenez said:
Hi, maybe some of you can give me a hand with this,
I have a dll written in VB 6 but i havent the source code of it.
In Visual Basic 6 this dll instanciates with createobject and the method was
accesed in this way:

mydll.method "1", "2", "3", True

Now in Asp.net when i add the reference and try to call it this way:

mydll.method("1","2","3",true);

It fails telling me that the parameters are by reference!!!! and some of the
parameters appears in the intellisense as ref object!!!!
The TLBIMp is wrong?

thanks
 
Back
Top