54 lines
1.0 KiB
Plaintext
54 lines
1.0 KiB
Plaintext
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
#ifdef _WIN32
|
|
#include <windows.h>
|
|
#else
|
|
#include <dlfcn.h>
|
|
#endif
|
|
|
|
typedef int (*QueryFunc)(char *, size_t *);
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
char Buffer[1024];
|
|
size_t Size = sizeof(Buffer);
|
|
|
|
#ifdef _WIN32
|
|
HMODULE hLib = LoadLibrary("libquery.dll");
|
|
if (!hLib) {
|
|
printf("failed to load library\n");
|
|
return 1;
|
|
}
|
|
QueryFunc Query = (QueryFunc)GetProcAddress(hLib, "Query");
|
|
#else
|
|
void *hLib = dlopen("./libquery.so", RTLD_LAZY);
|
|
if (!hLib) {
|
|
printf("failed to load library\n");
|
|
return 1;
|
|
}
|
|
QueryFunc Query = (QueryFunc)dlsym(hLib, "Query");
|
|
#endif
|
|
|
|
if (!Query) {
|
|
printf("failed to find Query function\n");
|
|
return 1;
|
|
}
|
|
|
|
if (0 == Query(Buffer, &Size)) {
|
|
printf("failed to call Query\n");
|
|
} else {
|
|
char *Ptr = Buffer;
|
|
while (Size-- > 0) putchar(*Ptr++);
|
|
putchar('\n');
|
|
}
|
|
|
|
#ifdef _WIN32
|
|
FreeLibrary(hLib);
|
|
#else
|
|
dlclose(hLib);
|
|
#endif
|
|
|
|
return 0;
|
|
}
|