Hi all,
I am working on an application in which a call is made to a DLL. From that dll a dialog has to be displayed. While doing so I was not able to see the dialog. Dialog is not getting displayed. When i checked the code in debug that handle of the dialog is not assigned. What might be the possible cause for this can you help me...

thanks

You didn't call the function in the DLL correctly would be my guess.

If the application program is a console program then you may have to have a WinMain() inside the dll and call it from the dll. For example if you have a function named foo() in the dll then foo() would call its WinMain() using HINSTANCE that it gets by calling GetModuleHandle(). You could probably name the function anything you want, I just used WinMain()

Here's an example DLL that I did for this thread. I got some of the code from other threads here at DaniWeb.

#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include "mydll.h"

BOOL MakeAWindow(HINSTANCE appInstance,int show);
LRESULT CALLBACK WndProc(HWND window,UINT msg,WPARAM wParam,LPARAM lParam);
HWND MainWindow = 0;

static int*	gInstList	[7]={ 0, 0, 0, 0, 0, 0, 0 };
static int	gInstCnt=0;




int MessageLoop()
{
	MSG msg;
	ZeroMemory(&msg, sizeof(MSG));

	while (GetMessage(&msg, 0, 0, 0))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}

return msg.wParam;
}

INT WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance, 
                   LPSTR lpCmdLine,
                   int nShowCmd)
{
	if (!MakeAWindow(hInstance, nShowCmd))
	{
		MessageBox(0, "Window Creation -- Failed", "Error", MB_OK);
		return 0;
	}

return MessageLoop();

}

BOOL MakeAWindow(HINSTANCE appInstance,int show)
{

	WNDCLASS wc;

	wc.style         = CS_HREDRAW | CS_VREDRAW;
	wc.lpfnWndProc   = WndProc;
	wc.cbClsExtra    = 0;
	wc.cbWndExtra    = 0;
	wc.hInstance     = appInstance;
	wc.hIcon         = LoadIcon(0,IDI_APPLICATION);
	wc.hCursor       = LoadCursor(0,IDC_ARROW);
	wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
	wc.lpszMenuName  = 0;
	wc.lpszClassName = "wc";

	if (!RegisterClass(&wc))
	{
		MessageBox(0, "Failed to register the window class", "Windows Sucks!", 0);
		return FALSE;
	}
	
	MainWindow = CreateWindow("wc",
                                  "Hello",
                                  WS_OVERLAPPEDWINDOW,
				  CW_USEDEFAULT,
				  CW_USEDEFAULT,
				  CW_USEDEFAULT,
				  CW_USEDEFAULT,
				  0,
				  0,
				  appInstance,
				  0);

	if(MainWindow == NULL)
	{
		MessageBox(0,"Function CreateWindow() Failed",0,0);
		return FALSE;
	}
	ShowWindow(MainWindow, show);
	UpdateWindow(MainWindow);

	return TRUE;
}

LRESULT CALLBACK WndProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
    switch(msg)
    {
        case WM_CLOSE:
            DestroyWindow(hwnd);
        break;
        case WM_DESTROY:
            PostQuitMessage(0);
        break;
        default:
            return DefWindowProc(hwnd, msg, wParam, lParam);
    }
    return 0;
}

//
// This function is exported and called from application programs
//
MYDLL_API int foo()
{
    
    HINSTANCE hInst = GetModuleHandle(NULL);
    WinMain(hInst,hInst,0,SW_SHOW);
    return 0;
}

Hi all,
I have just narrowed down the error part. When my code is trying to display the dialog to the DLL the error obtained is 1812(Error_Resource_Data_Not_Found). can anyone guide me how to find which resource is missing?

I think the explanation in this thread will solve that problem.

The problem was resolved.
new CDynLinkLibrary(DLLNAME); was not present in the DLLMAIN function which
will enable the dll’s resource file available to the application

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.