Passing 64-bit int to DLL problem

Started by m35, July 02, 2007, 12:59:14 PM

Previous topic - Next topic

m35

I'm having trouble with passing 64-bit integers to DLL functions. The DLL is compiled on Windows XP using MinGW, and used with newLISP v9.1.1.



Here is a test program that shows the problem:



test64.c
#include <stdio.h>

__declspec (dllexport) int Test64(__int64 i)
{
unsigned int * pi;
pi = (unsigned int*)&i;
printf("0x %08X %08X", pi[1], pi[0]);
return 0;
}


test64.def
LIBRARY     TEST64.DLL

EXPORTS
Test64 @1 Test64


make.bat
C:MinGWbinmingw32-gcc test64.c -c -Wall
C:MinGWbindllwrap.exe test64.o --enable-stdcall-fixup -def test64.def -o test64.dll


test64.lsp
(import "test64.dll" "Test64")

(setq test-values
   '(0x0000000087654321
     0x000000A987654321
     0x0000CBA987654321))

(dolist (val test-values)

   (println (dump val))
   (println (format "0x %08X %08X"
      (get-int (+ 4 (address val)))
      (get-int (address val))
   ))
   (Test64 val)
   (println)(println)

)
(exit)


Output:
(218736 898 212400 -2023406815 0)
0x 00000000 87654321
0x 000356D0 87654321

(218736 898 212400 -2023406815 169)
0x 000000A9 87654321
0x 000356F0 87654321

(218736 898 212400 -2023406815 52137)
0x 0000CBA9 87654321
0x 000356D0 87654321


32-bit integers pass without a problem, but I can't seem to get the most significant integer of the 64-bit number.

Lutz

#1
Only 32-bit values are handled. You have to pass the 64-bit value as two 32-bit entitities in the right sequence. On little-endian CPUs in your example:


(Test64 low32 high32)

Lutz



ps: see also this thread with my longer explanations on Sun Jun 17, 2007:

http://www.alh.net/newlisp/phpbb/viewtopic.php?p=9412&highlight=lp64#9412">http://www.alh.net/newlisp/phpbb/viewto ... =lp64#9412">http://www.alh.net/newlisp/phpbb/viewtopic.php?p=9412&highlight=lp64#9412



ps2: you existing Test64 will take the low32 and high32 values from the stack (which is 32-bit wide), so no rewriting of Test64 is necessary.

m35

#2
Ah I see. Thank you Lutz.