PB calls two entry functions of. Net code

Source: Internet
Author: User

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; 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.