AutoHotkey Community

It is currently May 27th, 2012, 11:43 am

All times are UTC [ DST ]




Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 41 posts ]  Go to page Previous  1, 2, 3
Author Message
 Post subject:
PostPosted: June 1st, 2010, 6:49 pm 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
I'd like to see in MSDN documentation. BTW, it seems rather unlikely.
Code:
MsgBox % DllCall("kernel32\CreateFile", "Str", "X:\test.test.dat", "UInt", 0x80000000, "UInt", 0, "Ptr", 0, "UInt", 3, "UInt", 0, "Ptr", 0, "Ptr") ; -1
MsgBox % DllCall("ole32\OleInitialize", "Ptr", 0, "Ptr") ; 1 in my system


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 24th, 2010, 1:43 pm 
Offline
User avatar

Joined: May 5th, 2007, 7:24 pm
Posts: 1240
Location: Seville, Spain
New release available.

_________________
fincs
Highly recommended: AutoHotkey_L (see why) (all my code snippets require it)
Formal request to polyethene - I support the unity of the AutoHotkey community
Get SciTE4AutoHotkey v3.0.00 (Release Candidate)
[My project list]


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 29th, 2010, 12:17 pm 
Offline

Joined: October 20th, 2007, 10:40 am
Posts: 15
Location: china,hubei
Hi, fincs
Thanks for the new release

Your release merged sean's com lib
in your example script, I only found ComObjCreate()
Did it have other new functions?

Better to write a documentation

Thanks Again!

_________________
英文不好,冏


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 11th, 2010, 12:57 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
fincs wrote:
After some research and crazy hours of coding and debugging DllCall() and RegisterCallback() are working now.
The catch? Exceptions don't seem to work properly. That's all.
I've begun merging and reviewing the 64-bit and COM changes. Since I probably won't be committing any code for a while yet, I thought I'd share the solution to this problem (additions in blue):
Code:
; x64call.asm

PerformDynaCall proc frame
   option prologue:none, epilogue:none

   ; Arguments:
   ; rcx: size of arguments to be passed via stack
   ; rdx: pointer to arguments to be passed via stack
   ; r8:  pointer to arguments to be passed by registers
   ; r9:  target function pointer

   ; Save some registers
   push rbp
.pushreg rbp
   push rsi
.pushreg rsi
   push rdi
.pushreg rdi

   ; Save the stack pointer
   mov rbp, rsp
.setframe rbp, 0
.endprolog
   ...

Basically, these additions cause MASM to generate a function table entry and unwind information, which is required for exception handling. The .directives describe how the function's stack frame is built and therefore how it unwinds. If you're interested, Kevin Frei's blog explains it in further detail.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 11th, 2010, 5:23 pm 
Offline
User avatar

Joined: May 5th, 2007, 7:24 pm
Posts: 1240
Location: Seville, Spain
Thanks for figuring out the exception problem. I believe similar fixes could be applied to the RegisterCallback() stub.

_________________
fincs
Highly recommended: AutoHotkey_L (see why) (all my code snippets require it)
Formal request to polyethene - I support the unity of the AutoHotkey community
Get SciTE4AutoHotkey v3.0.00 (Release Candidate)
[My project list]


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 12th, 2010, 4:20 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
That hadn't occurred to me until this morning. I'll be sure to look into it before releasing the next update.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 18th, 2010, 7:12 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
fincs wrote:
The x64 calling convention states that the higher bits in less-than-64-bits parameters may be garbage...
Sean wrote:
I'd like to see in MSDN documentation. BTW, it seems rather unlikely.
If I'm interpreting the AMD64 documentation correctly, operations such as mov ecx, n or mov eax, n which may be used to prepare the parameters or return value actually zero-extend 32-bit values into the appropriate 64-bit register. It appears to apply to any operation which places a 32-bit value into a 64-bit register, so it is very likely that most functions which return an int will work correctly if we use "int64" return type.
Quote:
3.4.5 High 32 Bits

In 64-bit mode, the following rules apply to extension of results into the high 32 bits when results smaller than 64 bits are written:
  • Zero-Extension of 32-Bit Results: 32-bit results are zero-extended into the high 32 bits of 64-bit GPR destination registers.
  • No Extension of 8-Bit and 16-Bit Results: 8-bit and 16-bit results leave the high 56 or 48 bits, respectively, of 64-bit GPR destination registers unchanged.
Source: AMD64 Architecture Programmer’s Manual Volume 1

There can still be "garbage" if the result is derived from a 64-bit operation. For example, return (x_int64 - y_int64); can be compiled as something like sub rax,rbx and the compiler is free to leave the result in rax/eax as the calling convention states the upper 32 bits may be garbage. The caller will then typically zero-extend eax explicitly if it needs a 64-bit value. On the other hand, it can be compiled as sub rbx,r11; mov eax,ebx, which is okay according to the above.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 18th, 2010, 7:47 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
I've been in U.S.A. a while and it never occurred to me to reply in this forum during. Anyway, I found this post in the blog shortly after my last post in this thread, which I always take more seriously than even the official MSDN documentation:
http://blogs.msdn.com/b/oldnewthing/arc ... 58579.aspx

So, it became obvious to me that there is no zero-extension and I concluded what I observed was an artifact of the code in x64call.asm, mov rax, r9, as AHK64 is still consuming only/mostly the 32-bit range of address.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 18th, 2010, 2:28 pm 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
Currently the "Float" and "Double" DllCall return types don't work, as they use the xmm0 register and we only (implicitly) retrieve rax. I spent hours trying to figure out how to retrieve the value of xmm0 using C++ intrinsics or let the assembly function determine which to return, and finally stumbled upon this article: C ABI Hacks. It presents some excellent ideas, one of which I was able to adapt to fix floating-point return values:
Code:
; in x64call.asm
read_xmm0_float proc
   option prologue:none, epilogue:none
   ret
read_xmm0_float endp

// in script2.cpp
extern "C" float read_xmm0_float();
...
      case DLL_ARG_FLOAT:
         aResultToken.symbol = SYM_FLOAT;
         aResultToken.value_double = Exp32or64(return_value.Float,
read_xmm0_float());
         
break;
It relies on there being no use of the xmm registers (presumably no floating-point operations) between calling the function and retrieving the register. Similar code is needed for "Double" return values. The article used C functions (no assembly required :lol:), but that meant putting the functions in a separate compilation unit and turning off link-time optimization.

I suppose the technique is comparable to this one I've used many times in AutoHotkey32:
Code:
str := DllCall("MulDiv", "int", ptr, "int", 1, "int", 1, "str")


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 18th, 2010, 4:49 pm 
Offline
User avatar

Joined: May 5th, 2007, 7:24 pm
Posts: 1240
Location: Seville, Spain
Thanks for figuring out how to retrieve float & double return values. I was also thinking about it.

_________________
fincs
Highly recommended: AutoHotkey_L (see why) (all my code snippets require it)
Formal request to polyethene - I support the unity of the AutoHotkey community
Get SciTE4AutoHotkey v3.0.00 (Release Candidate)
[My project list]


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 24th, 2010, 4:16 pm 
Offline
User avatar

Joined: May 5th, 2007, 7:24 pm
Posts: 1240
Location: Seville, Spain
New release available.
Changelog:
Added Lexikos' DllCall() changes. Merged latest changes from AutoHotkey_L repository. 64-bit binaries are now compressed with MPRESS. Added A_Is64bitOS which returns 1 if the script is running under 64-bit Windows, regardless of the AutoHotkey version.

_________________
fincs
Highly recommended: AutoHotkey_L (see why) (all my code snippets require it)
Formal request to polyethene - I support the unity of the AutoHotkey community
Get SciTE4AutoHotkey v3.0.00 (Release Candidate)
[My project list]


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 41 posts ]  Go to page Previous  1, 2, 3

All times are UTC [ DST ]


Who is online

Users browsing this forum: nothing and 3 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group