Created
August 19, 2015 10:01
-
-
Save ork/32da69687c94530931ed to your computer and use it in GitHub Desktop.
Wine version detector and dll procedure wrapper
This file contains hidden or 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 <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