Esempio n. 1
0
        public static void DynamicLoadTests()
        {
            //string pathToDLL = @"C:\ProFast\Projects\DotNetClassesV3\WinAppComponents\TestprogSystemObjectsDLL\bin\Release\TestprogSystemObjectsDLL.dll";
            string pathToDLL = System.IO.Path.GetFullPath(@"..\..\..\..\..\DotNetClassesV3\WinAppComponents\TestprogSystemObjectsDLL\bin\Release\TestprogSystemObjectsDLL.dll");

            try
            {
                _msg.Length = 0;
                _msg.Append("DynamicLoadTests started ...");
                Program._messageLog.WriteLine(_msg.ToString());

                Type testClass = WindowsAssembly.LoadType(pathToDLL, "TestprogSystemObjectsDLL.PFInitClassExtended");

                WindowsAssembly.InvokeVoidMethodNoArguments(testClass, "DisplayTestMessage");

                //no error will be thrown on this call, even though routine is a void method and no parameters required
                object nores = WindowsAssembly.InvokeMethod(testClass, "DisplayTestMessage", null);

                int x = 5;
                int y = 8;
                int z = -1;

                object[] parms = new object[2] {
                    x, y
                };
                object res = WindowsAssembly.InvokeMethod(testClass, "AddTwoNumbers", parms);
                z = (int)res;

                _msg.Length = 0;
                _msg.Append("Result from AddTwoNumbers is ");
                _msg.Append(z.ToString());
                Program._messageLog.WriteLine(_msg.ToString());

                object obj = WindowsAssembly.InstantiateType(testClass);
                object val = WindowsAssembly.GetPropertyValue(obj, "TestDouble", null);
                _msg.Length = 0;
                _msg.Append("TestDouble value is ");
                _msg.Append(val.ToString());
                Program._messageLog.WriteLine(_msg.ToString());
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex));
                Program._messageLog.WriteLine(_msg.ToString());
                AppMessages.DisplayErrorMessage(_msg.ToString(), _saveErrorMessagesToAppLog);
            }
            finally
            {
                _msg.Length = 0;
                _msg.Append("... DynamicLoadTests finished.");
                Program._messageLog.WriteLine(_msg.ToString());
            }
        }