News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Question about creating include files for HJWASM64

Started by Vortex, July 11, 2016, 04:03:14 AM

Previous topic - Next topic

Vortex

Concerning 64-bit programming with HJWASM, is to possible to consider that everything can be QWORDs in include files? ( like DWORDs in masm32 include files ) :  My intention is to convert all the DWORDs to QWORDs for 64-bit compatibility.

A quick example, kernel32.inc :

ActivateActCtx PROTO :QWORD,:QWORD
AddAtomA PROTO :QWORD
AddAtom equ <AddAtomA>

AddAtomW PROTO :QWORD
AddConsoleAliasA PROTO :QWORD,:QWORD,:QWORD
AddConsoleAlias equ <AddConsoleAliasA>

AddConsoleAliasW PROTO :QWORD,:QWORD,:QWORD
AddLocalAlternateComputerNameA PROTO :QWORD,:QWORD
AddLocalAlternateComputerName equ <AddLocalAlternateComputerNameA>
.
.
.

habran

That would probably work, in that case it would be better to use INT_PTR and than it would be valid for both 32 and 64 bit, however, that would be the same as ToutEnMasm's SDK with XMASM.
WinInc can be used in both 32 and 64 bit and it shows what kind of data is used:
Quote
Add typedef proto stdcall :HBITMAP,:HBITMAP,:ptr DWORD
ReplaceIcon typedef proto stdcall :DWORD,:HICON,:ptr DWORD
SetOverlayImage typedef proto stdcall :DWORD,:DWORD
Replace typedef proto stdcall :DWORD,:HBITMAP,:HBITMAP
AddMasked typedef proto stdcall :HBITMAP,:COLORREF,:ptr DWORD
Draw typedef proto stdcall :ptr IMAGELISTDRAWPARAMS
Remove typedef proto stdcall :DWORD
GetIcon typedef proto stdcall :DWORD,:DWORD,:ptr HICON
IMHO it would be better idea to concentrate on going through WinInc and recheck everything to work properly,
It could be a collective task, we could share headers to be tested. 
Cod-Father

Vortex

Hi habran,

Thanks for the information. I will try WinInc, it's a nice and sophisticated work. I will try the all everything is QWORD method.

mineiro

On x86-64, when you move a value using 32 bits register it "zero' upperside of 64 bits register.
eg:
mov rax,-1
mov eax,12345678h

now rax is not 0ffffffff12345678h, instead it is 0000000012345678h.

You need change structure alignment to 8 by command line, handles (all structure members that start with 'h' on masm32 include will be qwords), all members that start with 'lp' and 'p' (pointers) are now 64 bits too. Equates remains the same, don't need touch. Functions prototipe only the ones that need handles,pointers and long pointers are 64 bits.
So, wParam, lParam and uMsg are 32 bits, hWnd is 64 bits, but you can consider use 64 bits because that fact above.
I'd rather be this ambulant metamorphosis than to have that old opinion about everything

jj2007

Quote from: mineiro on July 12, 2016, 09:32:16 AMSo, wParam, lParam and uMsg are 32 bits, hWnd is 64 bits, but you can consider use 64 bits because that fact above.

Does that mean DefWindowProc works with mixed size arguments?

hutch--

JJ,

If you save the 4 registers that are passed to the WndProc into locals, you use them with DefWindowProc() as the 4 arguments required and you have no reason to change from 4 QWORD variables from the original 64 bit registers.

mineiro

#6
I do not have tested ok, I do not have winx86-64, but, if you have function below:

WndProc   proc hWnd:Qword,uMsg:dword,wParam:dword,lParam:dword
        ret
WndProc   endp

But parameters are passed by registers rcx,rdx,r8,r9
so, dwords turns into qwords.

WndProc   proc hWnd:qword,uMsg:qword,wParam:qword,lParam:qword
mov hWnd,rcx
mov uMsg,rdx
mov wParam,r8
mov lParam,r9
        ret
WndProc   endp

And above code is supposed the same as below

WndProc   proc hWnd:qword,uMsg:qword,wParam:qword,lParam:qword
mov hWnd,rcx        ;<-qword
mov uMsg,edx
mov wParam,r8d     ;<-dword
mov lParam,r9d
;----above is prologue of this code
;here goes your code
;---below is epilogue of this code, supose you don't remember if registers rcx and rdx is trashed
;so you move from function parameter to register back again
mov rcx,hWnd
mov rdx,uMsg
mov r8,wParam
mov r9,lParam
call DefWindowProc
;...
        ret
WndProc   endp

---edited---
inserted defwindowproc.
I'd rather be this ambulant metamorphosis than to have that old opinion about everything

habran

WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
WndProc proc hWnd:QWORD, uMsg:DWORD, wParam:QWORD, lParam:QWORD
Cod-Father

hutch--

If you can find a reliable way to get the argument count in API functions then you can automate an entire set of Win 64 prototypes that match the libraries. Getting the names out of Microsoft format libraries is a reasonably simple operation, just scan the library for the starting "imp" notation then copy it up to the following zero terminator. Its the argument count that cannot be obtained from the libraries. Perhaps a full scan of the Microsoft header files could produce the argument count.

mineiro

Quote from: habran on July 12, 2016, 07:18:11 PM
WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
WndProc proc hWnd:QWORD, uMsg:DWORD, wParam:QWORD, lParam:QWORD
Yes, wParam and lParam are qwords, thanks for correct.
uMsg being dword is pseudo promoted to qword, as Chen say, upperside is ignored.
And this point can create confusion, because if somebody is coding thinking with qwords but the real meaning is dword so weird things can happen.
So, I think it's better define types exactly
https://msdn.microsoft.com/en-us/library/windows/desktop/aa383751(v=vs.85).aspx
I'd rather be this ambulant metamorphosis than to have that old opinion about everything

habran

#10
QuoteSo, I think it's better define types exactly
Yes, that is why WinInc is the best solution.
Cod-Father

hutch--

It just happens to be a matter of fact that the 4 arguments passed to a WndProc are 64 bit registers and even if only the bottom 4 bytes are used, they are still QWORD 64 bit registers. Be careful what you wish for using WinInc as it locks you into the Microsoft "mystery bag" style of header files. You cannot enforce strong typing in assembler as the data always collapses to assembler data sizes. If you want strongly typed data, use a C compiler.

habran

Microsoft "mystery bag" style of header files:
WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM

opposite to perfectly clear what we are doing:
WndProc proc hWnd:QWORD, uMsg:QWORD, wParam:QWORD, lParam:QWORD

Aussie way of thinking ::)

How many more years I have to spend in OZ to start thinking upside down, or it is a gift only to people born here :icon_confused:
Cod-Father

rrr314159

Quote from: habran on July 13, 2016, 08:19:49 AMHow many more years I have to spend in OZ to start thinking upside down

Just to help get in the mood you ought to turn your Godfather avatar upside down :)
I am NaN ;)

habran

Thanks for the advice rrr314159, I'll think about it :bgrin:

I think you should use that avatar instead of me because you are the one who first renamed JWasm to HJWasm ;)
Cod-Father