Page 1 of 1

How return pointer to string from dll function

Posted: Thu Nov 15, 2012 3:33 am
by dducatel
Hello,
I search to use a dll function (c++) for crypt a string.
The prototype of this function:
void Crypt(const char *StrToCrypt,const char *key,char *cryptedStr,int &length_out)

cryptedStr and length_out, are initialized by function.

In my installAware script I use this line for call the previous function

Code: Select all

~InstallAware Clipboard Data~
~Call DLL Function~
~{D431C00B-9B7E-44D9-A9B4-DAB5BB2D5A2C}~
~$SUPPORTDIR$\SetSecurity.dll,Crypt,void,RESULT,"pointer to string",$TOCRYPT$,"pointer to string",$CRYPTKEY$,"allocated string buffer (MAX_PATH length)",$CRYPTED$,long,$LENGTHOUT$,$~
~mIDEFunc.dll\mEXEFunc.dll~


So:
--> my dll function is called without problem but $CRYPTED$ and $LENGTHOUT$ are not initialized.
--> my dll function receive correctly $TOCRYPT$ and $CRYPTKEY$ variable

I tested to change $CRYPTKEY$ to "pointer to string" but this not fix my problem

You know how to solve this problem ?

Thanks in advance for your help

Re: How return pointer to string from dll function

Posted: Thu Nov 15, 2012 8:50 am
by FrancescoT
Dear User,

I don't know in which way you are actually handling those parameters with your function, but very probably, I believe exist a problem with that in your code.

The string pointer passed by InstallAware is allocated to a fixed size (MAX_PATH = 260) and this means, that your function should take the passed parameter for "int &length_out" as maximum number of characters (including null terminator) to be copied to the destination string.

In this case the maximum allowed characters is fixed to 260 (MAX_PATH) and this should be passed as fixed value to your function.

I suggest you to have a look at the following topic, where I describe with a sample IA script, how to handle a call to "GetVolumeInformationA" WIN API function.
http://www.installaware.com/forum/viewtopic.php?f=2&t=8958

Regards

Re: How return pointer to string from dll function

Posted: Fri Nov 16, 2012 2:17 am
by dducatel
Ok, I tried with minimal function

C++

Code: Select all

BOOL WINAPI st(__inout LPDWORD size){
   size=42;
   ::MessageBox(NULL,_T("TEST"),_T("TITLE"),MB_OK);
   return TRUE;
}


Code: Select all

~InstallAware Clipboard Data~
~Set Variable~
~{D9E22D78-A274-427C-BB33-76B2020C4B4E}~
~LENGTHOUT$MYAH$MYAH$FALSE~
~~

~Call DLL Function~
~{097CE19A-B96B-4ED7-ADFC-170A2DF3ED53}~
~$SUPPORTDIR$\SetSecurity.dll,st,bool,RESULT,"pointer to double word",$LENGTHOUT$,$~
~mIDEFunc.dll\mEXEFunc.dll~


The messageBox is displayed but $LENGTHOUT$ is not changed to 42

I don't understand why !

EDIT: I found !!!!!
I deleted "Return result in variable: RESULT" and, it works !!!!!!!!!!!!! (I use NX version)

Re: How return pointer to string from dll function

Posted: Fri Nov 16, 2012 9:33 am
by FrancescoT
Happy you solved :D :D :D !!!