Old 18th June 2014, 13:41   #1
Dafr
Junior Member
 
Join Date: Jun 2014
Posts: 4
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 is offline   Reply With Quote
Old 18th June 2014, 14:27   #2
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
Use wsprintf.

Stu
Afrow UK is offline   Reply With Quote
Old 19th June 2014, 07:35   #3
Dafr
Junior Member
 
Join Date: Jun 2014
Posts: 4
@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.
Dafr is offline   Reply With Quote
Old 19th June 2014, 08:04   #4
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
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
Afrow UK is offline   Reply With Quote
Old 19th June 2014, 14:37   #5
Dafr
Junior Member
 
Join Date: Jun 2014
Posts: 4
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?
Dafr is offline   Reply With Quote
Old 19th June 2014, 15:11   #6
JasonFriday13
Major Dude
 
JasonFriday13's Avatar
 
Join Date: May 2005
Location: New Zealand
Posts: 877
Quote:
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.

"Only a MouseHelmet will save you from a MouseTrap" -Jason Ross (Me)
NSIS 3 POSIX Ninja
Wiki Profile
JasonFriday13 is offline   Reply With Quote
Old 19th June 2014, 18:42   #7
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,097
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...

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 20th June 2014, 06:48   #8
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
Yes you need to use a callback function that uses DetailPrint or LogText.

Stu
Afrow UK is offline   Reply With Quote
Old 23rd June 2014, 11:34   #9
Dafr
Junior Member
 
Join Date: Jun 2014
Posts: 4
Ok, I managed to do logging from the plugin dll.

in the dll:
code:
int funcAddr = popint();
pushstring("Logging from plugin DDL");
extra->ExecuteCodeSegment(funcAddr - 1, 0);



in the nsi:
code:
GetFunctionAddress $R0 LogText
Push $R0
MyPlugin::MyFunction



Thank you.
Dafr is offline   Reply With Quote
Old 28th June 2014, 13:55   #10
JasonFriday13
Major Dude
 
JasonFriday13's Avatar
 
Join Date: May 2005
Location: New Zealand
Posts: 877
Just something to note, this:
Quote:
Push $R0

MyPlugin::MyFunction
is the same as this:
Quote:
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.

"Only a MouseHelmet will save you from a MouseTrap" -Jason Ross (Me)
NSIS 3 POSIX Ninja
Wiki Profile
JasonFriday13 is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Tags
logging, plugin

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump