Win32 - Loading and displaying a dialog within a DLL

Started by
2 comments, last by TheBlackJester 19 years, 2 months ago
Hey guys, been a long time :) Ok, here's the deal. I have a DLL that gets loaded into my application at run time. I have defined a resource file within that DLL that defines a dialog box and I'm trying to create and display the dialog from the DLL. Some source code for you.... This code is in the DLL along with the resource file and resource header


/**********************************************************************
/* CIgnusDebug.cpp
/*
/* Contains the function implementations for the CIgnusDebug class
/*
/**********************************************************************/

#include "CIgnusDebug.h"

//
// Static instantiation
//
char	CIgnusDebug::m_szTextBuf[MAX_BUFFER_SIZE];
HWND	CIgnusDebug::m_hDlg = NULL;
HINSTANCE	g_hDLL = GetModuleHandle(NULL);


//
// INIT
//
void	CIgnusDebug::Init()
{
	char	errBuf[256];
	char	errStr[256];

	// Need to load the richedit dll
	if(!LoadLibrary("riched20.dll"))
		MessageBox(NULL, "Error Loading riched20.dll. Verify that this DLL is loaded on the system", "IgnusEngine - Error", MB_OK | MB_ICONINFORMATION);

	// Create the dialog box
	m_hDlg = CreateDialog(g_hDLL, MAKEINTRESOURCE(IDD_IGNUS_LOG),NULL, (DLGPROC)LogDlgProc);
	if(!m_hDlg)
	{
		FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), LANG_SYSTEM_DEFAULT, errBuf, 256, NULL);	
		sprintf(errStr, "Error Loading the Log Dialog: %s", errBuf);
		MessageBox(NULL, errStr, "IgnusEngine - Error", MB_OK | MB_ICONINFORMATION);
	}

}

The CreateDialog function fails. The error message returned from windows is : "The specified resource name cannot be found in the image file" I've looked basically everywhere and there isn't much info on this error. Any insight would be very helpful. Thanks!

"With my feet upon the ground I lose myself between the sounds and open wide to suck it in, I feel it move across my skin. I'm reaching up and reaching out. I'm reaching for the random or what ever will bewilder me, what ever will bewilder me. And following our will and wind we may just go where no one's been. We'll ride the spiral to the end and may just go where no one's been." - Maynard James Keenan Name: [email=darkswordtbj@hotmail.com]TheBlackJester[/email]Team: Wildfire Games
Projects O A.D.The Last Alliance

Advertisement
Quoting the MSND, about GetModuleHandle():
Quote:
If this parameter is NULL, GetModuleHandle returns a handle to the file used to create the calling process (.exe file).


Your g_hDLL is the application module handle. To get the dll handle, get it from the DllMain() function.

I didn't test this. I usually avoid this kind of situation.

HTH,

Hey,


Thanks for the reply.

I actually was using that at one point, but it didn't seem to be the issue. At least not that by itself. But you are correct and I should change it back because it is at least fundamentally closer to correct.

About why I'm doing it this way: My engine is contained in a DLL and I want to create a log/debug window with rich edit text control and I'm just spitting out text to this control. Pretty much the same little console that quakeIII arena uses and I think doom3 uses the same because it's the same code base.

If you know of another way of doing something like this while keeping it outside of the application using the DLL then I'm all ears :)

Thanks again!

"With my feet upon the ground I lose myself between the sounds and open wide to suck it in, I feel it move across my skin. I'm reaching up and reaching out. I'm reaching for the random or what ever will bewilder me, what ever will bewilder me. And following our will and wind we may just go where no one's been. We'll ride the spiral to the end and may just go where no one's been." - Maynard James Keenan Name: [email=darkswordtbj@hotmail.com]TheBlackJester[/email]Team: Wildfire Games
Projects O A.D.The Last Alliance

As usual, I must have been missing something simple becuase when I used the DLL instance from DllMain, it worked perfect.

Sorry for being such an ignoramous, and thanks for your suggestion!

"With my feet upon the ground I lose myself between the sounds and open wide to suck it in, I feel it move across my skin. I'm reaching up and reaching out. I'm reaching for the random or what ever will bewilder me, what ever will bewilder me. And following our will and wind we may just go where no one's been. We'll ride the spiral to the end and may just go where no one's been." - Maynard James Keenan Name: [email=darkswordtbj@hotmail.com]TheBlackJester[/email]Team: Wildfire Games
Projects O A.D.The Last Alliance

This topic is closed to new replies.

Advertisement