C# and VC++ 6.0 DLL..

H

Harish Sachdeva

I$B!G(Bm working on a C# .NET application that is showing some strange behavior
when calling a DLL using PInvoke or COM Interop. The DLL was written in VC6
and is used to control an external device via serial communications. I am
calling a method in the DLL that returns measurement data from the device.

According to the specifications of the device, the DLL should return
measurement data after 1.5 seconds. In fact, if I create a standalone VC6
application, a call to the DLL method does return data after 1.5 seconds.
But, if I make the same call to the DLL from C#, it takes 4 seconds to
return data. This is a time critical application and 4 seconds is not
acceptable. There is nothing different in the configuration except that I$B!G(Bm
calling the DLL from C# instead of VC6. I$B!G(Bve experimented with PInvoke and
COM Interop and both have similar behavior. Unfortunately, I don$B!G(Bt have
access to the source code of the DLL so I cannot debug what is happening
inside it.

My theory is that there is something about how the .NET runtime sets up the
apartment for the DLL execution that is different from VC6. The DLL is
probably trying to perform some memory operations or serial port operations
that the .NET runtime is restricting. This results in some errors that slow
down execution of the DLL. This makes me wonder if there is some way to
change parameters of PInvoke or COM Interop so that the DLL is not
restricted. So far, I cannot find any information on this issue.

Any information or suggestions would be greatly appreciated. Thank you for
your help.
 
I

Irfan

Hi Harish,

I guess the delay was due to the interoperability!

One thing you could do is have your VC++ DLL onto the
COM+/Component Services and see if there is any
improvement in the time.

Also, the usage of RCW shall not be a problem calling
unmanaged COM components in .NET

HTH
irfan
 

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