1. ts maniam
  2. PowerBuilder
  3. Tuesday, 21 April 2020 04:04 AM UTC

1. We have a c++ dll compiled in CodeBlocks which has a function declared as below

__declspec(dllexport) char * __cdecl vc_encrypt(char* vol, char* id);

(MingGW compiler suffixes @8 to the function name when __stdcall is used in c++)

2. The function has been called with the code in a user event as below

ls_setcode = vc_encrypt(ls_mvol, ls_code)

The error message we get is 

error calling external function %s

3. The declaration in Global External Function in PB is as below

Function String vc_encrypt(char vol, char id) library "exdll.dll" alias for "vc_encrypt;Ansi" 

(when string is used as datatype in input, the error message "specified argument type differs from required argument type at run time in DLL function vc_encrypt - invalid stack pointer on return from function call at line ....)

 

I do not have experience in c++ and tried different combinations. The C++ code not written by me. Imported from visual studio solution of an earlier version. Searched in google and appeon community - some improvements made but could not find the solution for this specific problem.   We use Appeon PB 2017 R3. Can you please help me out 

TS Maniam, tsmaniamca@gmail.com 

Attachments (2)
John Fauss Accepted Answer Pending Moderation
  1. Tuesday, 21 April 2020 06:00 AM UTC
  2. PowerBuilder
  3. # 1

Greetings, TS -

The DLL function has to be exported with __stdcall, as this is the convention used by PB.

Since the function name gets @8 appended to it when __stdcall is used, you have to use ALIAS FOR in the External Function Declaration because the "@" is considered a special character, like ALIAS FOR "vc_encrypt@8;ansi".

The DLL function declaration shows two string arguments, but the External Function Declaration shown uses the datatype "char", which is not correct. In C/C++, "char*" translates to "string", so these arguments have to be declared in PB as strings.

If either of the argument values are to be returned to PB, you need to preface each of them with "REF" so that PB knows they are to be passed by reference, even if a pointer is being passed.

PB has to "own" any strings, buffers, that it uses, so initialize any strings arguments to be passed by reference. This is typically done with the Space(n) PowerScript function. I don't know if this will be needed in your case, since I'm not familiar with this DLL function. Initialization is not needed for the string return value.

HTH, Regards - John

Comment
  1. ts maniam
  2. Tuesday, 21 April 2020 08:57 AM UTC
Greetings John,

Thanks a lot, With both the changes carried out and also a type error, the problem got solved.

Thank you very much.

with regards, - TS Maniam
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.