Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem calling a c++ dll

Status
Not open for further replies.

rdpoling

Programmer
Aug 4, 2004
2
US
I have the task of writing a communications library for an RS232 serial comm port magstripe reader. I am writing the library in visual C++ with MFC. The functions in this library will be called from a legacy program written in PowerBuilder 6.5. So far, PowerBuilder successfully calls the function within the dll and it works correctly, but when control returns from the dll to the PowerBuilder function, I am getting this error from PowerBuilder:

**************************************
Error Number 42
at line number 1
of Event open
in Object w_test_window
in Window w_test_window

Specified argument type differs from required argument type at runtime in DLL function isbadgereaderpresent.
(invalid stack pointer on return from function call)
**************************************

Here is the C++ function declaration in the dll:
extern int EXPORT IsBadgeReaderPresent(DWORD dwComPort)

In PowerBuilder, you have to declare a prototype for the external function. Here it is:
FUNCTION int IsBadgeReaderPresent(long lComPort) library "C:\projects\nfs_comm\nfs_comm\debug\nfs_comm.dll"

And finally, here is how the function is actually called from PowerBuilder:
IsBadgeReaderPresent(1)

The PowerBuilder code is version 6.5; the C++ code is being compiled with Visual Studio .NET 2003. Does anyone have any idea about why I am getting an error???
 
FUNCTION int IsBadgeReaderPresent(long lComPort) library "C:\projects\nfs_comm\nfs_comm\debug\nfs_comm.dll"

the above declaration should be as :
FUNCTION int IsBadgeReaderPresent(long lComPort) nfs_comm.dll

provided u have registered "nfs_comm.dll" dll into the registry using the regsrv command

once its done.. try it out... and moreover since its return type is an integer, try fetching for the return value

Anjali
 
FUNCTION int IsBadgeReaderPresent(long lComPort) library "C:\projects\nfs_comm\nfs_comm\debug\nfs_comm.dll"

the above declaration should be as :
i missed out the keyword library
FUNCTION int IsBadgeReaderPresent(long lComPort) library nfs_comm.dll

 
Thanks for the responses, but your solution does not fix the problem (and actually my dll declaration is correct and works that way it is). The solution I found to this problem is to declare the C++ function with the __stdcall flag. This forces the C++ function to clean up the stack before control gets returned to the calling PowerBuilder code.

Thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top