Create a DLL [Repost] that can output a function in VB

xiaoxiao2021-03-06  129

Reposted from: http://www.applevb.com/art/vb_dll.html VB created DLL is just a COM component, which cannot be used as a DLL of the output function. Today, from Yuan Bo to find a method of creating a DLL of the output function. The VB compilation file actually took two compiled methods, first to call C2.exe to generate an OBJ file, then call the Link.exe connection. If you add an Export option when LINK, it is actually an output function. However, these shields in VB's engineering options. And excessive is: VB will delete the OBJ file after completion of Build, which cannot output a function via Link. However, I found a way to change the way, just create an EXE project, write the following statement in the form_load event: private suform_load () IF (MsgBox ("HEHE", vbokcancel) = vbok) Then shell "LINK2 .exe "& command $ END IF Endend Sub then compiled as linkTemp.exe, next to link.exe to link2.exe, renamed LinkTemp.exe to link.exe. This will pop up the dialog box when the VB calls Link.exe, and the process is interrupted. At this time, you can have the opportunity to copy the OBJ file. Then I created an ActiveX DLL project, add a Module to this project and create a public function Mathadd: Public Function Mathadd (BYVAL A As Long, Byval B As Long) As long mathadd = a bend function builder This project is interrupted when LINK is interrupted. Then back up the created class1.obj, module1.obj, project1.obj. Then you can call Link2.exe to connect Obj to DLL, my connection code is: link2.exe "e: /vbdll/class1.obj" "E: /VBDLL/Module1.Obj" "E: / VBDLL / Project1. Obj "" E: / Program Files / Microsoft Visual Studio / VB98 / VBAEXE6.LIB "/ Entry: __ vbas / export: Mathadd /out:"e:/vbdll/projectok.dll" / base: 0x11000000 /subsystem :windows, 4.0 / VERS Note The / Entry and / Export Switch inside, / the / export switch declares the output function Mathadd. This will be greatly made :-D, can be introduced by other languages, such as in VB, only: private declare function mathadd lib "e: /vbdll/projectok.dll" (Byval A As Long, BYVAL B AS Long) AS Long Yes.

转载请注明原文地址:https://www.9cbs.com/read-127147.html

New Post(0)