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
  • 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)

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.
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails


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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Process filename extension 3 156
dog bark java program 15 82
format the code in java 6 72
Making an alias 7 54
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

746 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now