dlfcn.hヘッダファイルをつくる
MinGWにはDLLをLoadするためのdlopen(),dlclose(),dlsym()などの関数がまだ定義されていないらしいので、 以下ヘッダファイルをつかってコンパイルする。 いってみれば単なるラッパーか。
1 /*
2 * dlfcn_win32.h 1.0 2003/01/16
3 *
4 * Emulates the POSIX dlfcn.h
5 *
6 * By Wu Yongwei
7 *
8 */
9
10 #ifndef _DLFCN_WIN32_H
11 #define _DLFCN_WIN32_H
12
13 #ifdef _WIN32
14 #define WIN32_LEAN_AND_MEAN
15 #include <windows.h>
16 #include <errno.h>
17 #define dlopen(P,G) (void*)LoadLibrary(P)
18 #define dlsym(D,F) (void*)GetProcAddress((HMODULE)D,F)
19 #define dlclose(D) FreeLibrary((HMODULE)D)
20 __inline const char* dlerror()
21 {
22 static char szMsgBuf[256];
23 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
24 NULL,
25 GetLastError(),
26 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
27 szMsgBuf,
28 sizeof szMsgBuf,
29 NULL);
30 return szMsgBuf;
31 }
32 #endif /* _WIN32 */
33
34 #endif /* _DLFCN_WIN32_H */