Go to C #. Net to call the DLL compiled by VB. Code The example (I made some changes) is transferred from: how to call the DLL written in VB6 in http://www.taotechinfo.com/collect/2010222/n68565463.html. net.
Take C # as an example. Hope to help people who encounter problems.
This example is divided into two parts. First, generate the DLL of VB. Second, call in C.
Part 1:
1. Select the activx DLL project type in VB.
2. Modify the project name and class file name and add two functions, for example:
The code for convenient copy is as follows:
Public Function fnctestdllfordotnet (instr as string) as integer
Fnctestdllfordotnet = 9
End Function
Public Function fnctestdllfordotnet2 (instr as string) as integer
Fnctestdllfordotnet2 = 99
End Function
3. Select generate testdllproject1.dll from the File menu to generate the DLL.
The second part is as follows:
1. Open vs2005, select the Language C #, and set the project type to a window application.
Add a button to form. For example:
I added: Copy testdllproject1.dll to the System32 folder.
2. In Solution Explorer, right-click to reference and select Browse in the pop-up dialog box,Find testdllproject1.dll in system32, select it, and click OK.You can add it to the reference. For example:
After adding the DLL, you will see that the reference to this dll has been added to the reference,
3. Finally, write the code of the button to call the method in this vb dll.
Double-click the button on form and add the following code to the button's click event:
Testdllproject1.testclass1 Tc = new testdllproject1.testclass1 ();
String Ss = "KKKK ";
Int I = tc. fnctestdllfordotnet (ref SS );
Int I2 = tc. fnctestdllfordotnet2 (ref SS );
MessageBox. Show (I. tostring () + "" + i2.tostring ());
OK. Press Ctrl + Shift + B to compile the project, press F5 to run it, and click the button. For example, the result is displayed successfully.
To port testdllproject1.dll to another computer, copy it to the System32 folder of the machine, run the regsvr32 testdllproject1.dll command in "run" to register the component (some components do not need to be registered). In this way, the component can be successfully transplanted to other computers. Otherwise, an error "failed to retrieve components whose CLSID is {a string of characters} in the com class factory due to the following error: 80040154" will be reported"