Maybe possibility for C# plugins

Interested in developing new plug-ins? Got one to share? Post here!
MaxLogic.eu
Posts: 25
Joined: Sat Oct 08, 2011 2:42 am
Contact:

Re: Maybe possibility for C# plugins

Postby MaxLogic.eu » Tue Jan 17, 2012 12:18 pm

The RunTimeExecute function of the Runtime Plug-in is called just once, and there is no parameter newvariables...
Show me more code and let me know if we are speaking about the IDE or the Runtine plug-in
About me:
Pawel Piotrowski is a software developer and a Delphi and C++/C# expert with 15 years of programming experience.
Learn more at http://www.maxlogic.eu

christ23
Posts: 82
Joined: Mon Jan 16, 2012 4:51 am

Re: Maybe possibility for C# plugins

Postby christ23 » Tue Jan 17, 2012 1:53 pm

Wow, thanks for your fast reply.
I will provide some code to you tomorrow, because i am at home now, and i am not able/allowed to transfer any line of code from my work to my home due to our safety guidelines.

But i think we are on the right way - your "support", Max, is really nice, thank you for this !
Think there might be many people like me not knowing what to do and asking you for help ;)... so thanks for your patience !!

Until soon ... (i will edit this post tomorrow with the code)

MaxLogic.eu
Posts: 25
Joined: Sat Oct 08, 2011 2:42 am
Contact:

Re: Maybe possibility for C# plugins

Postby MaxLogic.eu » Tue Jan 17, 2012 2:54 pm

I'm always glad to be of some help.
But please post the code as a new post, otherwise I will not be notified about your reply and will not look into this topic until I got a email notification ;)
About me:
Pawel Piotrowski is a software developer and a Delphi and C++/C# expert with 15 years of programming experience.
Learn more at http://www.maxlogic.eu

christ23
Posts: 82
Joined: Mon Jan 16, 2012 4:51 am

Re: Maybe possibility for C# plugins

Postby christ23 » Wed Jan 18, 2012 2:37 am

Ok,

so i cleaned my code completely, and now it looks like in the example :

Code: Select all

public unsafe void RunTimeExecute(
            uint window,
            string variables,
            string state,
            Int32 callback,
            ref Int32 returnVal, ref string newVal)
        {
            IntPtr ptr = new IntPtr(callback);
            RunTimeCallback callbackMethod = (RunTimeCallback)Marshal.GetDelegateForFunctionPointer(ptr, typeof(RunTimeCallback));
             (...)
            Thread.Sleep(1000);
            callbackMethod(100, "Finalize");

            newVal = "Test, value01";
            returnVal = 333;
        }


Hmmm - in the docs it is written, that the RunTimeExecute "will always be called twice" (IA help file, under the book 'plugin authoring') ?

The variables from IA are correctly stored in the 'string variables', but how can i pass back variables to IA from the plugin ? In IA i created a variable named 'Test', but it is not updated by the plugin.

MaxLogic.eu
Posts: 25
Joined: Sat Oct 08, 2011 2:42 am
Contact:

Re: Maybe possibility for C# plugins

Postby MaxLogic.eu » Wed Jan 18, 2012 6:49 am

This function is called just once. Anyway, it would be illogical, to call it twice and to execute the installation twice, right?
as for the test variable, my net bridge past anything back to IA, what IA do with it I can not tell.
Please run your plug-in in my test tool, in the log memo on the bottom of the window, you should be notified what was send back by your plug-in



BTW: the test tool was updated a bit.
Please go to
http://www.maxlogic.eu/downloads/install_aware/

there are also some delphi and C# samples.
About me:
Pawel Piotrowski is a software developer and a Delphi and C++/C# expert with 15 years of programming experience.
Learn more at http://www.maxlogic.eu

christ23
Posts: 82
Joined: Mon Jan 16, 2012 4:51 am

Re: Maybe possibility for C# plugins

Postby christ23 » Tue Jan 24, 2012 7:59 am

Ok, right - i am with you : it does not make sense to call the Execute twice. Seems to be wrong in the docs of IA.

And yepp, in the test tool the test variable is past back.

Here is what is written in the test tool :

Code: Select all

Loading Bridge DLL From : C:\Documents and Settings\***\My Documents\Doku\Installer\_InstallAware\Plugins_dotNet\NETBridgeProject\_Bin\data\EXEPlug_NetBridge.dll
 RunTimeExecute was successfuly called
  Result: 0
  Return: 333
  NewVariables: "Received vars: "MyVariables"
Received State: "MyState"code]

Here the code i am running :
[code]public unsafe void RunTimeExecute(
            uint window,
            string variables,
            string state,
            Int32 callback,
            ref Int32 returnVal, ref string newVal)
        {
               IntPtr ptr = new IntPtr(callback);
            RunTimeCallback callbackMethod = (RunTimeCallback)Marshal.GetDelegateForFunctionPointer(ptr, typeof(
              RunTimeCallback));

            callbackMethod(0, "Initialize");
            Thread.Sleep(1000);

            callbackMethod(50, "Half");
         
            Thread.Sleep(1000);
            callbackMethod(99, "Finalize");

            //newVal = "new value from .Net\""+variables+"::"+state+"\"";
            newVal = "Received vars: \""+variables+"\""+"\r\n"+    "Received State: \""+state+"\"";
            returnVal = 333;
  }


Even the progress bar in the testtool moves :) - but why is nothing post back in IA.

One idea in my mind :
- termination of the strings (null-termination, but this is done implicit by .Net)

Maybe one of the IA developers can support at this point, or provide some information what could be wrong ?

MaxLogic.eu
Posts: 25
Joined: Sat Oct 08, 2011 2:42 am
Contact:

Re: Maybe possibility for C# plugins

Postby MaxLogic.eu » Thu Jan 26, 2012 7:59 am

From the IA Help

Code: Select all

The RunTimeExecute function will always be called twice:

1) The first call of the function will always have the NewVariables parameter set to NULL. The function should perform its installation action, perpare the NewVariables string, and store it in a buffer. The function should return the length of the buffer as its result. This will enable the caller to allocate sufficient memory to hold the NewVariables string.

2) The second call of the function will always pass a non-NULL NewVariables parameter, with just enough space to hold the NewVariables string. In this second iteration, the function should not perform an installation action at all. It should instead copy to the buffer pointed to by the NewVariables variable the NewVariables string it generated and stored in the first iteration. In the second iteration, the function should always return 0.



Sinan, the maker of IA helped me with this a bit.
The IA help is correct and I was wrong, this function is indeed called twice.
In theory, this should be of no matter as I'm just sending anything forth and back.
But, strings are not sent as plain pointers to the NET assembly, there is no way to find out if the NewVariables are nil or just empty ''.
So I need to expand the function by a new parameter which will tell the Assembly in which mode it have to work.

The New Declaration of the function is as follows:


DELPHI FOR NET:

Code: Select all

function TClass1.RunTimeExecute(
    Window: uint;
    const Variables, State: String;
    PlugProgressIndicator : integer;
    var Return: Integer;
    var NewVariables: String;
    FirstIteration: Boolean): Integer; unsafe;



and here is the declaration for C#:

Code: Select all



unsafe int RunTimeExecute(
         uint window,
         string variables,
         string state,
            Int32 callback,
         ref Int32 returnVal,
         ref string newval,
         bool firstiteration)



I updated the NET Bridge and the Sample plug-ins, you can find the whole pack here:
http://www.maxlogic.eu/downloads/install_aware/
About me:
Pawel Piotrowski is a software developer and a Delphi and C++/C# expert with 15 years of programming experience.
Learn more at http://www.maxlogic.eu

christ23
Posts: 82
Joined: Mon Jan 16, 2012 4:51 am

Re: Maybe possibility for C# plugins

Postby christ23 » Thu Jan 26, 2012 2:43 pm

Dear Pawel - you are the man !! Yeah great to read this, and great to realize that i am not as stupid as is thought ;).

I will try to implement the new C# declaration tomorrow when i am back at my office. But your modified function makes sense, and complies to the docs.

At this point thanks to you and Sinan !

MaxLogic.eu
Posts: 25
Joined: Sat Oct 08, 2011 2:42 am
Contact:

Re: Maybe possibility for C# plugins

Postby MaxLogic.eu » Fri Jan 27, 2012 4:39 am

Please let me know how it went.
and keep in mind that:
There’s No Such Thing As A Stupid Question …… Only Stupid Answers.
About me:
Pawel Piotrowski is a software developer and a Delphi and C++/C# expert with 15 years of programming experience.
Learn more at http://www.maxlogic.eu

christ23
Posts: 82
Joined: Mon Jan 16, 2012 4:51 am

Re: Maybe possibility for C# plugins

Postby christ23 » Fri Jan 27, 2012 4:48 am

Hi,

yeah it is running !! I get my variables back, the progressbar updates - and i am happy :).

This is really great fine, thank you.

christ23
Posts: 82
Joined: Mon Jan 16, 2012 4:51 am

Re: Maybe possibility for C# plugins

Postby christ23 » Fri Jan 27, 2012 9:52 am

Ok, so now the next questions are following ...

About the DesigntTimeEdit :
My example scenario : In DesignTimeEdit, a messageBox just asking "YES or NO?" is popping up. If the user clicks "YES", the RuntimeExecute should do domething different as when the user chooses "NO".
How do i tell my RuntimeExecute, what the user has chosen in DesignTimeEdit ?

The docs say something about the State and NewState Parameters. But - the variable "state" in RunTimeExecute is always "null" (nil).

How to do that ? Has the chosen answer to be stored in a file or so ? Do you have any ideas ?

christ23
Posts: 82
Joined: Mon Jan 16, 2012 4:51 am

Re: Maybe possibility for C# plugins

Postby christ23 » Tue Feb 07, 2012 6:51 am

Hi there, it's me again ...

Is it possible, that the DesignTimeEdit-Function (in C#) also has the wrong parameters ?
I am doing this :

Code: Select all

 public unsafe int DesignTimeEdit(uint Window, String State, String NewState, bool DisplayDialog)
{
            List<String> stringList = new List<String>();
            if (NewState == null) // or if(DisplayDialog) ??!
            {
                Form1 ff1 = new Form1();

                if (State == null)
                {
                    stringList.Add("FALSE");
                    stringList.Add("");
                }
                else
                {
                    //stringList.commaText = State; //?
                    ff1.ShowDialog();

                    if (ff1.checkBox1.Checked)
                    {
                        stringList[0] = "TRUE";
                    }
                    else
                    {
                        stringList[0] = "FALSE";
                    }

                    stringList[1] = "variablenText";
                    strNewState = ListToString(stringList, globalDelim);
                    return strNewState.Length;
                }
            }
            else
            {
                //this call is to obtain user selection state
                NewState = strNewState;
                return 0;
            }
}


When i store the variables/state in the strNewState, at the second call it (=strNewState) is again "null", so the plugin cannot be configured.

Any help ? Any suggestions ?

MaxLogic.eu
Posts: 25
Joined: Sat Oct 08, 2011 2:42 am
Contact:

Re: Maybe possibility for C# plugins

Postby MaxLogic.eu » Tue Feb 07, 2012 12:58 pm

do not check if the newstate variable is null, in fact it shall never be.... the engine which loads net assemblies into will send an empty but not null string.

just test for displaydialog
About me:
Pawel Piotrowski is a software developer and a Delphi and C++/C# expert with 15 years of programming experience.
Learn more at http://www.maxlogic.eu

christ23
Posts: 82
Joined: Mon Jan 16, 2012 4:51 am

Re: Maybe possibility for C# plugins

Postby christ23 » Tue Mar 27, 2012 1:45 am

Ok, the thing with "displaydialog" is working, but still my plugin does not react at of what the user has chosen to do in the RunTimeExecute. Any ideas ?

Here is my code :

Code: Select all

          public unsafe int RunTimeExecute(
            uint window,
            string variables,
            string state,
            Int32 callback,
            ref Int32 returnVal,
            ref string newval,
            bool firstiteration)
        {
           if (firstiteration)
            {
                IntPtr ptr = new IntPtr(callback);
                RunTimeCallback callbackMethod = (RunTimeCallback)Marshal.GetDelegateForFunctionPointer(ptr, typeof(
                  RunTimeCallback));

                MessageBox.Show("First call");

                callbackMethod(0, "Initialize");
                Thread.Sleep(1000);
                callbackMethod(50, "Half");

                Thread.Sleep(1000);
                callbackMethod(100, "Finalize");

                // how can i get user chosen option here ?

                this.m_newval = "TEST,23,TEST2,5,PROGRESS,100";
                returnVal = 0;
                MessageBox.Show("First call finished");
                return m_newval.Length;
            }
            else
            {
                MessageBox.Show("Second call");
                newval = this.m_newval;
                return 0;

            }


How can i test what the user has chosen in DesignTimeEdit ?
The code of my DesignTimeEdit is this :

Code: Select all

if (DisplayDialog)
            {
                Form1 ff1 = new Form1();

                ff1.ShowDialog();

                if (ff1.checkBox1.Checked)
                {
                    stringList[0] = "TRUE";
                }
                else
                {
                    stringList[0] = "FALSE";
                }

                stringList[1] = "variablenText";
                strNewState = ListToString(stringList, globalDelim);
                return strNewState.Length;

            }
            else
            {
                //this call is to obtain user selection state
                String xyz = stringList[0];
                NewState = strNewState;
                return 0;
            }


I thought the user decision will be stored in stringList[], but it seems to be cleared when calling the RunTime Execute.
Hm, and when i am calling my dlls in the PluginTestTool, the variable "state" in the RunTimeExecute is filled; called by the Installer, it is null.

Any ideas ?

MaxLogic.eu
Posts: 25
Joined: Sat Oct 08, 2011 2:42 am
Contact:

Re: Maybe possibility for C# plugins

Postby MaxLogic.eu » Tue Mar 27, 2012 8:22 am

Please have a look at the parameters send to this procedure:

Variables: The names and values of variables used in the setup script
State: State of plug-in controls, as chosen during compile time


I think this is what you are looking for.
About me:
Pawel Piotrowski is a software developer and a Delphi and C++/C# expert with 15 years of programming experience.
Learn more at http://www.maxlogic.eu


Return to “Plug-In Development”

Who is online

Users browsing this forum: No registered users and 9 guests