it all seems to work fine and i can have my app running and change some code in the DLL
and it works fine when i run it from the console.
However, the program just terminates when i run it from the windows GUI. why could this be?
king01.cpp
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 | #include <windows.h> #include <stdio.h> #include <iostream> #include "myDLL.h" typedef void (*myFP)(int, int); int main() { int answer = 1; while(answer != 0) { CopyFile("build\\myDLL.dll", "build\\myDLL_COPY.dll", false); HMODULE hm = LoadLibrary("build\\myDLL_COPY.dll"); if(hm) { printf("YES\n"); } myFP mfp = (myFP)GetProcAddress(hm, "drawRect"); if(mfp) { printf("mfp success\n"); } std::cout << "Enter Number: "; std::cin >> answer; std::cout << "\n\n\n"; mfp(10, 10); std::cout << "\n\n\n"; std::cout << answer << std::endl; FreeLibrary(hm); } return 0; } |
myDLL.h
1 2 3 4 | extern "C" { __declspec(dllexport) void drawRect(int width, int height); } |
myDLL.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | #include <stdio.h> #include "myDLL.h" __declspec(dllexport) void drawRect(int width, int height) { int number = 0; for(int i = 0; i < width; i++) { for(int j = 0; j < height; j++) { printf("%d", number); //printf(" HELLO"); } printf("\n"); } } |
build.bat
1 2 3 4 5 6 7 8 9 10 11 12 | @echo off IF NOT EXIST build mkdir build pushd build cl -Zi /EHsc ..\king01.cpp cl -Zi ..\myDLL.cpp /LD popd del *.bat~ *.cpp~ *.un~ *.h~ |