Re: Why does this cause "data abort" ?
Thanks for your feedback.
I do error checking, and I am very aware of the m_lpszClassName pointer
being risky, and I make sure I use it properly.
I am trying to bugfix some existing code from someone else. It's too much to
rewrite at this point. I am interested in general pointers, however, that's
not currently the issue at hand. I want to know why certain constructions
don't work properly, not why it's bad practice in general.
As for the LoadIcon one.. no, it's not the reason for the problem.. but it
is strange to me why following occurs, which may be related:
CSomeClass
{
CSomeClass(HINSTANCE hInstance) { m_hInstance = hInstance; };
virtual ~CSomeClass(){};
HINSTANCE m_hInstance;
HICON LoadIcon(UINT nID) {
return (HICON)LoadImage(m_hInstance,
MAKEINTRESOURCE(IDI_APP_ICON),
IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
}
};
// global var
HINSTANCE g_hInstance = NULL;
BOOL APIENTRY DllMain(HANDLE hModule, DWORD dwReason, LPVOID pReserved)
{
switch(dwReason)
{
case DLL_PROCESS_ATTACH:
g_hInstance = (HINSTANCE) hModule;
break;
}
return TRUE;
}
// exported func
void SomeExportedFunc()
{
CSomeClass* p = new CSomeClass(g_hInstance);
HICON hIcon;
// this FAILS
hIcon = p->LoadIcon(IDI_ICON);
// this SUCCEEDS
hIcon = (HICON)LoadImage(m_hInstance, MAKEINTRESOURCE(IDI_ICON),
IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
if (hIcon) DestroyIcon(hIcon);
}
Any clues?
There does seem to be some issue with instance handles or something..
I just don't understand this.
Lisa