0

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!

MrSilverSnorkel
  • 499
  • 1
  • 5
  • 17
  • 1
    Maybe resource is not in `GetModuleHandle(NULL)`. Test it with `GetModuleHandle("fullpath")` where "fullpath" is the exe/ocx/dll which holds the resource. – Barmak Shemirani Sep 10 '15 at 21:10
  • 1
    The error message is unequivocal. The resource is not there. You passed an instance of `GetModuleHandle(NULL)` which is the process module. But your BHO is surely in a DLL. So why would the resource be in the process module? Don't you need to pass the instance for your module? – David Heffernan Sep 10 '15 at 21:35
  • [Accessing the current module's HINSTANCE from a static library](http://blogs.msdn.com/b/oldnewthing/archive/2004/10/25/247180.aspx). – IInspectable Sep 11 '15 at 00:37
  • @DavidHeffernan right you are! I also needed to change the third parameter from NULL to the the browser window handle to avoid a "no parent window" error, but now the dialog is created. Still having trouble showing it, but that's another can of worms. If you answer the question, I will accept the answer. – MrSilverSnorkel Sep 11 '15 at 14:53
  • @BarmakShemirani right you are as well - see my answer to Mr Heffernan. – MrSilverSnorkel Sep 11 '15 at 14:53

1 Answers1

2

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.

Community
  • 1
  • 1
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490