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


  • Jr. Member
  • **
  • Posts: 56
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:
# [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


  • Hero Member
  • *****
  • Posts: 678
  • Automation leads to relaxation...
    • Free Console Utilities for Windows (and a few for Linux) from BrainWaveCC
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?

Lazarus v2.2.7-ada7a90186 / FPC v3.2.3-706-gaadb53e72c
(Windows 64-bit install w/Win32 and Linux/Arm cross-compiles via FpcUpDeluxe on both instances)

My Systems: Windows 10/11 Pro x64 (Current)


  • Jr. Member
  • **
  • Posts: 56
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 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}

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.


  • Administrator
  • Hero Member
  • *
  • Posts: 10716
  • FPC developer.
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.


TinyPortal © 2005-2018