|
-
Nov 22nd, 2002, 03:55 PM
#1
Thread Starter
Member
My Dll is unable to load resources !?
I don`t know the reason but my dll isn`t be able to load resources. Even that simple code below, fails.
CString str;
str.LoadResource(IDS_MYSTR);
I tried to create a modal dialog but it also failed to load resource of the dialog template.
CDialog myDlg(IDD_DIALOG_MYDLG);
myDlg.DoModal(); // Returns -1
I even tried to write;
CDialog *pMyDlg = new CDialog;
pMyDlg->Create(IDD_DIALOG_MYDLG); //Create(...) asserts
in dlgcore.cpp
BOOL CDialog::Create(LPCTSTR lpszTemplateName, CWnd* pParentWnd)
{
ASSERT(IS_INTRESOURCE(lpszTemplateName) || AfxIsValidString(lpszTemplateName));
m_lpszTemplateName = lpszTemplateName; // used for help
if (IS_INTRESOURCE(m_lpszTemplateName) && m_nIDHelp == 0)
m_nIDHelp = LOWORD((DWORD_PTR)m_lpszTemplateName);
#ifdef _DEBUG
if (!_AfxCheckDialogTemplate(lpszTemplateName, FALSE))
{
ASSERT(FALSE); // invalid dialog template
!!!! DEBUGGER STOPS EXECUTION {AFTER THE ASSERT(FALSE)} HERE !!!!!!
namePostNcDestroy(); // cleanup if Create fails too soon
return FALSE;
}
#endif //_DEBUG
......
.....
}
I don`t know how to overcome that problem. If you have experienced the same problem and/or know the solution, would you please let me know
Thanks in advance
-
Nov 23rd, 2002, 07:46 AM
#2
Are you absolutly sure that the resource script is in your project and contains all the resources you load?
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Nov 23rd, 2002, 07:47 AM
#3
There is also something with the resource instance handle in MFC, but I don't know much about that. Have you tried tracing with a debugger through the LoadString call?
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Nov 23rd, 2002, 09:43 AM
#4
Thread Starter
Member
Firstly, thanks for your reply.
I rechecked the resources and didn`t find any mistake.
I put a breakpoint on the code
CDialog myDlg(IDD_DIALOG_MYDLG);
and in the Locals window:
myDlg
- CDialog
- m_lpszTemplateName 0x00000007 <Bad Ptr> const char *
IDD_DIALOG_MYDLG is defined as 7 and the value of m_lpszTemplateName is correct, so I even don`t know why it`s a bad pointer.
-
Nov 23rd, 2002, 10:14 AM
#5
Monday Morning Lunatic
It's an invalid pointer, but that's ok because it isn't *used* as one (see the documentation...).
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Nov 23rd, 2002, 10:59 AM
#6
Thread Starter
Member
The bad prt m_lpszTemplateName is the reason of the assertion
see below:
// in CDialog::Create(...)
#ifdef _DEBUG
if (!_AfxCheckDialogTemplate(lpszTemplateName, FALSE)) // m_lpszTemplateName is equal to lpszTemplateName
{
ASSERT(FALSE); // invalid dialog template
!!!! DEBUGGER STOPS EXECUTION {AFTER THE ASSERT(FALSE)} HERE !!!!!!
namePostNcDestroy(); // cleanup if Create fails too soon
return FALSE;
}
#endif //_DEBUG
-
Nov 23rd, 2002, 11:05 AM
#7
Thread Starter
Member
Debugger traces
ERROR: Cannot find dialog template with IDD 0x0007.
BOOL AFXAPI _AfxCheckDialogTemplate(LPCTSTR lpszResource, BOOL bInvisibleChild)
{
ASSERT(lpszResource != NULL);
HINSTANCE hInst = AfxFindResourceHandle(lpszResource, RT_DIALOG);
HRSRC hResource = ::FindResource(hInst, lpszResource, RT_DIALOG); // FindResource or AfxFindResourceHandle is unsuccessful
if (hResource == NULL)
{
if (DWORD_PTR(lpszResource) > 0xffff)
TRACE(traceAppMsg, 0, _T("ERROR: Cannot find dialog template named '%s'.\n"),
lpszResource);
else
TRACE(traceAppMsg, 0, "ERROR: Cannot find dialog template with IDD 0x%04X.\n",
LOWORD((DWORD_PTR)lpszResource));
return FALSE;
}
.............
............
...........
}
BTW, You`re right Parksie, m_lpszTemplateName is OK.
In that case I realized that MFC is hell.
Last edited by might; Nov 23rd, 2002 at 11:19 AM.
-
Nov 23rd, 2002, 08:40 PM
#8
Are you sure that AfxFindResourceHandle returns a valid value?
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Nov 24th, 2002, 06:57 AM
#9
Thread Starter
Member
I realized the problem.
When I call AfxGetResourceHandle() in CWinApp::InitInstance() of my DLL it returns 0x490000. Resource handle of the main executable is 0x400000. And When I call AfxGetResourceHandle() in an exported function of the Dll, it returns 0x400000; the resource handle of the exe, not the dll !?
So, When the Dll tries to load a resource, it tries to find in the main executable`s. Thus, that becomes almost impossible to load it.
Last edited by might; Nov 24th, 2002 at 07:04 AM.
-
Nov 25th, 2002, 04:09 AM
#10
That's what I guessed. You can set this handle with AfxSetResourceHandle, but you have to reset it after loading, else all subsequent resource loading ops in the main exe will fail...
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|