1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
// La define de STDCALL, doit être adaptée à votre environnement
// de veloppement. Celle qui est donnée ici, correspond à GCC. Avec Borland
// vous pourrez essayer __stdcall (sauf erreur). Avec LCC, il me semble
// qu'il faut passer par une pragma (j'ai oublié, j'ai abandonné LCC pour
// des raisons de licence). Certains environnements définissent
// d'ailleur déjà cette macro.
//
// En compilant ce source, vous obtiendrez peut-être un message du genre
// « warning: `_PfnLoadUnicows' initialized and declared `extern' » de la part
// de votre compilateur. N'y pretez pas attention, c'est tout à fait normal,
// et il ne s'agit en aucun cas d'une erreur.
#define NULL ((void*)0)
#define STDCALL __attribute__((stdcall))
#define API extern STDCALL
typedef void* HMODULE;
API HMODULE LoadLibraryA(char* path);
API int MessageBoxA (void* owner, char* message, char* caption, int style);
static char* ErrorMessage =
"Failed to load the Unicode API\n"
"\n"
"Check that either unicows.dll or opencaw.dll\n"
"is present in the application directory.\n"
"\n"
"- You may get a copy of the original unicows.dll at\n"
"http://www.microsoft.com/downloads/\n"
"(type 'unicows.dll' in the search box)\n"
"- You may get a copy of the opensource version opencow.dll at\n"
"http://opencow.sourceforge.net/\n";
static char* ErrorTitle = "Unicode API Error";
HMODULE hUnicowsAPI = NULL;
HMODULE hOpencowAPI = NULL;
STDCALL HMODULE LoadUnicodeAPI (void)
{
hUnicowsAPI = LoadLibraryA("unicows.dll");
if (hUnicowsAPI != NULL) return hUnicowsAPI;
else {
hOpencowAPI = LoadLibraryA("opencow.dll");
if (hOpencowAPI != NULL) return hOpencowAPI;
else {
MessageBoxA (NULL, ErrorMessage, ErrorTitle, 0);
exit (-1);
}
}
}
extern HMODULE (STDCALL *_PfnLoadUnicows)(void) = &LoadUnicodeAPI; |
Partager