The MASM Forum

General => The Campus => Topic started by: Landsfiskalen on January 16, 2015, 04:24:27 AM

Title: Custom procedure question
Post by: Landsfiskalen on January 16, 2015, 04:24:27 AM
Hi all!
If I want to create a custom procedure, am I going about it the correct way if I do like this?


DisableCtrls proto :BOOL

....

invoke DisableCtrls,0

....

DisableCtrls proc Enabled:BOOL
invoke EnableWindow,hButton,Enabled;
DisableCtrls endp


Right now it crashes when I call the procedure with the invoke command.

Any help would be greatly appreciated!
Title: Re: Custom procedure question
Post by: fearless on January 16, 2015, 05:07:35 AM
This is how i might do this:

EnableCtrls proto :DWORD

....

invoke EnableCtrls, TRUE ; TRUE for enable, FALSE for disable - changed name of function for better understanding of function based on api call below

....

EnableCtrls proc dwEnabledOrDisable:DWORD
   invoke EnableWindow, hButton, dwEnabledOrDisable ; last param uses TRUE or FALSE based on win32 documentation, so easier to stick with that for our parameter.
   ret ; need return here when coming back out of function, otherwise it might run on into some other function below it
EnableCtrls endp
Title: Re: Custom procedure question
Post by: Landsfiskalen on January 16, 2015, 06:49:32 AM
Cheers! Looks way nicer than my attempt. :) I was missing the ret in the proc... Doh!

Quote from: fearless on January 16, 2015, 05:07:35 AM
This is how i might do this:

EnableCtrls proto :DWORD

....

invoke EnableCtrls, TRUE ; TRUE for enable, FALSE for disable - changed name of function for better understanding of function based on api call below

....

EnableCtrls proc dwEnabledOrDisable:DWORD
   invoke EnableWindow, hButton, dwEnabledOrDisable ; last param uses TRUE or FALSE based on win32 documentation, so easier to stick with that for our parameter.
   ret ; need return here when coming back out of function, otherwise it might run on into some other function below it
EnableCtrls endp

Title: Re: Custom procedure question
Post by: dedndave on January 16, 2015, 07:16:52 AM
i rarely use BOOL types, because they're a little confusing
if you look in windows.inc...

bool                        typedef BYTE
BOOLEAN                     typedef BYTE
BOOL                        typedef DWORD


looks like an accident waiting to happen
Title: Re: Custom procedure question
Post by: Landsfiskalen on January 16, 2015, 10:47:48 AM
Yikes! What do you recommend using instead, Dave? Byte or DWORD?

Quote from: dedndave on January 16, 2015, 07:16:52 AM
i rarely use BOOL types, because they're a little confusing
if you look in windows.inc...

bool                        typedef BYTE
BOOLEAN                     typedef BYTE
BOOL                        typedef DWORD


looks like an accident waiting to happen
Title: Re: Custom procedure question
Post by: dedndave on January 16, 2015, 10:55:10 AM
well - you don't want to use BYTE - the stack should always be 4-aligned for 32-bit code
DWORD is probably the best choice in this case
Title: Re: Custom procedure question
Post by: Landsfiskalen on January 16, 2015, 11:11:07 AM
Ah, true, true. Works like a charm now.  :t

Quote from: dedndave on January 16, 2015, 10:55:10 AM
well - you don't want to use BYTE - the stack should always be 4-aligned for 32-bit code
DWORD is probably the best choice in this case