2

I'm a Developer-Student and I'm writing my Bachelor-Thesis right now. Since a few days I despair at a problem about calling a DLL from Powerbuilder Classic 12.5.

Yes, there are Discussions about it, but I really tried a lot, and nothing works... and my collegues weren't able to help me, too.

I have a DLL, programmed in c++, which I want to call. The Head Function is

__declspec(dllexport) bool __stdcall registerPbControl(unsigned long hctl);

In PowerBuilder, I declared a Global External Function:

FUNCTION boolean  registerControl (ulong hctl ) LIBRARY "C:\Users\...\GateWayFinal.dll"   ALIAS FOR "registerPbControl;ansi"

And the Command of the Button in Powerbuilder:

boolean lb
      lb = registerControl (handle (mle_1))

When I Press the Button, I get this error:

PowerBuilder application execution error: Application Terminated. Error: Bad runtime Function reference at line ...

What did I do wrong?

TaW
  • 53,122
  • 8
  • 69
  • 111
DuMont
  • 55
  • 1
  • 7
  • Never worked with PowerBuilder; however could it be a [calling convention](https://msdn.microsoft.com/en-us/library/k2b2ssfy.aspx) mismatch? – CristiFati Jul 07 '16 at 12:00

3 Answers3

3

I'm not a C++ expert but I always declare functions as WINAPI. I think that is different than stdcall but I don't remember at the moment.

The ;ansi part is only needed when passing a string and the function expects it ansi instead of unicode.

Don't use the full file path in the declaration.

Roland Smith
  • 957
  • 4
  • 7
1

It is probably the mangled name that you miss as the alias. Also put the dll in the folder where the powerbuilder project is and then just state ...LIBRARY "GateWayFinal.dll"...

Have you tried creating the c++ project as described here: http://www.rgagnon.com/pbdetails/pb-0123.html (especially the part with the Map and the mangled name)

Michael
  • 499
  • 4
  • 16
1

Sounds like it might be a name mangling issue. You can use Dependency Walker to view the actual name in the DLL. Also see this SO question for more information: How do I stop name-mangling of my DLL's exported function?

Community
  • 1
  • 1
Slapout
  • 3,759
  • 5
  • 40
  • 61