<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: how do i write a C++ dll which a parameter ref the  string for powerbuilder? in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/how-do-i-write-a-c-dll-which-a-parameter-ref-the-string-for-powerbuilder/qaa-p/11181943#M4128213</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Just to be clear on a few things.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;C/C++ provides for two different sizes of strings, ANSI and Unicode;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LPTSTR and LPCTSTR are defined in WINNT.H, and are not part of the MFC, they're just standard ways of declaring and easily reading type definitions. Winnt.h should be included in your VC installation.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;wchar_t *str - unicode declaration&lt;/P&gt;&lt;P&gt;char *str - ansi declaration&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PB9 uses ANSI, PB10 and up uses Unicode.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you need to use PB9, then the declaration you have will work ok (as you've seen).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you only need to use pb 12.5, then you don't need to use the ;ANSI at all, just redefine your function to use wchar_t as it's argument type.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try this for pb 12.5:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;int&amp;nbsp; __stdcall&amp;nbsp; testmyapi(wchar_t * tempstr, size_t maxlen)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; wchar_t *wstrinvnum = L&lt;SPAN style="font-size: 13.3333330154419px;"&gt;"1215265152";&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RtlStringCbCopy(tempstr, maxlen, wstrinvnum);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;On the PB side:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Function TestTheDLL(string InvNum, ulong MaxLen) library "testdll.dll"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;String ls_invnum&lt;/P&gt;&lt;P&gt;ls_invnum = space(22)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // string is 10 chars long (in the C++ code), 11 when you include null terminator, so double it for unicode storage&lt;/P&gt;&lt;P&gt;TestTheDLL(ls_invnum, 22)&lt;/P&gt;&lt;P&gt;messagebox("And the result is", ls_invnum)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you need to call the dll from both PB 9 and pb 12.5, then create 2 functions that act as wrappers to the main function that does the work. The PB9 version of the function will do the string conversion after calling the single , the 12.5 version will just return the result in the return string.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// function that actually does work&lt;/P&gt;&lt;P&gt;wchar_t *DoStuff()&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return L"&lt;SPAN style="font-size: 13.3333330154419px;"&gt;1215265152&lt;/SPAN&gt;";&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// wrapper for PB9&lt;/P&gt;&lt;P&gt;int __stdcall TestMyAPI9(char *tempstr, size_t maxlen)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; std::wstring_convert&amp;lt;std::codecvt &amp;lt;wchar_t, char, std::mbstate_t&amp;gt;&amp;gt; converter(new std::codecvt&amp;lt;wchar_t, char, std::mbstate_t&amp;gt;("CHS"));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; std::string narrowstr = converter.to_bytes(DoStuff());&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; size_t outputSize = narrowstr.length() + 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(outputSize &amp;gt; maxlen) outputSize = maxlen;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; const char * str = new char[outputSize];&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; str = narrowstr.c_str();&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; strcpy_s(tempstr, outputSize, str);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; //delete[] str;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// wrapper for pb12.5&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;int __stdcall TestMyAPI125(wchar_t * tempstr, size_t maxlen)&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;{&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RtlStringCbCopy(tempstr, maxlen, DoStuff());&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;}&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;Warning: None of this code is tested, but should be correct in concept.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 07 Jul 2015 14:46:01 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2015-07-07T14:46:01Z</dc:date>
    <item>
      <title>how do i write a C++ dll which a parameter ref the  string for powerbuilder?</title>
      <link>https://community.sap.com/t5/technology-q-a/how-do-i-write-a-c-dll-which-a-parameter-ref-the-string-for-powerbuilder/qaq-p/11181932</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hello sir/madma&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; may i ask question about C/C++ build a api for powerbuilder to consume,i'd like write dll which powerbuilder could call in function which is defined int myfun(string ls_param1,ref string&amp;nbsp; ls_param2) "mydll.dll;Ansil" ,i just cant figure out the ls_param2 in C++,if should write as&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;int myfun(char * theparm1,char** ls_param2) ?&lt;/P&gt;&lt;P&gt;do i have to use char ** in the second parameter?&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;&lt;P&gt;regards&lt;/P&gt;&lt;P&gt;Ken&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 05 Jul 2015 07:28:25 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/how-do-i-write-a-c-dll-which-a-parameter-ref-the-string-for-powerbuilder/qaq-p/11181932</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2015-07-05T07:28:25Z</dc:date>
    </item>
    <item>
      <title>Re: how do i write a C++ dll which a parameter ref the  string for powerbuilder?</title>
      <link>https://community.sap.com/t5/technology-q-a/how-do-i-write-a-c-dll-which-a-parameter-ref-the-string-for-powerbuilder/qaa-p/11181933#M4128203</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Ken,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The responses from Bruce and Roy in this post should help you out.&lt;/P&gt;&lt;P&gt;&lt;A href="http://codeverge.com/sybase.powerbuilder.objects/calling-c++-function-in-pb/"&gt;Http://codeverge.com/sybase.powerbuilder.objects/calling-c++-function-in-pb/&lt;/A&gt;891348&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hth,&lt;/P&gt;&lt;P&gt;Mark&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 05 Jul 2015 12:23:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/how-do-i-write-a-c-dll-which-a-parameter-ref-the-string-for-powerbuilder/qaa-p/11181933#M4128203</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2015-07-05T12:23:49Z</dc:date>
    </item>
    <item>
      <title>Re: how do i write a C++ dll which a parameter ref the  string for powerbuilder?</title>
      <link>https://community.sap.com/t5/technology-q-a/how-do-i-write-a-c-dll-which-a-parameter-ref-the-string-for-powerbuilder/qaa-p/11181934#M4128204</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hello mark, thanks,i have checked the link,but i still confused that char ** means string array or refrenece a string pararmeter in POWERBUILDER,what do you think?&lt;/P&gt;&lt;P&gt;it sounds like i should use char ** as parameter in C++ if i'd like to reference the string In Powerbuilder to cosume the C++ dll&lt;/P&gt;&lt;P&gt;regards&lt;/P&gt;&lt;P&gt;Ken&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 05 Jul 2015 12:41:16 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/how-do-i-write-a-c-dll-which-a-parameter-ref-the-string-for-powerbuilder/qaa-p/11181934#M4128204</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2015-07-05T12:41:16Z</dc:date>
    </item>
    <item>
      <title>Re: how do i write a C++ dll which a parameter ref the  string for powerbuilder?</title>
      <link>https://community.sap.com/t5/technology-q-a/how-do-i-write-a-c-dll-which-a-parameter-ref-the-string-for-powerbuilder/qaa-p/11181935#M4128205</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;short WINAPI myfunc(LPSTR lpParam1,LPSTR lpParam2)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LPSTR indicates a by ref string. I am pretty sure C doesn't distinguish between updateable and non-updateable strings. It is just a memory pointer to a char array.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 05 Jul 2015 13:48:23 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/how-do-i-write-a-c-dll-which-a-parameter-ref-the-string-for-powerbuilder/qaa-p/11181935#M4128205</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2015-07-05T13:48:23Z</dc:date>
    </item>
    <item>
      <title>Re: how do i write a C++ dll which a parameter ref the  string for powerbuilder?</title>
      <link>https://community.sap.com/t5/technology-q-a/how-do-i-write-a-c-dll-which-a-parameter-ref-the-string-for-powerbuilder/qaa-p/11181936#M4128206</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you write the dll only for PowerBuilder, then writing a PBNI extension might also be an option, &lt;BR /&gt;You would have predefined types pbstring with get and set functions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Jul 2015 06:39:52 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/how-do-i-write-a-c-dll-which-a-parameter-ref-the-string-for-powerbuilder/qaa-p/11181936#M4128206</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2015-07-06T06:39:52Z</dc:date>
    </item>
    <item>
      <title>Re: how do i write a C++ dll which a parameter ref the  string for powerbuilder?</title>
      <link>https://community.sap.com/t5/technology-q-a/how-do-i-write-a-c-dll-which-a-parameter-ref-the-string-for-powerbuilder/qaa-p/11181937#M4128207</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hello sir,i just not familar with C++,however i tried the LPSTR replace the char *,but VC seems not recognize the LPSTR,even i have include&amp;lt;windows.h&amp;gt;,i dont know how to resolve this issue&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Jul 2015 13:11:21 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/how-do-i-write-a-c-dll-which-a-parameter-ref-the-string-for-powerbuilder/qaa-p/11181937#M4128207</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2015-07-06T13:11:21Z</dc:date>
    </item>
    <item>
      <title>Re: how do i write a C++ dll which a parameter ref the  string for powerbuilder?</title>
      <link>https://community.sap.com/t5/technology-q-a/how-do-i-write-a-c-dll-which-a-parameter-ref-the-string-for-powerbuilder/qaa-p/11181938#M4128208</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;thanks you ,i will find more information about PBNI later,but i have tried to build a dll for powerbuilder, i&amp;nbsp; have failed,could you check what's wrong?i think&amp;nbsp; i have two challenge of building the dll for powerbuilder,firstly is wchar_t * convert to char *,secondly is how to return a int and char * in a same time,i build the dll for cosuming the rest web service,so firstly i done the following test&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i builded a dll in VC with the following code&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;int&amp;nbsp;&amp;nbsp; __stdcall&amp;nbsp; testmyapi(char * tempstr, char ** retstring)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; std::wstring wstrinvnum = L"1215265152";&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; std::wstring_convert&amp;lt;std::codecvt &amp;lt;wchar_t, char, std::mbstate_t&amp;gt;&amp;gt; converter(new std::codecvt&amp;lt;wchar_t, char, std::mbstate_t&amp;gt;("CHS"));&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; std::string narrowstr = converter.to_bytes(wstrinvnum);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; size_t outputSize = wstrinvnum.length() + 1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; const char * str = new char[outputSize];&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;//&amp;nbsp;&amp;nbsp;&amp;nbsp; char * tempstr = new char[outputSize];&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; str = narrowstr.c_str();&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; strcpy_s(tempstr, outputSize, str);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; *retstring = tempstr;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;then i declare this dll in Powerbuilder&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i declare it in global external function&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;function long testmyapi (string tempstr,ref string retstring) library "testdll.dll"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;then i test this function in a button click event&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;string ls_tempstr,ls_src&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;long recode&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;recode= testmyapi(ls_src, ls_tempstr)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;messagebox("",ls_tempstr)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;however the messagebox didnt display the 1215265152 ,it has displayed the odd string&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;,when i click this button second time,the string has change to another odd string .&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Jul 2015 14:49:09 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/how-do-i-write-a-c-dll-which-a-parameter-ref-the-string-for-powerbuilder/qaa-p/11181938#M4128208</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2015-07-06T14:49:09Z</dc:date>
    </item>
    <item>
      <title>Re: how do i write a C++ dll which a parameter ref the  string for powerbuilder?</title>
      <link>https://community.sap.com/t5/technology-q-a/how-do-i-write-a-c-dll-which-a-parameter-ref-the-string-for-powerbuilder/qaa-p/11181939#M4128209</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;PS :all my purpose for i'd like use jsoncpp library for powerbuilder&lt;/P&gt;&lt;P&gt;regards&lt;/P&gt;&lt;P&gt;Ken&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Jul 2015 15:07:30 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/how-do-i-write-a-c-dll-which-a-parameter-ref-the-string-for-powerbuilder/qaa-p/11181939#M4128209</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2015-07-06T15:07:30Z</dc:date>
    </item>
    <item>
      <title>Re: how do i write a C++ dll which a parameter ref the  string for powerbuilder?</title>
      <link>https://community.sap.com/t5/technology-q-a/how-do-i-write-a-c-dll-which-a-parameter-ref-the-string-for-powerbuilder/qaa-p/11181940#M4128210</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here's an example and description of a Windows DLL call that uses both a string, and a reference to a string:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PB declaration:&lt;/P&gt;&lt;P&gt;Function long GetEnvironmentVariable(string lpName, ref string lpBuffer, long nSize) library "kernel32.dll" alias for "GetEnvironmentVariableW"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;By using REF, it tells PB that the string can change. If it's not used, PB will use a copy of the string (or copy of any other value) as a throw away. This guarantees that the var you send will remain unchanged, even if it's a badly written DLL that may overwrite it by accident. Both are pointers to a string, one that can't change, one that is expected to be set by the DLL function.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Windows declaration (from MSDN):&lt;/P&gt;&lt;P&gt;DWORD WINAPI GetEnvironmentVariable( LPCTSTR lpName, LPTSTR&amp;nbsp; lpBuffer, DWORD nSize);&lt;/P&gt;&lt;P&gt;LPCTSTR means Long Pointer to Constant Wide String (unicode)&lt;/P&gt;&lt;P&gt;LPTSTR means Long Pointer to Wide String (unicode)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;alternate declaration:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;long WINAPI GetEnvironmentVariable( const char *lpName, char *lpBuffer, long nSize);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;Always make sure you have made the REF String var be big enough in PB to hold the string generated in the DLL. Use the space function to pre-allocate it.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;Hope this helps,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;Brad&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 06 Jul 2015 19:17:17 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/how-do-i-write-a-c-dll-which-a-parameter-ref-the-string-for-powerbuilder/qaa-p/11181940#M4128210</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2015-07-06T19:17:17Z</dc:date>
    </item>
    <item>
      <title>Re: how do i write a C++ dll which a parameter ref the  string for powerbuilder?</title>
      <link>https://community.sap.com/t5/technology-q-a/how-do-i-write-a-c-dll-which-a-parameter-ref-the-string-for-powerbuilder/qaa-p/11181941#M4128211</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;thanks for your tips,i have resolve the problem with that.however the LPCTSTR and LPTSTR is a variable in MFC,not the win32,it seems that will be more complicate to write a dll that relative to MFC,i ever searched some web page that it's a little bit different to call the MFC in dll,so im not sure how to use it.&lt;/P&gt;&lt;P&gt;now i change the C++ code,i have a problem with this dll in pb 12.5,however it works fine in POWERBUILDER version 9,i just got the odd string in pb 12.5 with which defined in global external function like&lt;/P&gt;&lt;P&gt;function long testmyapi (ref string retstring) library "testdll.dll"&lt;/P&gt;&lt;P&gt;,i tried to define in global external function like this&lt;/P&gt;&lt;P&gt;function long testmyapi (ref string retstring) library "testdll.dll;Ansi"&lt;/P&gt;&lt;P&gt;unfortunatery,i just got the program occured&amp;nbsp; the bad runtime error.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;int&amp;nbsp;&amp;nbsp; __stdcall&amp;nbsp; testmyapi(char * tempstr)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; std::wstring wstrinvnum = L"1215265152";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; std::wstring_convert&amp;lt;std::codecvt &amp;lt;wchar_t, char, std::mbstate_t&amp;gt;&amp;gt; converter(new std::codecvt&amp;lt;wchar_t, char, std::mbstate_t&amp;gt;("CHS"));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; std::string narrowstr = converter.to_bytes(wstrinvnum);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; size_t outputSize = narrowstr.length() + 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; const char * str = new char[outputSize];&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; str = narrowstr.c_str();&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; strcpy_s(tempstr, outputSize, str);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; //delete[] str;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i declare it in global external function&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;function long testmyapi (ref string retstring) library "testdll.dll"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;then i test this function in a button click event&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;string ls_tempstr&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;long recode&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;recode= testmyapi( ls_tempstr)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;messagebox("",ls_tempstr)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;does sombody know what's wrong?&lt;/P&gt;&lt;P&gt;regards&lt;/P&gt;&lt;P&gt;Ken&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Jul 2015 05:02:52 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/how-do-i-write-a-c-dll-which-a-parameter-ref-the-string-for-powerbuilder/qaa-p/11181941#M4128211</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2015-07-07T05:02:52Z</dc:date>
    </item>
    <item>
      <title>Re: how do i write a C++ dll which a parameter ref the  string for powerbuilder?</title>
      <link>https://community.sap.com/t5/technology-q-a/how-do-i-write-a-c-dll-which-a-parameter-ref-the-string-for-powerbuilder/qaa-p/11181942#M4128212</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;now im not confusing,i knew i should using the char *,it will reference the string from powerbuilder,not the char **,thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Jul 2015 05:04:33 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/how-do-i-write-a-c-dll-which-a-parameter-ref-the-string-for-powerbuilder/qaa-p/11181942#M4128212</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2015-07-07T05:04:33Z</dc:date>
    </item>
    <item>
      <title>Re: how do i write a C++ dll which a parameter ref the  string for powerbuilder?</title>
      <link>https://community.sap.com/t5/technology-q-a/how-do-i-write-a-c-dll-which-a-parameter-ref-the-string-for-powerbuilder/qaa-p/11181943#M4128213</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Just to be clear on a few things.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;C/C++ provides for two different sizes of strings, ANSI and Unicode;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;LPTSTR and LPCTSTR are defined in WINNT.H, and are not part of the MFC, they're just standard ways of declaring and easily reading type definitions. Winnt.h should be included in your VC installation.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;wchar_t *str - unicode declaration&lt;/P&gt;&lt;P&gt;char *str - ansi declaration&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PB9 uses ANSI, PB10 and up uses Unicode.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you need to use PB9, then the declaration you have will work ok (as you've seen).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you only need to use pb 12.5, then you don't need to use the ;ANSI at all, just redefine your function to use wchar_t as it's argument type.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try this for pb 12.5:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;int&amp;nbsp; __stdcall&amp;nbsp; testmyapi(wchar_t * tempstr, size_t maxlen)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; wchar_t *wstrinvnum = L&lt;SPAN style="font-size: 13.3333330154419px;"&gt;"1215265152";&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RtlStringCbCopy(tempstr, maxlen, wstrinvnum);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;On the PB side:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Function TestTheDLL(string InvNum, ulong MaxLen) library "testdll.dll"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;String ls_invnum&lt;/P&gt;&lt;P&gt;ls_invnum = space(22)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // string is 10 chars long (in the C++ code), 11 when you include null terminator, so double it for unicode storage&lt;/P&gt;&lt;P&gt;TestTheDLL(ls_invnum, 22)&lt;/P&gt;&lt;P&gt;messagebox("And the result is", ls_invnum)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you need to call the dll from both PB 9 and pb 12.5, then create 2 functions that act as wrappers to the main function that does the work. The PB9 version of the function will do the string conversion after calling the single , the 12.5 version will just return the result in the return string.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// function that actually does work&lt;/P&gt;&lt;P&gt;wchar_t *DoStuff()&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return L"&lt;SPAN style="font-size: 13.3333330154419px;"&gt;1215265152&lt;/SPAN&gt;";&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// wrapper for PB9&lt;/P&gt;&lt;P&gt;int __stdcall TestMyAPI9(char *tempstr, size_t maxlen)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; std::wstring_convert&amp;lt;std::codecvt &amp;lt;wchar_t, char, std::mbstate_t&amp;gt;&amp;gt; converter(new std::codecvt&amp;lt;wchar_t, char, std::mbstate_t&amp;gt;("CHS"));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; std::string narrowstr = converter.to_bytes(DoStuff());&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; size_t outputSize = narrowstr.length() + 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if(outputSize &amp;gt; maxlen) outputSize = maxlen;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; const char * str = new char[outputSize];&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; str = narrowstr.c_str();&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; strcpy_s(tempstr, outputSize, str);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; //delete[] str;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// wrapper for pb12.5&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;int __stdcall TestMyAPI125(wchar_t * tempstr, size_t maxlen)&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;{&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; RtlStringCbCopy(tempstr, maxlen, DoStuff());&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 13.3333330154419px;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;SPAN style="font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;}&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;Warning: None of this code is tested, but should be correct in concept.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Jul 2015 14:46:01 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/how-do-i-write-a-c-dll-which-a-parameter-ref-the-string-for-powerbuilder/qaa-p/11181943#M4128213</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2015-07-07T14:46:01Z</dc:date>
    </item>
    <item>
      <title>Re: how do i write a C++ dll which a parameter ref the  string for powerbuilder?</title>
      <link>https://community.sap.com/t5/technology-q-a/how-do-i-write-a-c-dll-which-a-parameter-ref-the-string-for-powerbuilder/qaa-p/11181944#M4128214</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hello sir&lt;/P&gt;&lt;P&gt;&amp;nbsp; thanks for your help,im appreciate,i have resolved this issue,i have defined wrong in PB 12.5,&lt;/P&gt;&lt;P&gt;i should define like this&lt;/P&gt;&lt;P&gt;function long testmyapi (ref string retstring) library "testdll.dll" alias for "testdll.dll;Ansi" instead of function long testmyapi (ref string retstring) library "testdll.dll;Ansi"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanks all!&lt;/P&gt;&lt;P&gt;regards&lt;/P&gt;&lt;P&gt;Ken&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Jul 2015 05:07:14 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/how-do-i-write-a-c-dll-which-a-parameter-ref-the-string-for-powerbuilder/qaa-p/11181944#M4128214</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2015-07-08T05:07:14Z</dc:date>
    </item>
    <item>
      <title>Re: how do i write a C++ dll which a parameter ref the  string for powerbuilder?</title>
      <link>https://community.sap.com/t5/technology-q-a/how-do-i-write-a-c-dll-which-a-parameter-ref-the-string-for-powerbuilder/qaa-p/11181945#M4128215</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The PB declaration should be this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;function long testmyapi(ref string retstring) library "testdll.dll" alias for "testmyapi;ansi"&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 08 Jul 2015 12:15:16 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/how-do-i-write-a-c-dll-which-a-parameter-ref-the-string-for-powerbuilder/qaa-p/11181945#M4128215</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2015-07-08T12:15:16Z</dc:date>
    </item>
  </channel>
</rss>

