By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,460 Members | 1,508 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,460 IT Pros & Developers. It's quick & easy.

figuring out c# declarations from a DLL of C functions

P: n/a
Hi,

I'm trying to use a C function ( long int myFunc() ) from a DLL in my
C# program. I use DllImport("dllname") a C function and declare it as

[DllImport("dllname")]
public static extern int myFunc();

At first I used

public static extern long myFunc();

but that returned a bizarre value. I incorrectly assumed a C long int
mapped
to C# long. Using C# int worked. But here's my question -

Since the DLL is known, is there a tool that will list the C#
equivalents for
the functions as long as the variable types are standard (i.e., int,
long, float, etc. )? Does it seems reasonable that C# should be able
to gather this info from the DLL?

Finally, what is the name of the process of using the [DllImport...]
specification for loading external functions?
Is this PInvoke?
Are there any books/articles describing this in detail, particularly
with
accessing and running C functions that return pointers to structures.

Thanks,

Ted
Nov 15 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
yep, it's Platform Invoke. look in your .net sdk documentation, look under P/Invoke, it contains a standard C/C++ datatype to C# equivalent table, and also a lot of information on more complicated string, array, struct/union, input/output, callback, GC related marshalling topics

I'm also looking for ways to make the process easier. Dumpbin doesn't supply a whole lot of information (maybe I don't know how to use it, I don't know how much information is actually included in the DLLs). it's a pain to dig up information on poorly documented C APIs, like the original typedefs, when you only have the binary dlls to work with, not the C header files

----- Ted Sung wrote: ----

Hi

I'm trying to use a C function ( long int myFunc() ) from a DLL in m
C# program. I use DllImport("dllname") a C function and declare it a

[DllImport("dllname")
public static extern int myFunc()

At first I used

public static extern long myFunc()

but that returned a bizarre value. I incorrectly assumed a C long in
mappe
to C# long. Using C# int worked. But here's my question

Since the DLL is known, is there a tool that will list the C
equivalents fo
the functions as long as the variable types are standard (i.e., int
long, float, etc. )? Does it seems reasonable that C# should be abl
to gather this info from the DLL

Finally, what is the name of the process of using the [DllImport...
specification for loading external functions
Is this PInvoke
Are there any books/articles describing this in detail, particularl
wit
accessing and running C functions that return pointers to structures

Thanks

Te

Nov 15 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.