Interop with VC dlls

  • Thread starter Thread starter swapna_munukoti
  • Start date Start date
S

swapna_munukoti

Hi all,

I am new to .net and that c#. I am currently working for a project
that includes migration from vb6 application to c#.

VB6 application communicates with a modules developed in VC++.

Now, the same logic I am trying with c#. That is c# application to
interact with VC++ modules.

I have 2 VC++ dlls, like m1 and m2, in which I used to interact with
class c1 in m1 and class c2 in m2.
something like m1.c1, m2.c2...
In m2.c2, there are functions that needs parameters (byref) of type
ic1.
where ic1 interface which includes all the definitions of m1.c1

Now the current vb6 application passes parameters of type m1.c1 to the
functions in m2.c2 and it is working fine.

But when tried to write the same in c#, it is throwing an error. It is
expecting only parameters of type ic1 interface...

Why is it so? Wont there be any other way to pass that argument of
m1.c1 type????

Thanks,
Swapna.
 
Swapna,

In VB6, the only way you would be able to work with objects written in
VC++ is through calls to API functions, or through COM. This is the same
way that .NET deals with unmanaged code (although in a much better manner,
IMO). From your post, I can't tell which you are doing.

Can you show some VB6 code in which you are calling your objects?
 
VB6 code is like this

Dim objDataWrapper as DataWrapper.DWrapper
Dim objFrameWorkWrapper as FrameWork.clsFrameWork

public function getData() as long

objDataWrapper = new DataWrapper.DWrapper
objFrameWorkWrapper = new FrameWork.clsFrameWork

getData = objFrameWorkWrapper.getData(objDataWrapper)

end function

In c#, objFrameWorkWrapper.getData() function is expecting the
parameter as IDDataWrapper, which is an interface of
DataWrapper.DWrapper in FrameWork dll.
And if I am trying to create an object of type IDDataWrapper, it is
throwing an error stating "Instance cannot be created for abstract
class or interface".

In Vb6 also, it was expecting the the parameter as IDDataWrapper. But
then if I pass an object of type DataWrapper.DWrapper, it is allowing
and functioning correctly.

What shall I need to do, to achieve the functionality I am expecting.

Thanks,
Swapna.
 
Hi all,

I found the solution for my problem in some trial n error.

In c# I have declared the variable as,

FrameWork.InternfaceName objDataWrapper;

objDataWrapper = (FrameWork.InternfaceName) new
DataWrapper.DWrapper();

I dont know whether it is correct or not. But it is working fine for
me.

Regards,
Swapna.
 

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

Back
Top