Announcement

Collapse
No announcement yet.

printf in NSIS plugin

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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.

  • #2
    Use wsprintf.

    Stu

    Comment


    • #3
      @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.

      Comment


      • #4
        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

        Comment


        • #5
          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?

          Comment


          • #6
            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

            Comment


            • #7
              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

              Comment


              • #8
                Yes you need to use a callback function that uses DetailPrint or LogText.

                Stu

                Comment


                • #9
                  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.

                  Comment


                  • #10
                    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.
                    "Only a MouseHelmet will save you from a MouseTrap" -Jason Ross (Me)
                    NSIS 3 POSIX Ninja
                    Wiki Profile

                    Comment

                    Working...
                    X
                    😀
                    🥰
                    🤢
                    😎
                    😡
                    👍
                    👎