• 0

[C#] Using C++ function from .dll in C#


Question

I'm developing a program using C# for my University project, I've gotten up to the point where I need to interact with some .dll files which are developed in C++, I've tracked down the necessary functions and now need to figure out how to implement them into my project, like execute the function with a button.

An example of the code in question:

long CALLBACK CDRconfigure(void)
{
 return 0;
}

Can someone point me in the right direction with easy-to-understand knowledge/tutorials?

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Are you exposing your C++ library through COM? If so, you can easily add a COM reference, which generates an interop library from your C++ library. If not, you can use P/Invoke to declare an external function:

[DllImport("mylibrary.dll")]
public static extern long CDRconfigure();

I don't know the exact signature requirements for your methods, but its along those lines. Have a google for P/Invoke, and take into consideration how you will be marshalling any custom types.

Hope that helps.

  • Like 2
Link to comment
Share on other sites

This topic is now closed to further replies.