using C function in C#

Posted by andrew on Stack Overflow See other posts from Stack Overflow or by andrew
Published on 2010-05-13T15:20:14Z Indexed on 2010/05/13 15:24 UTC
Read the original article Hit count: 314

Filed under:
|
|
|
|

i have a dll, built with mingw
one of the header files contains this:

extern "C" {
  int get_mac_address(char * mac); //the function returns a mac address in the char * mac
}

I use this dll in another c++ app, built using Visual C++ (2008SP1), not managed, but plain c++ (simply include the header, and call the function)

But now I have to use it in a C# application

The problem is that i can't figure out how exactly (i'm new in .net programming)

this is what i've tried

public class Hwdinfo {
    [DllImport("mydll.dll")]
    public static extern void get_mac_address(string s);
}

When i call the function, nothing happens

(the mydll.dll file is located in the bin folder of the c# app, and it gives me no errors or warnings whatsoever)

© Stack Overflow or respective owner

Related posts about c#

Related posts about c++