How to call functions inside a C dll which take pointers as arguments from C#
Posted
by AndrejaKo
on Stack Overflow
See other posts from Stack Overflow
or by AndrejaKo
Published on 2010-05-06T19:06:25Z
Indexed on
2010/05/06
19:08 UTC
Read the original article
Hit count: 284
Hi people, this is my first post here!
I'm trying to make a windows forms program using C# which will use a precompiled C library. It will access a smart card and provide output from it. For the library, I have a .dll, .lib and .h and no source. In the .h file there are several structs defined. Most interesting functions of the .dll expect pointers to allocated structs as arguments. I've been calling functions inside the .dll like this: For example function EID_API int WINAPI EidStartup(int nApiVersion); would be called like this [DllImport("CelikApi.dll")]//the name of the .dll public static extern int EidStartup(int nApiVersion);
Now my problem is that I can't find equivalent of C's pointers which point to dynamically allocated structures in memory in C#, so I don't know what to pass as argument to functions which take C pointers.
I don't have much experience in C#, but to me its use looked as the easiest way of making the program I need. I tried with C++, but Visual Studio 2010 doesn't have IntelliSense for C++/CLR. If you can point me to something better, feel free to do so.
© Stack Overflow or respective owner