?
Solved

LPCTSTR parameters in Windows API and MAKEINTRESOURCE usage

Posted on 2003-03-11
7
Medium Priority
?
1,282 Views
Last Modified: 2013-11-13
Hello...

I previously answered a question about a dialog that won't display, because the calling function was specifying the dialog template name as a string. I remembered I had this problem quite a few times and only using MAKEINTERESOURCE(RESOURCE_ID) would solve the problem.

Wherever resources are involved through the API, LPCTSTR paramters are present in the functions that can receive either a string with the name of the resource (the Dialog Template __name__, in the case above) or the result of the MAKEINTERESOURCE macro.

Looking at the macro, it *seems* to convert the integer ID of a resource to a string, representing the resource name.
If this is the case, how this differs from sending the plain resource name to, let's say, DialogBox function?
When having a dialog with the resource ID of "IDD_DIALOG1", calling
DialogBoxA(hInstance,"IDD_DIALOG1",...) will fail, whereas
DialogBoxA(hInstance,MAKEINTRESOURCE(IDD_DIALOG1),...) will succeed.
The documentation for DialogBox states clearly that the template name can be used to identify the dialog box template. Isn't that the name in the resource? I tried to find the name "IDD_DIALOG1" in the binary resource but found nothing there (Unicode or ASCII) so I am a bit confused about this.

Can anybody shed a bit of light on this? I get the feeling that I am missing something very basic here...
TIA.
0
Comment
Question by:Nosfedra
[X]
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
  • 4
  • 2
7 Comments
 
LVL 1

Expert Comment

by:aamironline
ID: 8119532
Hi,


If you see the MSDN you will find that
The MAKEINTRESOURCE macro is defined as follows:

#define MAKEINTRESOURCE(i)  (LPTSTR) ((DWORD) ((WORD) (i)))

remember resource id actually is an integer not a string
so this is #defined in the resource.h

in the following way

   #define IDD_DIALOG1   101

now if you see the defination of the MAKEINTRESOURCE you can realize that MAKEINTRESOURCE's return values is string of the (specified value in the low-order word and zero in the high-order word).

.: MAKEINTRESOURCE(IDD_DIALOG1) != "IDD_DIALOG1"

cheers
m aamir maniar




0
 

Accepted Solution

by:
WaffleSouffle earned 300 total points
ID: 8119748
I have no answer to your question, sorry.
However, I'd like to add that after playing around with this the slightly fuller documentation for "FindResource()" doesn't appear to work as expected either.

In particular, specifying strings instead of ints, or strings that are converted to ints, does not appear to work:
E.g. FindResource(hInst, "IDD_FOO", "RT_DIALOG");
or
FindResource(hInst, "#IDD_FOO", RT_DIALOG);
or any combination of the above don't work.

I could find no examples which use a string instead of an id. The MFC code for dialogs loads the dialog into memory and calls one of the "CreateDlgIndirect()" type functions faking a modal dialog.

For what it's worth, I remember in the old days (and as it happens nowadays too) you could define a resource to have an id which was actually a string
E.g.
"MyFunkyDialog" DIALOG 0, 0, 256, 84, etc....
and I assume that's what the string lookup is aimed at.

However it doesn't appear to work now. Possibly the move to unicode string storage in resources has broken the lookup, possibly it just isn't supported anymore, or probably I'm just missing something.

Not an answer, but maybe some resolution

0
 
LVL 3

Author Comment

by:Nosfedra
ID: 8119915
Indeed, that's why I was making reference in the post to all functions that take the result of MAKEINTRESOURCE.

My wild guess is that in each such function there is an IF statement that handles the input string.
The result of MAKEINTRESOURCE is actually an address converted to a pointer to a string.
Thus,
MAKEINTRESOURCE(101 /* IDD_DIALOG1 by default*/) would result in a pointer at 0x00000065. I really doubt that that memory address is used per se.

I wonder if this is what really happens and if this was an early hack of function overloading done in C...
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 1

Expert Comment

by:aamironline
ID: 8121104
MAKEINTRESOURCE converts 0x00000065 into string pointer and returns it. it wont return numeric value.
0
 
LVL 3

Author Comment

by:Nosfedra
ID: 8121148
That's what *pointer at* 0x00000065 means.
0
 
LVL 3

Author Comment

by:Nosfedra
ID: 8141880
Does anybody else have any other oppinions on this?
0
 
LVL 3

Author Comment

by:Nosfedra
ID: 8245001
Thanks for your post WaffleSouffle, I appreciate your interest in it.
I am closing this question as apparently I can't get anymore feedback.

Regards,
--Razvan
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
This is about my first experience with programming Arduino.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Simple Linear Regression

800 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