Created
November 3, 2012 10:27
-
-
Save gashtio/4006900 to your computer and use it in GitHub Desktop.
Simple exported callback from a DLL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#define LIBAPI __declspec(dllexport) | |
#define LIBSTDCALL __stdcall | |
struct SimpleStruct | |
{ | |
SimpleStruct() : Value(0) {} | |
operator int () | |
{ | |
return Value; | |
} | |
int Value; | |
}; | |
typedef SimpleStruct ReturnType; | |
typedef ReturnType (LIBSTDCALL *MyCallback)(int, int); | |
static MyCallback g_MyCallback = nullptr; | |
extern "C" | |
{ | |
LIBAPI void LIBSTDCALL InstallCallback(MyCallback callback) | |
{ | |
g_MyCallback = callback; | |
} | |
LIBAPI void LIBSTDCALL FireCallback(int x, int y) | |
{ | |
if (g_MyCallback) | |
{ | |
ReturnType retVal = g_MyCallback(x, y); | |
SimpleStruct* simple = (SimpleStruct*)&retVal; | |
std::cout << *simple << std::endl; | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment