Define the following two functions to call. Net windows and Methods. Only string-type parameters are supported.
View code
Using System; Using System. Collections. Generic; Using System. LINQ; Using System. text; Using System. reflection; Using System. Windows. forms; Namespace Dotnetext { Public Class Util { Public String Runform ( String Assembly, String Type, String ARGs, Int Hasargs, Int Isdialog ){ VaR T = assembly. loadfrom (Assembly +" . Dll " ). GetType (type, True ); Form FRM = Null ; If (Hasargs> 0 ) {FRM = Activator. createinstance (T, argS) As Form ;} Else {FRM = Activator. createinstance (t) As Form ;} If (Isdialog> 0 ) {Frm. showdialog ();} Else {Frm. Show ();} Return "" ;} Public String Invokemethod (String Assembly, String Type, String Method, String ARGs, Int Hasargs, Int Isinstance ){ VaR T = assembly. loadfrom (Assembly + " . Dll " ). GetType (type, True ); Object Target = Null ; If (Isinstance> 0 ) {Target = Activator. createinstance (t );} If (Hasargs> 0 ){ Return T. invokemember (method, bindingflags. Default | bindingflags. invokemethod, Null , Target,New Object [] {ARGs}). tostring ();} Else { Return T. invokemember (method, bindingflags. Default | bindingflags. invokemethod, Null , Target, Null ). Tostring ();}}}}
Note:
1. When invokemethod is defined as invoke for the first time, no definition is found. If an error is prompted, The Function Definition of "INVOKE" cannot be found (the first character is in lower case)
2. directly use VaR T = type. when GetType (Type + "," + assembly, true) is. net can automatically load the DLL under the directory, and must be assembly in Pb. loadfrom ("XXX. DLL ")
3. The returned string type is any in Pb and must be converted using string.
// = Call in PbCode==================
View code
Oleobject util Long Conn_status // It is normal when conn_status is 0. For more information about other values, see the help document. Util = Create oleobject conn_status = Util. connecttonewobject ( " Dotnetext. util " ) MessageBox ( "" , String (Conn_status) util. runform ( " LIBA " , " LIBA. frmmain " , " Input parameters " , 1 , 1 ) MessageBox ( "" , String (Util. invokemethod ( " LIBA " , " LIBA. " , " Testa " , " AA " , 1 ,1 ); MessageBox ( "" , String (Util. invokemethod ( " LIBA " , " LIBA. " , " Testb " , " Bb " ,1 , 0 ); MessageBox ( "" , String (Util. invokemethod ( " LIBA " , " LIBA. " , " Testc " , " CC " , 0 , 1 ); Util. disconnectobject (); destroy util;