1 2 3 4 5 6 7 8 | #include "Windows.h" #define EXPORT extern "C" __declspec (dllexport) EXPORT void PopMsg(char *msg) { MessageBox(NULL, msg, "Export Function Demo", MB_OK); } |
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 | #include <windows.h> #include <string.h> #include <iostream> int _tmain(int argc, char* argv[]) { // Load the TestDLL.dll HINSTANCE hDLL = LoadLibrary("D:\\askyb\\release\\TestDLL.dll"); if(hDLL == NULL) { printf("Failed to load DLL"); return 1; } // define the function prototype here typedef void(*fnPtr)(char*); fnPtr pfn; // Get the address of the function you wish to call pfn=(fnPtr)GetProcAddress(hDLL,"PopMsg"); if(pfn) { // call the PopMsg in TestDLL pfn("Exporting C++ Functions from DLL"); } FreeLibrary(hDLL); return 0; } |

Exporting C++ Functions from DLL