1. mukul pandey
  2. PowerBuilder
  3. Friday, 26 June 2020 12:26 PM UTC

Hi Everyone,

 

I am using Powerbuilder classic 2017R2 build 1769(32 bit) and windows 10. I am not able to use c++ dll in my application. I got runtime error as "R021 - Bad runtime function reference".

My C++ dll code is:-

int __declspec(dllexport) __stdcall testMethodCall(char* retVal)
    {
        strcpy_s(retVal, sizeof("Inside Test Library"), "Inside Test Library");
        return 0;
    }
 
Declaration of global external function as:-
 
        Function int testMethodCall(Ref char cretval[100]) library "TestDLLforCSW.dll" alias for "testMethodCall;Ansi"
 
calling:-
 
      char cretval[100]=''
      int li_ret
      li_ret=testMethodCall(REF cretval)
 
Please suggest.
 
Thanks,
Mukul
Attachments (1)
Roland Smith Accepted Answer Pending Moderation
  1. Friday, 26 June 2020 12:41 PM UTC
  2. PowerBuilder
  3. # 1

A couple issues:

It should be declared as a string on the PB side and allocated like this:

ls_retval = Space(100)

An int in C is a long in PowerBuilder.

 

When I write a C function I always use a .def file to list exported functions. Here is an example of one of mine:

void WINAPI EscapeToAscii(CHAR *lpEscape)

{

}

PowerBuilder declaration:

Subroutine EscapeToAscii ( Ref string lpEscape ) Library "twserver.dll" Alias For "EscapeToAscii;Ansi"

 

The function converts hex escaped strings back to characters so the output string is always shorter than the input.

 

Comment
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.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.