Link to home
Start Free TrialLog in
Avatar of deming
deming

asked on

How do I return a string from C++ DLL?

Hello,

I have the following C++ code in a DLL which all works fine. However, it is horribly inefficient. Please help to simplify.  

(1) Here is the working C++ function:

__declspec(dllexport) LPSTR __stdcall PopStrData2(const char *object, char *retval){
      if(object == NULL) object = "";
      BPCHAR p;
      if(!BeginTransaction()) return FALSE;
      if(!Pop(&pSharedData->pStrStacks, object, &p)) {EndTransaction();return FALSE;}
      strcpy(retval, p);
      hfree(p);
      EndTransaction();
      return retval;
}

(2) I am calling the function from another program in the format:

Dim Buffer="                                            "
MyString = PopStrData2("OBJECT", Buffer)


(3) QUESTION

Is there someway to get rid of the "char *retval" parameter in the C++ function PopStrData2(const char *object, char *retval) ?

In otherwords, I want to simply call:

Dim MyMsg as String
MyMsg = PopStrData2("OBJECT")

What changes do I need to make to my C++ dll function?

ASKER CERTIFIED SOLUTION
Avatar of dualsoul
dualsoul

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Daij-Djan
Daij-Djan

BSTR is unicode too btw
> BSTR is unicode too btw

it's just what i've said :)
BSTR is the pointer to sequence 16bit character
upsi ;) Didnt see that.