Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Win32 SDK question - CreateDialog fails - HELP !

Posted on 1998-09-18
10
Medium Priority
?
746 Views
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),
NULL,
DlgProc);

_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 ?

Thanks
fstab.
0
Comment
Question by:fstab
  • 3
  • 3
  • 2
  • +2
10 Comments
 

Expert Comment

by:bobbym
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 :)

0
 
LVL 11

Expert Comment

by:mikeblas
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
0
 
LVL 8

Expert Comment

by:Answers2000
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)
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 1

Author Comment

by:fstab
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
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CAPTION "Greet DLL - Status"
FONT 8, "MS Sans Serif"
BEGIN
    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
                    WS_TABSTOP
    RTEXT           "task id = ",-1,47,11,35,8
    EDITTEXT        Task_ID,85,11,28,12,ES_READONLY | NOT WS_BORDER | NOT
                    WS_TABSTOP
END

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 ..

Thanks
fstab.
0
 
LVL 1

Expert Comment

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

Expert Comment

by:Answers2000
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)
0
 
LVL 1

Author Comment

by:fstab
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.

Thanks
fstab.
0
 
LVL 8

Accepted Solution

by:
Answers2000 earned 400 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
non-NULL.

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



0
 
LVL 1

Author Comment

by:fstab
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 :-) !!

fstab.
0
 
LVL 11

Expert Comment

by:mikeblas
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

0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

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

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…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

564 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