Skip to content
⌘ NSIS Forum Archive

Problem sending string arg to DLL function

12 posts

yotambarzilay#

Problem sending string arg to DLL function

Hey all,
I need some assistant.
I'm calling a DLL function from an NSIS script. The function takes a char* as an argument. However, when I send a string to the DLL function, I only get the first char of the string.

Here's the call to the function:
Processes::KillParentProcess "chrome"

I get the string in the DLL by using popstring(char* str)

To debug, I used a message box and only got "c" instead of "chrome"

I'd really appreciate some input on this
rebot#
I'm having the same issue....anybody have any advice? Popstring is returning only the first character from the string parameter.
Afrow UK#
Are you using Unicode NSIS with a non-unicode DLL or maybe vice-versa?

Some code would help too.

Stu
rebot#
Unicode NSIS with Unicode RealProgress plugin.

From the call to plugin:
RealProgress:😁etailProgress /NOUNLOAD 30 40

Debugging the plugin code...in the function

int popstring(TCHAR *str, int len)
{
stack_t *th;

if (!g_stacktop || !*g_stacktop) return 1;
th=(*g_stacktop);
lstrcpyn(str, th->text, len);
*g_stacktop=th->next;
GlobalFree((HGLOBAL)th);
return 0;
}

str is returning '3' (as opposed to '30') when called from the DetailProgress function...

extern "C"
void __declspec(dllexport) DetailProgress(HWND hWndParent, int string_size,
TCHAR *variables, stack_t **stacktop,
extra_parameters *extra)
{
g_hWndParent=hWndParent;

EXDLL_INIT();
{
TCHAR szParam[8];

// Attempt to get a parameter.
if (popstring(szParam, 8) == 0)
{

//szParam evaluated at this point is '3'
//MessageBox(hWndParent, szParam, "Add szParam", MB_OK);

// Get the number of details to be printed.
g_iProgressBarAdd = str2int(szParam);

.
.
etc.
Afrow UK#
Are you definitely using Unicode character set in the plug-in? Sounds to me like you aren't because a Unicode '3' would be an ASCII '3' padded with a leading NULL byte thereby terminating the string as a single ASCII character.

Stu
Afrow UK#
I should probably elaborate a bit more:

* Check you have Unicode selected in Properties (that one is too obvious I know)
* Check you have since done a Clean/Rebuild
* Are you using the Unicode pluginapi.lib and header?

Stu
rebot#
Plugin files can be found below:

RealProgress.cpp
RealProgress.vcproj
RealProgress.dsp
RealProgress.sln
Afrow UK#
I can't see any reference to the Unicode plug-in API in there. You should really use that. For an example, look at my Aero plug-in which has both ANSI and Unicode plug-in APIs bundled and a build configuration for each. Also if you use the plug-in API you get myatoi and myatou so you don't need to use CRT (which you want to avoid).

Stu