cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
TruthOf42
Level 2

Returning a string from c++ dll function

I am trying return a programmatically built string from a c++ function to InstallScript. For example, appending and replacing (sub-strings) a string that I return from another function.

Code in c++
SQLHELPER_API LPCSTR GetAvailableAppName(LPCSTR appNameP)
{
//return "this works just fine";
std::string newAppName = "I work, maybe?";
LPCSTR returnVal = newAppName.c_str();
return returnVal; //this will either return an empty string or a mishmash of the string
}


code in InstallScript
prototype cdecl string      SqlHelper.GetAvailableAppName(BYREF string);
string ERPORTALAPP;
ERPORTALAPP = GetAvailableAppName("eRPortalApp"); //returns an empty string or a mishmash of the string


I have tried altering my c++ function so that it returns a string instead of LPCSTR, but did NOT change any code in InstallScript. This resulted in a run-time error in InstallShield.

How can I pass a string back to InstallScript?
Labels (1)
0 Kudos
(1) Reply
MichaelU
Level 12 Flexeran
Level 12 Flexeran

For APIs used across DLL boundaries, typically the best approach is for the API to accept a pointer to a buffer (and a size of that buffer) and fill it in. Many Windows API functions, like GetEnvironmentVariable or MsiGetProperty work this way, and these are fairly easy to call from InstallScript.
0 Kudos