Skip to content
⌘ NSIS Forum Archive

printf in NSIS plugin

10 posts

Dafr#

printf in NSIS plugin

How I can do printf-like stuff in a self made plugin? I have heard of fprintf(g_output, ... but I don't know where g_output is declared.
Dafr#
@Stu, thanks, but doesn't this print to a string? Or is there some special string to use?
I haven't seen any printf logging in plugin code I've seen so far.
An example would do very nice here.
Afrow UK#
Where do you want to write output to? If it's to the installer log window you have to send the LVM_INSERTITEM message to the list view control. Normally a plug-in will use pushstring() to push its output or return value to the stack for the caller.

Edit: You can also call a callback function while your plug-in executes. You still use the stack to pass messages though.

Stu
Dafr#
An extra word on the request:
I am using the Advanced Logging Build from the Special Builds and have set 'LogSet on'. From the NSIS file, I use 'LogText "foobar"' to log to the install.log file in the installation folder.
I would like to log to this file from within our own C plugin as well.

Regarding previous post:
Return value is easy to do but I would like to do logging while executing the plugin function.
Can you explain how to call this callback from the C code?
JasonFriday13#
Originally Posted by Dafr View Post
Can you explain how to call this callback from the C code?
I believe nsdialogs.dll has this functionality, and the source for it is available too.
Anders#
I don't think you can write to the LogSet log because NSIS itself opens that file with just FILE_SHARE_READ so you will not be able to open it for write access...
Dafr#
Ok, I managed to do logging from the plugin dll.

in the dll:
int funcAddr = popint();
pushstring("Logging from plugin DDL");
extra->ExecuteCodeSegment(funcAddr - 1, 0);
in the nsi:
GetFunctionAddress $R0 LogText
Push $R0
MyPlugin::MyFunction
Thank you.
JasonFriday13#
Just something to note, this:
Push $R0

MyPlugin::MyFunction
is the same as this:
MyPlugin::MyFunction "$R0"
When using a direct plugin call, the arguments are automatically pushed onto the stack in reverse order, so in you're plugin you pop them off the stack in order. This is documented in the NSIS docs.