Create a DLL that can output a function in VB

zhaozj2021-02-08  203

The DLL created in the VB is just a COM component and 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 sub flow_load ()

IF ("HEHE", VBOKCANCEL) = VBOK) THEN

Shell "Link2.exe" & Command $

END IF

End

End Sub

Then compile to linkTemp.exe, then renamed 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) As long

Mathadd = a b

END FUNCTION

Builder This project will be interrupted when LINK. 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 that the / Entry and / Export switch, / export switch declares the output function Mathadd. This will be greatly made :-D, can be introduced by other languages, such as in VB, only need:

Private Declare Function Mathadd LIB "E: /VBDLL/Projectok.dll" (Byval A as long) As long

Yes.

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

New Post(0)