Discussion:
__int64 return value problem from DLLs
(too old to reply)
k***@gmail.com
2006-03-13 20:28:46 UTC
Permalink
Hi folks,

I have a DLL which contains functions that return __int64 values, but I

can't get Visual C to read the return value correctly. I am using the
2003 version.


Here is the test code:

// __int64 return value example
//

#include "windows.h"
#include "quad_dll.h"

int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{


char szBuffer[500];
__int64 uu;

uu = TEST(100);

wsprintf(szBuffer, "Number returned from TEST(): %u", (int)uu);
MessageBox(NULL, szBuffer, "quadtest", MB_ICONINFORMATION);

// Exit the program
return(0);
}

In all cases, uu is the incorrect value. Is there a special compiler
switch I need to
use, or is this not supported? Could the problem lie in the .LIB
header?

Complete sample project:
http://www.kgpsoftware.com/downloads/quadprob.zip

Thanks for any assistance.
David Lowndes
2006-03-13 21:58:11 UTC
Permalink
Post by k***@gmail.com
I have a DLL which contains functions that return __int64 values
You do?

What's the definition of the return type of your VB DLL - what's Quad?
Post by k***@gmail.com
__int64 uu;
uu = TEST(100);
wsprintf(szBuffer, "Number returned from TEST(): %u", (int)uu);
You should use %I64i (or %I64u) and drop the int cast to convert a
64-bit value.
Post by k***@gmail.com
In all cases, uu is the incorrect value.
What is it, and what do you expect it to be?
Post by k***@gmail.com
Is there a special compiler switch I need to use
No.

Dave
k***@gmail.com
2006-03-14 11:22:18 UTC
Permalink
Hi Dave,
Post by David Lowndes
What's the definition of the return type of your VB DLL - what's Quad?
The DLL is compiled in PowerBASIC and it returns a 64-bit signed data
type, which according to MS docs, is the equivalent of the _int64 type.
Post by David Lowndes
You should use %I64i (or %I64u) and drop the int cast to convert a 64-bit value.
Ok, thanks. I have done that (using %I64i) and I get 7730941132 instead
of 100.
Post by David Lowndes
What is it, and what do you expect it to be?
In the example, it should display "100". The DLL converts the number
from an int to an __int64 and returns it.

Here is the DLL code, it's pretty simple:

#Compile Dll
#Dim All
Function TEST(ByVal i As Long) Export As Quad
Function = i
End Function
David Lowndes
2006-03-14 15:02:24 UTC
Permalink
Post by k***@gmail.com
#Compile Dll
#Dim All
Function TEST(ByVal i As Long) Export As Quad
Function = i
End Function
I've no experience with PowerBASIC, so I don't know anything about
interfacing to it.

From what you've shown, I can't spot anything else wrong.

Can anyone else see anything obvious?

Dave
Tim Roberts
2006-03-15 07:56:55 UTC
Permalink
Post by k***@gmail.com
Post by David Lowndes
What's the definition of the return type of your VB DLL - what's Quad?
The DLL is compiled in PowerBASIC and it returns a 64-bit signed data
type, which according to MS docs, is the equivalent of the _int64 type.
Well, since Microsoft doesn't make PowerBASIC, their docs don't actually
have any comment about the PowerBASIC QUAD datatype...

A few minutes with a debugger identified the problem. The PowerBASIC docs
say that the QUAD type is supposed to be equivalent to the LARGE_INTEGER
type in VC++, but they are lying to you. An __int64 value is returned in
edx:eax, and that's exactly what the VC++ code expects, but your DLL
function is returning its value in the top of the floating point stack. I'd
call that counterintuitive.

So, oddly enough, if you simply edit your quad_dll.h file and change the
return type of TEST from "_int64" to "double", your program will work just
fine. I just did it.
--
- Tim Roberts, ***@probo.com
Providenza & Boekelheide, Inc.
k***@gmail.com
2006-03-15 13:21:54 UTC
Permalink
Thanks Dave and Tim, for the replies. I will mention this on the
PowerBASIC forum, and try using a double instead.

In case anyone is interested. Here is the associated thread on that
forum:

http://www.powerbasic.com/support/forums/Forum6/HTML/005431.html

Loading...