Author Topic: Question about creating include files for HJWASM64  (Read 16174 times)

Vortex

  • Member
  • *****
  • Posts: 2794
Question about creating include files for HJWASM64
« on: July 11, 2016, 04:03:14 AM »
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 :

Code: [Select]
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

  • Member
  • *****
  • Posts: 1228
    • uasm
Re: Question about creating include files for HJWASM64
« Reply #1 on: July 11, 2016, 06:20:52 AM »
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

  • Member
  • *****
  • Posts: 2794
Re: Question about creating include files for HJWASM64
« Reply #2 on: July 12, 2016, 03:54:16 AM »
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

  • Member
  • ****
  • Posts: 958
Re: Question about creating include files for HJWASM64
« Reply #3 on: July 12, 2016, 09:32:16 AM »
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

  • Member
  • *****
  • Posts: 13957
  • Assembly is fun ;-)
    • MasmBasic
Re: Question about creating include files for HJWASM64
« Reply #4 on: July 12, 2016, 11:17:32 AM »
So, 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--

  • Administrator
  • Member
  • ******
  • Posts: 10583
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Question about creating include files for HJWASM64
« Reply #5 on: July 12, 2016, 12:40:02 PM »
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.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

mineiro

  • Member
  • ****
  • Posts: 958
Re: Question about creating include files for HJWASM64
« Reply #6 on: July 12, 2016, 01:19:44 PM »
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.
« Last Edit: July 12, 2016, 02:23:19 PM by mineiro »
I'd rather be this ambulant metamorphosis than to have that old opinion about everything

habran

  • Member
  • *****
  • Posts: 1228
    • uasm
Re: Question about creating include files for HJWASM64
« Reply #7 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
Cod-Father

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 10583
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Question about creating include files for HJWASM64
« Reply #8 on: July 12, 2016, 08:04:50 PM »
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.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

mineiro

  • Member
  • ****
  • Posts: 958
Re: Question about creating include files for HJWASM64
« Reply #9 on: July 12, 2016, 11:08:29 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

  • Member
  • *****
  • Posts: 1228
    • uasm
Re: Question about creating include files for HJWASM64
« Reply #10 on: July 13, 2016, 05:42:49 AM »
Quote
So, I think it's better define types exactly
Yes, that is why WinInc is the best solution.
« Last Edit: July 13, 2016, 09:10:30 AM by habran »
Cod-Father

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 10583
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Question about creating include files for HJWASM64
« Reply #11 on: July 13, 2016, 06:38:29 AM »
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.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

habran

  • Member
  • *****
  • Posts: 1228
    • uasm
Re: Question about creating include files for HJWASM64
« Reply #12 on: July 13, 2016, 08:19:49 AM »
Microsoft "mystery bag" style of header files:
Code: [Select]
WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
opposite to perfectly clear what we are doing:
Code: [Select]
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

  • Member
  • *****
  • Posts: 1378
Re: Question about creating include files for HJWASM64
« Reply #13 on: July 13, 2016, 09:06:31 AM »
How 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

  • Member
  • *****
  • Posts: 1228
    • uasm
Re: Question about creating include files for HJWASM64
« Reply #14 on: July 13, 2016, 09:09:30 AM »
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