Skip to content

Instantly share code, notes, and snippets.

@gashtio
Created November 3, 2012 10:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gashtio/4006900 to your computer and use it in GitHub Desktop.
Save gashtio/4006900 to your computer and use it in GitHub Desktop.
Simple exported callback from a DLL
#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