Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / November 2005

Tip: Looking for answers? Try searching our database.

C# program calling a C++ DLL

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Laurent - 24 Nov 2005 14:32 GMT
   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
Mattias Sjögren - 24 Nov 2005 19:44 GMT
>[C++]
>long myFunction1(void ** parameter);
[quoted text clipped - 4 lines]
>[DllImport("MyDLL.dll")]
>public static extern long myFunction1(ref IntPtr parameter);

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

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

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

Mattias

Signature

Mattias Sjögren [C# MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Laurent - 25 Nov 2005 09:33 GMT
   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...

> >[C++]
>>long myFunction1(void ** parameter);
[quoted text clipped - 14 lines]
>
> Mattias

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.