Link to home
Start Free TrialLog in
Avatar of Nosfedra
Nosfedra

asked on

LPCTSTR parameters in Windows API and MAKEINTRESOURCE usage

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.
Avatar of aamironline
aamironline

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




ASKER CERTIFIED SOLUTION
Avatar of WaffleSouffle
WaffleSouffle

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Nosfedra

ASKER

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...
MAKEINTRESOURCE converts 0x00000065 into string pointer and returns it. it wont return numeric value.
That's what *pointer at* 0x00000065 means.
Does anybody else have any other oppinions on this?
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