Interesting read on Error handling
An interesting article on error handling in software.
Well it seems God really does not want me to have a working computer at home. Again, I've had problems with my machine, I just rebooted and paff! It would not boot anymore. I boot the Windows CD and it tells me it does not even know what kind of formating my Windows partition has. I try reinstalling, no go. I finally reinstalled on another disk and it worked. So I have officially lost 220 Gigs of data!
Me no happy.
Google is at it again, they have just released Google Moon, an extension to their Google Map. With it, you can view parts of the moon, specifically where the moon landings occurred, exactly 36 years ago.
[ Source: Slashdot ]
It's interesting how life works. It's only been a couple of days that I had to load a DLL dynamically at work and now I have to do the same for a project I'm working at home. The only difference is that I need to load child dialog resources into my application.
You would think that it wouldn't be too hard, but MFC always manages to make it hard. When will I learn to not use MFC? Anyways what I needed was to call the create on a dialog passing it my parent window.
DLLNow you would think that by calling this function in the CDialog derived class that it would work. But somehow, that's does not work. At first it was errors because it could not the resource. This is easily repaired by doing this:
CDlg::InitDlg( CWnd* pParent )
{
VERIFY( Create( IDD, pParent ) );
}
DLLBut now, I was getting errors because of a map somewhere in MFC which was NULL. I checked everywhere but I did not find answers. So ended coding it like this:
CDlg::InitDlg( CWnd* pParent )
{
AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
VERIFY( Create( IDD, pParent ) );
}
AppBy magic, this worked. It's not very elegant but this was done late at night. If I change this, I'll post another Blog about it.
CApp::ShowDllResource()
{
HINSTANCE hResApp = AfxGetResourceHandle();
HINSTANCE hResExt = GetModuleHandle(_T("DllName.dll"));
if(hResExt)
{ // loading resources was OK
AfxSetResourceHandle(hResExt);
m_pDlgResource->GetDlgWnd()->Create( m_pDlgResource->GetDlgID(), this);
m_pDlgResource->GetWnd()->ShowWindow(SW_SHOW);
AfxSetResourceHandle(hResApp);
}
}
Wow, it's been a while since I've blog here.
A quick note, dynamically linking to DLLs. It's something I had to do for work and it's not something I do normally. I have to say, what an experience. It's not that bad but when you are loading the wrong dll and can't figure out why your exported functions are not found, it can get frustrating! :)
Anyways, if you need to do it or just for me so that I don't forget, here are some good ressources: