May 02, 2024, 09:04:10 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


MAKEINTRESOURCE

Started by fasecero, January 05, 2010, 04:11:19 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

fasecero

how to emulate this macro? Here is the C definition:


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



LarryMc

Is this what you are looking for?
SUB MAKEINTRESOURCE(n as WORD),POINTER
DEF pReturn as POINTER
_asm
lea eax,[ebp-4]
mov ebx,[ebp+8]
mov [eax],ebx
_endasm
RETURN pReturn
endsub
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

fasecero

I did a second search and I found this function in another post. Sorry,  I could not find anything the first time, perhaps I misspelled the name.

I'll try it , thanks.

fasecero

The function work fine, thanks again.

sapero

There is yet another way to cast a variable to pointer: &*<TYPE>variableWhere TYPE can be any known variable type like INT, POINT.
If you need to call a function with general-pointer parameter, the parameter you have is defined as char, int or word, and you need to pass it by value, use a heper function (like MAKEINTRESOURCE) or the above re- and de-reference:
declare extern OpenResourceDialog(pointer id_or_name)
' where id_or_name can be an integer 0-65535, or a string pointer.

' usage examples:
OpenResourceDialog(5)
OpenResourceDialog("dialog2")
int id = 8;
OpenResourceDialog(id) ' <- BUG! id is passed by reference
OpenResourceDialog(&*<int>id) ' <- OK! id is passed by value
OpenResourceDialog(&*<window>id) ' OK! id is passed by value


Example 2: converting pointers to integers:
WINRECT rc
pointer value = 3
rc.left = value ' ERROR invalid assignment
rc.left = &*<int>value ' OK

fasecero

I'm using this precisely to open dialogs from resources.
Very useful information, thanks.