Win32 SDK question - CreateDialog fails - HELP !

Posted on 1998-09-18
Last Modified: 2013-11-19
I am porting a 16-bit DLL to the 32-bit world. The exe which uses this DLL is also being ported. In the DLL there is a function which calls CreateDialog to create a modeless dialog box. The code in the 16 bit world looked like this :

Begin DLL exported function ()
hwnd = NULL;
if (hwnd == NULL)
 hwnd = CreateDialog (hinst,                                MAKEINTRESOURCE (cancel_dialog),

_itoa( TaskInfo.hTask,buffer,8 );
SetDlgItemText(hwnd, Task_ID, buffer);

_itoa( (int) CallArg.thread_handle,buffer,8 );
SetDlgItemText(hwnd, Thread_ID, buffer);

SetWindowLong (hwnd, DWL_USER, (LONG) &CallArg);
MessageBox(NULL,"entering new","Info",MB_OK);

EndDialog (hwnd, 0);
} // end of DLL exported fn.

In the 32 bit world I have changed the 3rd parameter to hParent which is passed from the EXE as the EXE's hWnd.

When I run this in my Win NT 4.0 Workstation the CreateDialog procedure does not create any dialog box on the screen. According to docs, when CreateDialog fails it returns hwnd as NULL and you should be able to see GetLastError to find out which error has occured.

However, though hwnd is returned as NULL, there does'nt seem to be any error set as GetLastError returns 0 !! I've racked my brains out for hours on this - any suggestions ?

Question by:fstab
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +2

Expert Comment

ID: 1322297
I think the problem here is the resource template of this dialog. Where does it reside? Probably because it is in the .DLL the CreateDialog function does not find the resource because it looks in the .EXE resources. Try to see if FindResource function works. If it works then the problem is somewhere else :)

LVL 11

Expert Comment

ID: 1322298
What does this have to do with MFC?  Have you translated this to a straight SDK program, or an MFC program?

What controls are on the dialog template?

What styles does the dialog template carry?

How is cancel_dialog defined?

How was hinst initialized?

If you open the DLL in the IDE, is the resource apparent?

B ekiM

Expert Comment

ID: 1322299
The clue is that it worked in Win16 and doesn't in Win32.

The answer is therefore
1. The hInst should be the hInst of the DLL
2. The CreateDialog call works in Win16 because in this case the hInst is correctly initialized, and fails in Win32 because in this case it isn't.
3. I bet the code includes a LibMain function (Win16 library start up point) which initializes hInst.  Under Win32 this function will never be called, hence hInst has the wrong value in this case.
4. Solution
i. Find LibMain, remove it (and cut out an initialization code)
ii. Delete LibMain
iii. Add DllMain, and paste the initialization code in here (including setting up the hInst)
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 1322300
Thank you all for responding! I shall try to answer your questions first -

1. This is a straight SDK program which was in Win16
2. Yes I did change LibMain to DllMain - I mean before I ran into this problem I had done all the necessary "ports"
3. Here is the dialog template :

#define cancel_dialog 1000
#define Thread_ID 100
#define Task_ID   101

cancel_dialog DIALOG DISCARDABLE  8, 17, 160, 75
CAPTION "Greet DLL - Status"
FONT 8, "MS Sans Serif"
    PUSHBUTTON      "Cancel",IDCANCEL,54,41,52,27
    RTEXT           "thread id = ",-1,43,22,39,8
    EDITTEXT        Thread_ID,85,22,28,12,ES_READONLY | NOT WS_BORDER | NOT
    RTEXT           "task id = ",-1,47,11,35,8
    EDITTEXT        Task_ID,85,11,28,12,ES_READONLY | NOT WS_BORDER | NOT

4. Mikeblas - when I open the DLL in the IDE the resource is *NOT* apparent ! But the resources are not apparent when I open any other EXE or DLL in the IDE - VC++ 5.0.

5. bobby - I have'nt tried FindResource yet so watch this space ..


Expert Comment

ID: 1322301
open the DLL or EXE as resourse ( option near the bottom of the Open Dialog ) to view it.

Expert Comment

ID: 1322302
Remove the .RC from the project, and re-add it.  Somehow it seems to have become separated.

Bridge's tip should confirm if this is the case (do this before my change)

Author Comment

ID: 1322303
I did open the dll as a resource but it shows only the DLL as a folder icon - no tree expanding to show the resources.

Also Answers2000 - this is not a VC project/workspace. All the action takes place through a Makefile which is used by nmake.


Accepted Solution

Answers2000 earned 100 total points
ID: 1322304
Okay here's the answer:
1. Bridge's tip confirms the Resources are not being linked into the 32 bit DLL

2. In Win16 look in the make file.  You will probably find a two stage compile of the resources
i. rc -r or rc /r will compile the .rc into a .res
ii. a second call to rc which links the .res into the DLL

3. In Win32 .res files are linked to your DLL by the linker (link).  
i. Remove 2.ii
ii. Add .res to the link (this will either be in the main make file or a file referenced from link's command line)
iii. Add the .res to the link option (in the make file) dependency list (this is stuff to the right of the colon)

Once you've recompiled everything with the make file, repeat loading the DLL into VC.  You should now see the resources.

Now test the DLL.  If it doesn't check the initialization code in DllMain and that hInst is being setup correctly.  You should be able to confirm this by setting hInst to NULL when you declare it, and adding a test before CreateDialog to check it's

If you're still having trouble or I haven't explained well enough, reject this, and post the make file as part of you're comment (or at least the bits around calls to rc and link).


Author Comment

ID: 1322305
And Answers is the winner ...

Yes Answers - the problem was the .RES was'nt getting linked to the DLL object files while producing the DLL !

Thanks to everybody who did the brain racking .. unfortunately I can't distribute points :-) !!

LVL 11

Expert Comment

ID: 1322306
If the resources are not evident when you open an EXE or DLL in the IDE, then you're not correctly using the IDE.

B ekiM


Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question