App wont run from GUI (dynamic code-loading app)

Hey, im trying to learn to implement the hot loading thing.

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~

Edited by C_Worm on Reason: Initial post
By "windows GUI" you mean Explorer window?
When you double click executable - is this file in same folder as "build" folder? They should be right next to each other as you are loading dll file from it.

To debug crash, you reproduce it and then attach debugger. This will allow to examine call stack and variables to determine what is happening.

Edited by Mārtiņš Možeiko on
Yes thanks, that was it.

it searched the wrong folder! :)