For projects that are currently developed simultaneously using pb and. NET, if you want to call the functions of. NET under PB, you can only make. NET a COM component and then call it in PB.
The method is as follows:
1. Create a class library in. NET
Ii. Register a class library
3. Calling in PB
The following describes in detail: Take. NET2005 and PB11.5 as examples.
1. Create a class library in. NET
1. Open Microsoft Visual Studio 2005
2. Create a class library project: click File> New> project. In the displayed window, select a class library.
3. Add code:
A class library file of Class1.cs is displayed after the file is created. open the file and modify it to the following code:
Using System;
Using System. Collections. Generic;
Using System. Text;
Namespace demo
{
Public class Class1
{
Public int AddTenToParameter (int param1)
{
Return param1 + 10;
}
Public void SayHi ()
{
System. Windows. Forms. MessageBox. Show ("Hello World! ");
}
Public String GiveMeDate ()
{
Return DateTime. Now. ToLongDateString ();
}
}
}
4. Add introduction because the MessageBox requires the Form component.
5. Modify project properties, click Project, right-click, and select Properties.
On the "generate" TAB, select"Register for COM Iterop"
6. Add introduction in Class1.cs
Using System. Runtime. InteropServices;
7. Add the following attributes to the class
[ComVisible(true)] [ClassInterface(ClassInterfaceType.AutoDual)] [ProgId("demo.Class1")]
Now the class library is complete and can be compiled and used. To modifyProgIdYou can modify it in AssemblyInfo. cs.
Ii. Register a class library
Use regasm for registration
The command is as follows: regasm demo. dll/tlb: demo. tlb
3. Calling in PB
Use the following code in the program:
Int return_code
Return_code = example. ConnectToNewObject ("demo. Class1 ")
If return_code <> 0 then
Destroy example
Messagebox ('error', 'an error occurred while opening OLE! ')
Return
Else
Example. sayhi ()
Int v = 20
Messagebox ('result', v)
String s
S = example. givemedate ()
Messagebox ('result', s)
End if
Now we have finished calling the. NET Component in PB.