I am working on a C#
application which is a port from a C++
application that utilizes a C++ DLL
. The C++ DLL
is from a third party which provides the .dll
, a .lib
, and a .h
file with all of the extern
functions contained within the DLL
. No issues here, using interop
I can call into the DLL
from my C#
app.
The issue comes in the fact that the third party has a couple functions in the .h
for their DLL
that they expect you to implement. It seems they provide function signatures in their .h
file that they call in the DLL
, so you must have an implementation of the function, even if it is just hollowed out.
For Example:
DLL
header file will contain:
extern void Foo(void); // Implemented in DLL
extern void YourFoo(void); // Must be implemented in your app
So the class where I bring in these functions in my C#
app will be something like:
[DllImport(MY_DLL, CallingConvention = CallingConvention.Cdecl)]
public static extern void Foo();
// Need to show C++ DLL that I implemented YourFoo here
public static void YourFoo()
{
// My logic
}
How do I provide my C# implementation of YourFoo to the C++ DLL?
EDIT #1: This question is not concerning using a callback between C#/C++
. I need to provide a C#
implementation for a function extern
'd in the header file for a C++ DLL
used by my C#
application.