473,387 Members | 1,859 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Question on Calling VB6 Dll

RC
Hi,

I have a dll written by vb6.
AFunction(ByRef o as Variant)

I want to use it in csharp by System.Reflection.

Assembly asm = Assembly.LoadFrom("Lib.dll");
Type t = asm.GetTypes("Lib.CLib");
object o = Activator.CreateInstance(t);
object param = new string[] {"1", "2", "3", "4"};
MethodBase mth = t.GetMethods("AFunction");
mth.Invoke(o, new object[]{param}); <---Throw ArgumentException "Object type
cannot be converted to target type."

As I know the argument type is "System.Object&" in .NET, I think it could
pass the parameter by "AFunction(ref object o)". However the dll file is
loaded in runtime dynamically, so calling "AFunction(ref object o)" directly
should not be worked.

Anyone know how to convert VB6 array into CSharp array in my case ?
And How to call the VB6 Function in CSharp?

Regards,
RC


Nov 17 '05 #1
3 2653
Hi,

As far as I know, VB6 can create only COM dlls. Therefore, they must be
consumed as any other COM objects - through creating an interop assembly
with tlbimp.exe. Your code below indicates that you are trying to load a VB6
dll like a .NET assembly, that won't work at all.

--
Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]
"RC" <rc@hotmail.com> wrote in message
news:uA**************@TK2MSFTNGP12.phx.gbl...
Hi,

I have a dll written by vb6.
AFunction(ByRef o as Variant)

I want to use it in csharp by System.Reflection.

Assembly asm = Assembly.LoadFrom("Lib.dll");
Type t = asm.GetTypes("Lib.CLib");
object o = Activator.CreateInstance(t);
object param = new string[] {"1", "2", "3", "4"};
MethodBase mth = t.GetMethods("AFunction");
mth.Invoke(o, new object[]{param}); <---Throw ArgumentException "Object
type cannot be converted to target type."

As I know the argument type is "System.Object&" in .NET, I think it could
pass the parameter by "AFunction(ref object o)". However the dll file is
loaded in runtime dynamically, so calling "AFunction(ref object o)"
directly should not be worked.

Anyone know how to convert VB6 array into CSharp array in my case ?
And How to call the VB6 Function in CSharp?

Regards,
RC



Nov 17 '05 #2
RC
oh, I forget to say. I 've already load the dll from a .NET assembly.

"Dmytro Lapshyn [MVP]" <x-****@no-spam-please.hotpop.com> wrote in message
news:OP****************@TK2MSFTNGP14.phx.gbl...
Hi,

As far as I know, VB6 can create only COM dlls. Therefore, they must be
consumed as any other COM objects - through creating an interop assembly
with tlbimp.exe. Your code below indicates that you are trying to load a
VB6 dll like a .NET assembly, that won't work at all.

--
Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]
"RC" <rc@hotmail.com> wrote in message
news:uA**************@TK2MSFTNGP12.phx.gbl...
Hi,

I have a dll written by vb6.
AFunction(ByRef o as Variant)

I want to use it in csharp by System.Reflection.

Assembly asm = Assembly.LoadFrom("Lib.dll");
Type t = asm.GetTypes("Lib.CLib");
object o = Activator.CreateInstance(t);
object param = new string[] {"1", "2", "3", "4"};
MethodBase mth = t.GetMethods("AFunction");
mth.Invoke(o, new object[]{param}); <---Throw ArgumentException "Object
type cannot be converted to target type."

As I know the argument type is "System.Object&" in .NET, I think it
could pass the parameter by "AFunction(ref object o)". However the dll
file is loaded in runtime dynamically, so calling "AFunction(ref object
o)" directly should not be worked.

Anyone know how to convert VB6 array into CSharp array in my case ?
And How to call the VB6 Function in CSharp?

Regards,
RC


Nov 17 '05 #3
RC,

MSDN reads on MethodInfo.Invoke:

"If the method or constructor represented by this instance takes a ByRef
parameter, there is no special attribute required for that parameter in
order to invoke the method or constructor using this function."

However, what looks suspicious is that you create an array of strings as the
value of the "param" - I'd try using "new object[] {...}" here as well.

You can also consider re-posting this question in the
microsoft.public.dotnet.framework.interop newsgroup.

--
Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]
"RC" <rc@hotmail.com> wrote in message
news:uh*************@TK2MSFTNGP10.phx.gbl...
oh, I forget to say. I 've already load the dll from a .NET assembly.

"Dmytro Lapshyn [MVP]" <x-****@no-spam-please.hotpop.com> wrote in message
news:OP****************@TK2MSFTNGP14.phx.gbl...
Hi,

As far as I know, VB6 can create only COM dlls. Therefore, they must be
consumed as any other COM objects - through creating an interop assembly
with tlbimp.exe. Your code below indicates that you are trying to load a
VB6 dll like a .NET assembly, that won't work at all.

--
Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]
"RC" <rc@hotmail.com> wrote in message
news:uA**************@TK2MSFTNGP12.phx.gbl...
Hi,

I have a dll written by vb6.
AFunction(ByRef o as Variant)

I want to use it in csharp by System.Reflection.

Assembly asm = Assembly.LoadFrom("Lib.dll");
Type t = asm.GetTypes("Lib.CLib");
object o = Activator.CreateInstance(t);
object param = new string[] {"1", "2", "3", "4"};
MethodBase mth = t.GetMethods("AFunction");
mth.Invoke(o, new object[]{param}); <---Throw ArgumentException "Object
type cannot be converted to target type."

As I know the argument type is "System.Object&" in .NET, I think it
could pass the parameter by "AFunction(ref object o)". However the dll
file is loaded in runtime dynamically, so calling "AFunction(ref object
o)" directly should not be worked.

Anyone know how to convert VB6 array into CSharp array in my case ?
And How to call the VB6 Function in CSharp?

Regards,
RC




Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: Nunaya | last post by:
We have developed two objects called "customer" and "salesrep". For simplicity, assume that these two objects will talk directly to a database. The database has three tables: customers,...
5
by: Dave | last post by:
does calling a regular function cost any cpu time? In other words, is it faster to write the code of two functions into main(), or is it the exact same thing as calling two functions. I know its...
15
by: designconcepts | last post by:
bo'jour, bo'jour, So I have question to present to the forum about OOD. This is a Csharp forum, but C# is the lang of choice and the question is an exercise based on some comments by the chief...
3
by: Jon Pope | last post by:
I've got a basic question about threading which I'm hoping someone here will be able to answer: Let's say my calling CallingClass has instantiated and started a worker thread. When my worker...
24
by: songie D | last post by:
Can managed C++ be trusted to handle the garbage collector correctly in the right bit if I have a project with unmanaged and managed parts in it?
14
by: Mr Newbie | last post by:
I am often in the situation where I want to act on the result of a function, but a simple boolean is not enough. For example, I may have a function called isAuthorised ( User, Action ) as ?????...
5
by: Michael Moreno | last post by:
Hello, In a class I have this code: public object Obj; If Obj is a COM object I would like to call in the Dispose() method the following code: ...
8
by: olanglois | last post by:
Hi, I was asking myself to following question. What is better to erase an element from a STL map: calling (option #1) size_type erase(const key_type& k) or calling (option #2)
5
by: Snis Pilbor | last post by:
Hello, Is there any actual difference between calling a function directly by name, vs. calling it by a function pointer which points to it? I read at the FAQ that the function name can be...
3
by: MathWizard | last post by:
Hi, I have a question about returning an object in a function and calling a copy constructor. As far as I understand, in the following code the copy constructor may or may not be called,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.