Lazarus

Programming => Graphics and Multimedia => DirectX => Topic started by: SonnyBoyXXl on August 01, 2018, 08:58:45 pm

Title: Problem with DLL and Win64
Post by: SonnyBoyXXl on August 01, 2018, 08:58:45 pm
Hi folks,
I have a problem with a Win64 Application - the same code works well in Win32, so I think it's an compiler issue. I work with CT 6.4
Calling the function GetSize from ID2D1Bitmap makes the problem
the function is declared as

Code: Pascal  [Select][+][-]
  1. ID2D1Bitmap = interface(ID2D1Image)
  2.         ['{a2296057-ea42-4099-983b-539fb6505426}']
  3.         function GetSize: TD2D1_SIZE_F; stdcall;  
       

Calling the function the compiler makes the code:
Quote
# [56] lBitmapSize := lBitmap.GetSize();
   movq   -48(%rbp),%rcx
   movq   -48(%rbp),%rax
   movq   (%rax),%rax
   call   *32(%rax)
   movq   %rax,-128(%rbp)

the function crashes on the line as you see in the attached picture.

The image itself is valid, could be drawn etc. but calling the get function fails. Also other functions like GetPixelSize fails.

Could be the problem that the rcx register is assigned, and Windows request the rdx register ?
How to solve this?

best regards





Title: Re: Problem with DLL and Win64
Post by: ASBzone on August 01, 2018, 09:43:35 pm
Are you calling the same DLL in the 32-bit application as in the 64-bit one?
Title: Re: Problem with DLL and Win64
Post by: SonnyBoyXXl on August 01, 2018, 11:45:41 pm
Hi folks,
I have now the answer. Finding this article https://forum.dlang.org/post/krxvtovytmjhnocyupah@forum.dlang.org (https://forum.dlang.org/post/krxvtovytmjhnocyupah@forum.dlang.org) and
working a small example in VisualStudio it seems that M$ is not following the calling convention  for some COM routines >:D

So the working assembler routine is this one. The RDX register needs the adress of the return value too.
Code: Pascal  [Select][+][-]
  1. {$asmmode intel}
  2.     asm
  3.         mov     rax ,  QWORD PTR [lBitmap]
  4.         mov     rax ,  QWORD PTR [rax]
  5.         lea     rdx ,  [lBitmapSize]
  6.         mov     rcx ,  QWORD PTR [lBitmap]
  7.         call    QWORD PTR [rax+32] // GetSize is first function
  8.         mov     rax , qword ptr [rax]
  9.         mov     qword ptr [lBitmapSize],rax
  10.     end;
  11.     {$ENDIF}
  12.  

I'm not sure if this is a "always working" way. Some gurus should look at this topic. I will place a bug issue in the bug tracker.

Best regards.
Title: Re: Problem with DLL and Win64
Post by: marcov on August 02, 2018, 12:38:17 pm
Please file a bug, and quote that URL. Thank you.
TinyPortal © 2005-2018