Search code examples
c++winapibho

CreateDialog in BHO always fails with error 1813 (resource not found)


I'm working on a BHO written a long time ago in C++, without the use of any of the VS wizards. As a result, this project deviates from the COM conventions and the boilerplate for a COM product. I worked with COM long ago, but never really did any Windows GUI/dialog stuff...

I'm trying to add a dialog box to allow the user to set the values of some new settings:

// serverDialog will be NULL
HWND serverDialog = CreateDialog(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_PROPPAGE_SETTINGS), NULL, DialogProc);

id (!serverDialog) 
{
    int error = GetLastError(); //1813
    ...
}

....

1813 means that the resource cannot be found. The IDD used there is in resource.h, which I manually included where needed.

DialogProc is defined as:

INT_PTR CALLBACK DialogProc(HWND hWndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {
    return FALSE;
}

Which I know I will have to change later if I want the dialog to actually process messages, but I haven't gotten that far yet. The 1813 error suggests failure before the dialog is even created as does the NULL dialog handle returned.

To add the dialog I used the Add Resource wizard and added a small property page.

I've tried to follow advice here, but to no avail.

Thanks!


Solution

  • You are passing GetModuleHandle(NULL) as the instance of the module that contains the resource. But GetModuleHandle(NULL) defines the executable file module. You need to pass the instance of the module containing your code. This question covers that topic: How do I get the HMODULE for the currently executing code?

    You probably ought to pass a window handle to the hWndParent parameter so that the dialog is owned.