View Full Version : How to return a LPSTR value to installshield script?

06-22-2005, 01:42 PM
I am using Installshield Pro 6.3. I want to write a VC++ dll file to open a file browser and select a file, then return the whole file path and name back to the installshield. The DLL file works ok, but I have problem to return it back to the installshield.
The dll function is below:
LPSTR __stdcall FileOpen()
CString szlstfile;
LPSTR test;
//Create an instance
CFileDialog fileDlg( TRUE, NULL, NULL, OFN_ALLOWMULTISELECT | OFN_HIDEREADONLY, "All Files (*.*)|*.*||");

// Initializes m_ofn structure
fileDlg.m_ofn.lpstrTitle = "My File Dialog";
// Call DoModal
if ( fileDlg.DoModal() == IDOK)
szlstfile = fileDlg.GetPathName(); // This is your selected file name with path
CString str = _T(szlstfile);
int nLen = str.GetLength();
test = str.GetBuffer(nLen);
//AfxMessageBox("Your file name is: " + test );
return test;

I do not know how to pass the LPSTR back to installshield 6.3 script. I tried to use:

prototype STRING DLLTest2.FileOpen();
function OnBegin()
int b ,nResult;
string svString;
STRING fileName;
fileName = FileOpen();
MessageBox("fileName = "+ fileName, INFORMATION);

The result from installshield is not expected. I am expecting the file path and name is displayed in the MessageBox, however, it displayed like; yyyyyyyyyyyy.

The problem might be in the prototype definition, but I don't how I should define that, does anybody know how to do that?

10-06-2005, 03:45 PM
Don't know if this is still an issue for you, but figured I'd answer anyway...

The prototype is fine, problem is that LPSTR is a pointer to character data, and the data itself goes out of scope when the function leaves. change the line

test = str.GetBuffer(nLen);

test = strdup(str.GetBuffer(nLen));
That way when str gets destroyed the buffer that test points to won't go with it.