all groups > dotnet interop > november 2005 >
You're in the

dotnet interop

group:

C# program calling a C++ DLL


C# program calling a C++ DLL Laurent
11/24/2005 12:00:00 AM
dotnet interop:
Hello,


I received a C++ DLL and I must include it in my C# programm. The
problem is that I don't know how to convert the parameters from C++ to C#,
specialy when there are pointers in it. There are 2 fonctions I would like
to convert.

The first one has only one parameter, but I don't know how to deal with
the void type.

[C++]
long myFunction1(void ** parameter);

I tried this, but it does not work:

[C#]
[DllImport("MyDLL.dll")]
public static extern long myFunction1(ref IntPtr parameter);




The second one has a double pointer to a structure. I think I dealed
with the structure, but what about the double pointer ?

[C++]
long myFunction2(myStruct** parameter);

with myStruct defined as:

struct FF_AO_ImageList
{
char structParameter1[30];
long structParameter2;
}

[C#]
[DllImport("MyDLL.dll")]
public static extern long myFunction2(??????);

with myStruct defined as:

public struct FF_AO_ImageList
{
[MarshalAs(UnmanagedType.ByValTStr), SizeConst = 30]
public string structParameter1;
public long structParameter2;
}


I hope it's not too difficult to understand, however I'll explain again.
I hope someone can help me ! Thanks...


Laurent

Re: C# program calling a C++ DLL Mattias Sjögren
11/24/2005 8:44:24 PM
[quoted text, click to view]

long in C++ becomes int in C# so you should change the return type.


[quoted text, click to view]

It depends on how the parameter is used. Is it an input or output
parameter (or both), who allocates memory etc.


Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Re: C# program calling a C++ DLL Laurent
11/25/2005 10:33:22 AM
Hi Mattias,


Thanks for your answer. I tried to change the long parameter to int, but
I still have the same error: The code throws a
System.EntryPointNotFoundException with the following message: "Unable to
find the Entry Point "xxxx" in the DLL "xxxx.dll".

I opened a DLL using "DLL Depends 2.1"... The tool shows me the function
I would like to call with an entry point adress. Prehaps the DLL has not
been well compiled ?

I don't know what I did wrong. I tried to use an unsafe code and a
void** parameter, but the same error occured. I'll try using a C++ code to
call my DLL, just to see if I can access the function...


If anyone has an idea...






"Mattias Sjögren" <mattias.dont.want.spam@mvps.org> a écrit dans le message
de news: uhZkI%23S8FHA.3876@TK2MSFTNGP09.phx.gbl...
[quoted text, click to view]

AddThis Social Bookmark Button