- NSIS Discussion
- Problem sending string arg to DLL function
Archive: Problem sending string arg to DLL function
yotambarzilay
20th January 2011 16:07 UTC
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
15th April 2011 22:40 UTC
I'm having the same issue....anybody have any advice? Popstring is returning only the first character from the string parameter.
Afrow UK
15th April 2011 23:09 UTC
Are you using Unicode NSIS with a non-unicode DLL or maybe vice-versa?
Some code would help too.
Stu
rebot
15th April 2011 23:27 UTC
Unicode NSIS with Unicode RealProgress plugin.
From the call to plugin:
RealProgress::DetailProgress /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
15th April 2011 23:37 UTC
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
15th April 2011 23:39 UTC
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
16th April 2011 01:09 UTC
Yes. Unicode versions of all.
Afrow UK
16th April 2011 10:30 UTC
Well I'll need more than that. Attach the files including the vcxproj.
Stu
rebot
18th April 2011 18:43 UTC
vcproj file can be found here
Afrow UK
18th April 2011 19:21 UTC
I said files including the vcproj. I can't build without all the files.
Stu
Afrow UK
30th April 2011 10:41 UTC
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