Reputation: 561
I wrote this code in c++:
extern "C" __declspec(dllexport) int __stdcall sumx(int a, int b)
{
int result;
result = a + b;
return result;
}
I also tried:
int __stdcall sumx(int a, int b)
{
int result;
result = a + b;
return result;
}
and build win32 dll. then copy it in PB directory.
I define it external function.
And I call it:
when I run it:
Why do error occurs? tnx
Upvotes: 3
Views: 284
Reputation: 11465
After some tests here I think that your problem may result from a name decoration of your exported function. I.E: instead of being named sumx
in the dll, it is named _sumx@8
by the compiler.
You can check that by invoking dumpbin /exports keyadll.dll
. With my test dll, it shows:
C:\dev\powerbuilder\dlltest>dumpbin.exe /exports keyadll.dll
Microsoft (R) COFF/PE Dumper Version 8.00.50727.762
Copyright (C) Microsoft Corporation. All rights reserved.
Dump of file keyadll.dll
File Type: DLL
Section contains the following exports for keyadll.dll
00000000 characteristics
5627876B time date stamp Wed Oct 21 14:39:07 2015
0.00 version
1 ordinal base
1 number of functions
1 number of names
ordinal hint RVA name
1 0 0000100A _sumx@8 = @ILT+5(_sumx@8)
^====================== HERE is the point!
Summary
1000 .data
1000 .idata
2000 .rdata
1000 .reloc
1000 .rsrc
2000 .text
BTW, the @8
in the name stands for the 8 bytes (2 x sizeof(int)
) of parameters that are given to the function.
You have 2 options to fix that:
use the exact _sumx@8
name in the declaration of the external function in PB (you can use an alias for not changing your PB code):
function int sumx (int a, int b) library "keyadll.dll" alias for '_sumx@8'
I don't consider that solution being very elegant, though.
you can force VC to name the exported as YOU want (and not the reverse!) by using a module definition file (a .def).
simply put the names of the functions to export. It will contain
LIBRARY "keyadll.dll"
EXPORTS
sumx
Rebuild your dll and it should be OK for PB.
Upvotes: 5