Wednesday, April 27, 2005

Visual Studio 2005 preview

There are a couple of articles on the new features of the Visual Studio 2005 IDE on CodeGuru. They are quite interesting and I can't wait to try it out!

Features I like:

  • Class Diagrams directly in Visual Studio!
  • XML Documentation
  • Editor Change Tracking
Part one and part two.

Sunday, April 24, 2005

DLL Hell part 2

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.

DLL

CDlg::InitDlg( CWnd* pParent )
{
VERIFY( Create( IDD, pParent ) );
}
Now 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:
DLL

CDlg::InitDlg( CWnd* pParent )
{
AFX_MANAGE_STATE(AfxGetStaticModuleState( ));

VERIFY( Create( IDD, pParent ) );
}
But 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:

App

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);
}
}
By 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.

This example was found on CodeProject in the threads at the end of the article.

Wednesday, April 20, 2005

Linking Dynamically To DLL

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: