Click here to Skip to main content
15,886,873 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questionhow to send message to CCmdTarget Pin
spiritofklanawa29-Jan-06 9:45
spiritofklanawa29-Jan-06 9:45 
AnswerRe: how to send message to CCmdTarget Pin
Ryan Binns29-Jan-06 17:34
Ryan Binns29-Jan-06 17:34 
QuestionWin32 project type Pin
zon_cpp29-Jan-06 9:33
zon_cpp29-Jan-06 9:33 
AnswerRe: Win32 project type Pin
Christian Graus29-Jan-06 15:48
protectorChristian Graus29-Jan-06 15:48 
GeneralRe: Win32 project type Pin
zon_cpp29-Jan-06 23:17
zon_cpp29-Jan-06 23:17 
GeneralRe: Win32 project type Pin
Christian Graus30-Jan-06 9:15
protectorChristian Graus30-Jan-06 9:15 
QuestionRe: MDI-Opening a new document type from IDR_MAINFRAME Pin
misugi29-Jan-06 9:25
misugi29-Jan-06 9:25 
QuestionDLL crashing Pin
tansey429-Jan-06 8:48
tansey429-Jan-06 8:48 
I recently wrote a simulator for a card game, and I wanted people to have the ability to extend the default AI by writing their own. I set it up so that people could write a DLL and the simulator would look for it. However, when I run the simulator using the DLL, it crashes at the start of the 2nd hand. The wierd part is that if I copy/paste the code from the DLL to the actual simulator, it runs fine.

The problem occurs when I try to access (not dereference) a pointer which is passed to the DLL's function.

This is the code I'm using to access the dll:
	string dllName = "BotAI.dll";<br />
	const char* functionName = "?getBotDecision@@YA?AVAction@@AAVHandHistory@@PAVStatsDB@@_N@Z";<br />
	HMODULE module = LoadLibrary(dllName.c_str());<br />
	// our function pointer for the function we defined in the dll<br />
	Action (*theDllFunc)( HandHistory&,StatsDB*,bool) = 0;<br />
<br />
	if (!module)<br />
	{<br />
		cout << dllName << " not found or load failed.\n" << endl;<br />
		Sleep( 10000 );<br />
		exit(1);<br />
	}<br />
<br />
	// retrieve our function from the .dll by name<br />
	theDllFunc = (Action (*)(HandHistory&,StatsDB*,bool))GetProcAddress(module, functionName);<br />
	Action result(ACTION_Fold);//fold is the default action<br />
	if (!theDllFunc)<br />
	{<br />
		cout << functionName << " not found inside " << dllName << " or load failed.\n" << endl;<br />
		Sleep(10000);<br />
	}<br />
	else<br />
	{ // load was sucessful<br />
		// we can now use the function pointer to call the function<br />
		result = theDllFunc(hand, stats, verbose );<br />
	}<br />
	// important, free the dll<br />
	if (!FreeLibrary(module))<br />
		cout << "error releasing the module loaded from " << dllName << endl; <br />
	return result;


The strange part as I said is that it runs fine for 1 hand using the DLL for all 10 players, then hand #2 starts and it crashes while accessing a function call to StatsDB. However if I put all the code into the actual simulator and comment out all the above code, it works fine.

Note that I'm compiling the DLL with the same compiler as the simulator, and am using the same static library for the DLL as for the simulator. Also, it accesses the DLL fine for the first hand, and only crashes on the 2nd hand. Each player accesses the DLL only once per hand, so I am inclined to think it is something to do with accessing the DLL twice from the same player...or something along those lines. As I've said, it works for the entire simulation if I just copy/paste the code from the dll to the simulator, and I've done a lot of simulator testing, so that's not what's wrong. Any ideas?
AnswerRe: DLL crashing Pin
Stephen Hewitt29-Jan-06 11:25
Stephen Hewitt29-Jan-06 11:25 
GeneralRe: DLL crashing Pin
tansey429-Jan-06 15:33
tansey429-Jan-06 15:33 
GeneralRe: DLL crashing Pin
Stephen Hewitt29-Jan-06 15:38
Stephen Hewitt29-Jan-06 15:38 
AnswerRe: DLL crashing Pin
Prakash Nadar29-Jan-06 17:46
Prakash Nadar29-Jan-06 17:46 
General[Message Deleted] Pin
Laxman929-Jan-06 18:00
Laxman929-Jan-06 18:00 
GeneralRe: DLL crashing Pin
Prakash Nadar29-Jan-06 18:18
Prakash Nadar29-Jan-06 18:18 
GeneralRe: DLL crashing Pin
Owner drawn29-Jan-06 18:35
Owner drawn29-Jan-06 18:35 
AnswerRe: DLL crashing Pin
Laxman929-Jan-06 18:31
Laxman929-Jan-06 18:31 
QuestionF1 help annoyance Pin
Uakari29-Jan-06 3:47
Uakari29-Jan-06 3:47 
AnswerRe: F1 help annoyance Pin
Owner drawn29-Jan-06 17:03
Owner drawn29-Jan-06 17:03 
QuestionRe: F1 help annoyance Pin
Uakari29-Jan-06 22:56
Uakari29-Jan-06 22:56 
AnswerRe: F1 help annoyance Pin
Owner drawn29-Jan-06 22:58
Owner drawn29-Jan-06 22:58 
GeneralRe: F1 help annoyance Pin
Uakari29-Jan-06 23:16
Uakari29-Jan-06 23:16 
GeneralRe: F1 help annoyance Pin
Owner drawn29-Jan-06 23:31
Owner drawn29-Jan-06 23:31 
GeneralRe: F1 help annoyance Pin
Uakari30-Jan-06 1:51
Uakari30-Jan-06 1:51 
GeneralRe: F1 help annoyance Pin
Owner drawn30-Jan-06 16:54
Owner drawn30-Jan-06 16:54 
QuestionDatabase conversion using C++ Pin
SWDevil29-Jan-06 1:49
SWDevil29-Jan-06 1:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.