how to use VC++ dll in .net

G

Guest

Hi,

I am having one VC++ dll. I need to refer this dll form C# web site. When I
try to add the dll as reference it says the "dll should be com dll or
assembly". So I understood I shouldnt use the VC++ dll as it is. I created a
serviced component so called wrapper class. Then I tried to add this wrapper
dll to my .net web site.
My wrapper looks like The project is built. when i run the application at
the line of calling VC++ function thro' wrapper class it throws an exception
as

[DllImport("a.dll", EntryPoint = "fun1")]
public static extern int fun1(int p1, int p2, int p3, int p4, ref
string p5);

a.dll->VC++ dll
fun1-> function name

The matching function in VC++ looks like
short CNK::fun1(ULONG p1,ULONG p2,ULONG p3,ULONG p4,WCHAR* p5)

Is the parameter data type matching with vc++ and .net is correct?

"Attempted to read or write protected memory. This is often an indication
that other memory is corrupt".

Am I anyway wrong here.
Kindly help me.
Tx in advance
 
M

Mattias Sjögren

[DllImport("a.dll", EntryPoint = "fun1")]
public static extern int fun1(int p1, int p2, int p3, int p4, ref
string p5);

Try it with

[DllImport("a.dll", EntryPoint = "fun1", CharSet=CharSet.Unicode)]
public static extern short fun1(..., string p5);


Mattias
 

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