PDA

View Full Version : strings between IScript and dll's



builder_will
07-06-2006, 11:27 AM
I need to get a string from a C++ function in a dll to InstallScript code as part of our product's license verification process. There's a seemingly sufficient example of the Script side of the process in the help documentation (the UseDLL Example). Using the code from the example, I'm able to pass my c++ function the string (as a char* function argument) and modify it. However, when we get back into the Script, none of the modifications persist. I'm not dynamically allocating new memory or changing the char* at all. Modifications to the values in the array allocated by IScript -should- be persisted (as the UseDLL example implies).
Here's the function:


UINT __stdcall MydllReturn(int size, char* const string)
{
for(int i=0; string[i] != '\0'; i++)
{
if(i%2 == 0)
{
string[i] = ((string[i] + i*3) % 26)+65;
}
}

MessageBox(
GetForegroundWindow(),
TEXT(_str_cat("I changed the string to: ", string)),
TEXT("From the dll"),
MB_OK | MB_ICONINFORMATION);

return ERROR_SUCCESS;
}

The value printed in the dll's message box is modified, but the value printed from the Script shows no change. I'm using the exact Script code from the UseDLL example, quoted below for reference.


prototype LicenseGenDLL.MydllReturn( NUMBER, POINTER );

...


// Get a string from the user.
AskText ("Enter an example string.", "Example string.",
svString);
// Get a pointer to the string to pass to MydllReturn.
psvString = &svString;
// Get the string length to pass to MydllReturn.
nValue = StrLength (svString);
// Call MydllReturn.
MydllReturn (nValue, psvString);
// Display the string to observe how it was altered by MydllReturn.

SprintfBox (INFORMATION, "UseDLL", "MydllReturn() changed the string " +
"to: %s", svString);


Any thoughts on what I'm missing?

RobertDickau
07-06-2006, 06:03 PM
A simple example with a slightly different prototype seemed to work. The C++ DLL code:
#include <windows.h>

int __stdcall ModifyStringInPlace(char *test)
{
MessageBox(GetForegroundWindow( ),
test, TEXT("In"), MB_OK | MB_ICONINFORMATION);

for (int j=0; test[j] != '\0'; j++)
{
if (j%2 == 0)
test[j] = ((test[j] + j*3) % 26) + 65; // I know, I know...
}

MessageBox(GetForegroundWindow( ),
test, TEXT("Out"), MB_OK | MB_ICONINFORMATION);

return ERROR_SUCCESS;
}And the InstallScript:
prototype int StringTest.ModifyStringInPlace(BYREF STRING);

function OnBegin( )
STRING inout_string;
begin

inout_string = "Testing";

UseDLL(SUPPORTDIR ^ "StringTest.dll");

ModifyStringInPlace(inout_string);

MessageBox(inout_string, INFORMATION); // displays "GeRtNnR"

UnUseDLL("StringTest.dll");

end;

builder_will
07-07-2006, 08:55 AM
Changing the prototype function declaration in my script from


prototype BuilderLicenseGenDLL.MydllReturn( NUMBER, POINTER);

to


prototype BuilderLicenseGenDLL.MydllReturn( NUMBER, BYREF STRING);

did the trick.

Thanks for being so helpful Rob. =)