General Usage of DLL-VB_DLL_Link for making output function by VB

Source: Internet
Author: User
VB production can be output function of the general DLL---VB_DLL _ link usage forum more and more people are concerned about DLL, special share VB production can output function of the general DLL---VB_DLL _ link usage

As you know, VB6 can only create ActiveX DLL files. Generally, tools such as VC are used to create common DLL files that can output functions. In fact, VB can be controlled during compilation and can be used to create a common DLL after proper processing. Using the vb_dll_link program, you can use VB to compile a common DLL file. This DLL file can be called by other programs, for example, using the declare statement in VB to call and execute functions in the DLL. The following describes how to use vb_dll_link:

1. installation:
This software is pure green software. Download vb_dll_link.exe and double-click it to automatically install it. Complete.

2. generate DLL:
After vb_dll_link is installed, open VB6, create a standard EXE project, project menu> remove form1, add a standard module such as module1.bas, and first write the DLL entry code to it:
Function dllmain (byval hinstdll as long, byval fdwreason as long, byval lpwreserved as long) as long
Dllmain = 1
End Function
Make sure that the parameter format is correct. Otherwise, the compilation fails. These parameters are useful in advanced programming. The dllmain function is executed when the first DLL call and the original program that calls the DLL exit. This function is required.

To prevent VB from reporting errors, add the following code:
Sub main ()
'Ensure that VB can be compiled
End sub

Then you can write custom function code to module1.bas, for example:
Function add (byval A as double, byval B as double) as double
Msgbox A + B
Add = a + B
End Function
Private sub M (S as string)
Msgbox S, vbinformation
End sub

After writing the code, save the project, select the File menu> Generate EXE, and change the file extension to. dll. Otherwise, the software cannot call up the file. Then the program runs. A dialog box is displayed, prompting you to select the module file of the function to be exported for this project. In this example, module1.bas, after selection, all function names in module1.bas will be listed in the Main Window of this program. If you have multiple modules, you can click "add from module" to add function names. The "add function name" button can be used to manually add the name of an existing function. Then, select the name of the function to be exported and click the "compile as DLL for output function" button to compile the common DLL file. It can output all the functions listed in the function list. If you do not need to compile a common DLL, click "General Compilation" or Press ESC.

3. Application dll:
The compiled generic DLL file can be called according to the calling method of the conventional DLL file. For example, the above example calls the method in VB as follows (change the string after lib to the DLL file name compiled above ):
Private declare function add lib "path and name of the compiled DLL file" (byval A as double, byval B as double) as double
Private declare sub M lib "path and name of the compiled DLL file" (s as string)
Private sub main ()
Add 9, 2 'Call the function in DLL
M strconv ("by Tongji Huang zheng", vbunicode) 'string needs to be converted to Unicode and then passed
End sub such as the following problem: Read your "VB production can output function of the general DLL---VB_DLL _ link usage", according to this method I generated the Lib, DLL file, however, function functions cannot be implemented when used in VC.
My code is:
Typedef double (* lpaddfun) (double, double );
Hinstance hdll;
Lpaddfun addfun;
Hdll = loadlibrary ("C: // project. dll ");
If (hdll! = NULL)
{
Addfun = (lpaddfun) getprocaddress (hdll, "add ");
If (addfun! = NULL)
{
Double result = addfun (1, 2 );
Cstring STR;
Str. Format ("% F", result );
MessageBox (STR );
}
}
Freelibrary (hdll); double result = addfun (); an error occurs here, that is, the return value cannot be returned.
Can you tell me what's going on?
It is best to provide more details !!
What are the locations and calls of LIB and DLL?

Related Article

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.