Recent

Author Topic: Problem with DLL and Win64  (Read 3418 times)

SonnyBoyXXl

  • New member
  • *
  • Posts: 44
Problem with DLL and Win64
« 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






ASBzone

  • Full Member
  • ***
  • Posts: 226
  • Automation leads to relaxation...
    • BrainWaveCC Utilities
Re: Problem with DLL and Win64
« Reply #1 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?
-ASB: https://www.BrainWaveCC.com

Lazarus v2.0.3 r61485 / FPC v3.2.0-beta-r42306 (via FpcUpDeluxe) -- Windows 64-bit install w/32-bit cross-compile
Primary System: Windows 10 Pro x64, Version 1903 (Build 18362.116)
Other Systems: Windows 10 Pro x64, Version 1809 or greater

SonnyBoyXXl

  • New member
  • *
  • Posts: 44
Re: Problem with DLL and Win64
« Reply #2 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 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.

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 7232
Re: Problem with DLL and Win64
« Reply #3 on: August 02, 2018, 12:38:17 pm »
Please file a bug, and quote that URL. Thank you.