Skip to content

Instantly share code, notes, and snippets.

@ork
Created August 19, 2015 10:01
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ork/32da69687c94530931ed to your computer and use it in GitHub Desktop.
Save ork/32da69687c94530931ed to your computer and use it in GitHub Desktop.
Wine version detector and dll procedure wrapper
#include <windows.h>
#include <stdio.h>
// FIXME Pass arguments to proc()
#define WRAP_DLL_PROC(_type, _proc, _dll, _default, ...) \
_type _proc(__VA_ARGS__) \
{ \
HMODULE dll = GetModuleHandle(_dll); \
\
if (!dll) \
return _default; \
\
_type (CDECL *proc)(__VA_ARGS__) = \
(void *) GetProcAddress(dll, #_proc); \
\
return (proc) ? proc() : _default; \
}
static const char * wine_get_version(void)
{
HMODULE ntdll = GetModuleHandle("ntdll.dll");
if (!ntdll)
return NULL;
const char * (CDECL *w_g_v)(void) =
(void *) GetProcAddress(ntdll, "wine_get_version");
return (w_g_v)? w_g_v() : NULL;
}
WRAP_DLL_PROC(const char *, wine_get_build_id, "ntdll.dll", NULL, void);
int main(int argc, char *argv[])
{
const char *wine_version = wine_get_version(),
*wine_build_id = wine_get_build_id();
if (wine_version)
printf("Wine version : %s\n", wine_version);
if (wine_build_id)
printf("Wine build id : %s\n", wine_build_id);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment