-
October 14th, 2011, 03:08 PM
#1
I cannot pass data into a 64 bit DLL from a 64 bit win32 app
Hi
I am attempting to create a 64 bit win32 test application that loads a 64 bit MFC test DLL. I created a test function within the DLL that takes in a pointer to an integer. This function is an exported DLL function. I load the DLL in the win32 executable. I get access to the exported function. I call the DLL test function, sending it a pointer to an integer where the value is = to 100. I then step into the DLL test function using the debugger. Within the DLL test function the address of the integer pointer is undefined or NULL. So the pointer was not passed properly. Now, if I rebuild the application and the DLL using the 32 bit compilers then all problems go away. The integer pointer is passed without any issues into the DLL test function and I can see the value (100).
Any ideas would be greatly appreciated.
thanks
Here is my code for the win32 application:
typedef void (CALLBACK* D_TestDllTest)(int* Val);
.
.
.
int APIENTRY _tWinMain(HINSTANCE hInstance,...)
{
.
.
.
// load "TestDLL.dll"
CString Path = "c:\\TestDll.dll";
HINSTANCE TestDllHInst = AfxLoadLibrary((LPCTSTR)Path);
// get pointer to exported DLL function
D_TestDllTest TestDllTest = (D_TestDllTest)GetProcAddress(TestDllHInst, "TestDllTest");
// call the DLL function
int Val = 100;
TestDllTest(&Val);
.
.
.
}
Here is the DLL code:
void CTestDllApp::TestDllTest(int* Val)
{
*Val = 2;
return;
}
-
October 14th, 2011, 03:23 PM
#2
Re: I cannot pass data into a 64 bit DLL from a 64 bit win32 app
Are you building a 32bit exe? If so, I don't believe you can call functions in a 64bit DLL from a 32bit exe, and vice versa. Both the exe and library must be of the same "type" (32 bit or 64 bit).
Viggy
-
October 14th, 2011, 03:34 PM
#3
Re: I cannot pass data into a 64 bit DLL from a 64 bit win32 app
I am building a "Win32" app (which from what I have read can be built as a 32 bit or 64 bit application). When I build my application I am using the "x64" compiler. When I run my application I can confirm that it is a 64 bit app by finding it within the process list of the task manager. 32 bit apps have a "*32" displayed to the left of their name in the process list. My test application does not have the "*32" text, so at least windows considers it to be a 64 bit application. From what I can gather there is no such thing as a "win64" application; instead, there are "win32" applications built using the 64 bit "X64"compiler.
-
October 14th, 2011, 06:50 PM
#4
Re: I cannot pass data into a 64 bit DLL from a 64 bit win32 app
Originally Posted by jmiller9126
I call the DLL test function, sending it a pointer to an integer where the value is = to 100. I then step into the DLL test function using the debugger. Within the DLL test function the address of the integer pointer is undefined or NULL. So the pointer was not passed properly.
Forget about the debugger -- did the program crash when you attempted to set the pointer?
You're relying strictly on what the debugger is showing. Maybe it's the debugger that is buggy, and there is nothing wrong.
Regards,
Paul McKenzie
-
October 14th, 2011, 07:04 PM
#5
Re: I cannot pass data into a 64 bit DLL from a 64 bit win32 app
Yes, the application crashes in release mode. I tried release mode first and then debug mode.
Also, I did try passing variables by reference with no better luck.
-
October 14th, 2011, 09:01 PM
#6
Re: I cannot pass data into a 64 bit DLL from a 64 bit win32 app
Originally Posted by jmiller9126
Yes, the application crashes in release mode. I tried release mode first and then debug mode.
My guess is that you're not using the correct calling convention. In other words, your function signature with regards to __stdcall, __cdecl, are inconsistent.
Also, I did try passing variables by reference with no better luck.
Never pass C++ references across module boundaries. A reference is not a pointer.
The implementation of a reference is compiler-dependent, and probably compiler-version dependent. You cannot guarantee that the internals of a reference are the same between application and DLL. Use references within your program, but never pass them to other programs.
As a matter of fact, you shouldn't even be passing a pointer to "int", as again, what an "int" is is compiler-dependent. The only types guaranteed to be consistent in size and type, are the Windows types, i.e. LONG, DWORD, BOOL, LPTSTR, etc., and pointers to these types.
So first, make sure your calling conventions are consistent.
Second, pass a pointer to a DWORD instead of pointer to int.
Third, do not even consider passing references.
Regards,
Paul McKenzie
-
October 31st, 2011, 08:19 AM
#7
Re: I cannot pass data into a 64 bit DLL from a 64 bit win32 app
-
November 13th, 2011, 09:33 AM
#8
Re: I cannot pass data into a 64 bit DLL from a 64 bit win32 app
@jmiller9126
Hi,
Did you ever get this solved?
I have a very similar issue.
Thanks.
:Ron
-
November 13th, 2011, 11:02 AM
#9
Re: I cannot pass data into a 64 bit DLL from a 64 bit win32 app
First of all, there's an obvious prototype mismatch:
Code:
typedef void (CALLBACK* D_TestDllTest)(int* Val); // global or static __stdcall
. . .
Here is the DLL code:
void CTestDllApp::TestDllTest(int* Val) // thiscall
{
*Val = 2;
return;
}
The more detailed analysis is possible only with full sample code.
Best regards,
Igor
-
November 13th, 2011, 11:05 AM
#10
Re: I cannot pass data into a 64 bit DLL from a 64 bit win32 app
Did you ever get this solved?
I have a very similar issue.
How can you be sure about the issue similarity, as there was no complete code shown.
Best regards,
Igor
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|