DialogBox Problem

In one COM object project (DLL, in-proc, no MFC
support) I need to show a dialog box. I added the box in the resources and everything is fine. Till that moment I'm using the default resource name IDD_DIALOG1.

Because I don't have MFC, I need to use Win32 DialogBox function (I need modal dialog).
So I wrote something like this:

int nRes = DialogBox(NULL,
DWORD dwErr = GetLastError();

LRESULT CALLBACK DlgFunc( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam ) {
      switch( message )
            case WM_INITDIALOG:
                        return TRUE;

            case WM_COMMAND:
                  if (LOWORD(wParam) == IDOK || LOWORD(wParam) ==
                        EndDialog(hDlg, LOWORD(wParam));
                        return TRUE;
    return FALSE;

When I debug this fragment of code, I receive, that nRes = -1; dwErr = 1814; // ERROR_RESOURCE_NAME_NOT_FOUND
When I try the same code in a normal Wi32 App, everything is fine and I see the dialog box.
I also tried to put real hwnd and hinst in DialogBox function - the same result
Can you help me please how can I show my dialog box?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

First parameter of DialogBox function is:
[in] Handle to the module whose executable file contains the dialog box template.

When you set this parameter to NULL, program tries to search for IDD_DIALOG1 in the caller executable resources. You need to set here COM Dll instance. I don't remember where can you get it. For example, in non-COM Dll hInstance is passed as parameter to DllMain and may be kept in global variable for later use. I think something similar must be also in COM Dll.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AlexFM is right about the instance handle. You can obtain it by calling 'GetModuleHandle()' with a NULL parameter, e.g.


hInst = (HINSTANCE) GetModuleHandle ( NULL);

(HINSTANCE and HMODULE are in fact the same).

Pass this handle to 'DialogBox()' and it shoud work.
If this parameter is NULL, GetModuleHandle returns a handle to the file used to create the calling process.

Your COM DLL should have a DLLMain function which is called on DLL loading.
Just memorize the hinstDLL parameter and use it in the DialogBox call.


  DWORD fdwReason,
  LPVOID lpvReserved
  switch (fdwReason)
      g_hinstDLL = hinstDLL ;
      break ;
      break ;
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.