Yun Peng | a93e9de | 2016-06-30 14:27:38 +0000 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <windows.h> |
| 3 | typedef char *(__cdecl *GET_TIME_PTR)(); |
| 4 | typedef void(__cdecl *SAY_HELLO_PTR)(char *); |
| 5 | |
| 6 | int main() { |
| 7 | HINSTANCE hellolib; |
| 8 | GET_TIME_PTR get_time; |
| 9 | SAY_HELLO_PTR say_hello; |
| 10 | |
| 11 | bool success = FALSE; |
| 12 | |
| 13 | hellolib = LoadLibrary(TEXT("hellolib.dll")); |
| 14 | |
| 15 | if (hellolib != NULL) { |
| 16 | get_time = (GET_TIME_PTR)GetProcAddress(hellolib, "get_time"); |
| 17 | say_hello = (SAY_HELLO_PTR)GetProcAddress(hellolib, "say_hello"); |
| 18 | |
| 19 | if (NULL != get_time && NULL != say_hello) { |
| 20 | success = TRUE; |
| 21 | char *now = get_time(); |
| 22 | say_hello(now); |
| 23 | } |
| 24 | FreeLibrary(hellolib); |
| 25 | } |
| 26 | |
| 27 | if (!success) printf("Failed to load dll and call functions\n"); |
| 28 | |
| 29 | return 0; |
| 30 | } |