Call the DLL developed in the VC environment in the VB Application

Source: Internet
Author: User
Application in VBProgramDLL developed in the VC environment: Ding junjian Release Date: 2001/01/03
 
ArticleAbstract:
This article discusses the DLL entry points, array parameter transfer, and other issues, and summarizes how to call the DLL method developed in the VC environment in the VB Application.
Keywords: DLL, VB, VC

Body:  

Call the DLL developed in the VC environment in the VB Application

1. Advantages of calling DLL
As the basis of the Windows operating system, the dynamic link library (DLL) has superior application performance:
DLL extends the features of applications. Because the DLL can dynamically load the address space of the process, the application can determine what operations need to be performed during runtime, and then load the correspondingCodeTo perform these operations as needed.
Dll can be written in multiple languages. For example, you can use VB to compile the application interface, and C ++ to writeAlgorithmCommunication and other underlying operations.
DLL simplifies the management of software projects. If different teams work on different modules during software development, it is easier to manage this project.
DLL helps to save memory. If two or more applications use the same DLL, all applications can share its pages as long as the DLL page is put into RAM once.
DLL facilitates resource sharing. Dll can contain resources such as dialog template, String, icon, and bitmap. Multiple applications can use DLL to share these resources.
DLL facilitates application localization. For example, an application that only contains code but does not contain user interface components can load a DLL containing localized user interface components.
DLL helps resolve platform differences. Different versions of Windows have different functions. Developers often want to call new functions. However, ifSource codeContains a call to a new function, and the application will run on a Windows version that does not provide the function, then the operating system loader will refuse to run the process. If you save these new functions in the DLL, the application can load them to the old version of Windows and successfully call the function.

2. Find the DLL entry point
Users who contact the DLL for the first time often encounter a problem: the DLL created in the VC environment runs well in the VC environment, when calling in a VB Application, errors such as "Call Convention errors" and "entry points not found" always occur. This is mainly caused by the following omissions.
First, you must note that the DLL functions and the function declaration in VB must be identical in terms of name, return type, parameter type, and number of parameters, especially case sensitivity.
Secondly, the entry function must be added to the. Def file of the DLL.
Finally, the extern "C", _ stdcall keyword must be added before the function definition.
For specific formats, see application instances.

3. Passing array parameters in DLL
Because the DLL is often used for some underlying operations, applications often need to transmit a large amount of data to the DLL. In C ++, pointers are the best choice for Array Operations, but there is no pointer concept in VB. This can be solved in two ways.
First, when declaring a DLL in VB, use byref instead of byval to pass the array pointer to the DLL.
In addition, declare the array as variant to directly pass the array to the DLL.

4. Application Instance
The following describes how to call the DLL created in the VC environment in VB through a specific example.
Create a DLL for signal processing, "sigpro. dll", which has a function "Fourier" for Fushi calculation ".

The declaration in VC:
Add the following code to "sigpro. H,
Extern "C"
{
Double export _ stdcall Fourier (long int * sample, int numsam, int overtoneorder, bool sinorcos );
}
Add the following code to "sigpro. cpp,
Extern "C"
Double export _ stdcall Fu (long int * sample, int numsam, int overtoneorder, bool sinorcos)
{
Int I;
Double result = 0.0;

If (sinorcos = true)
{
For (I = 0; I <numsam; I ++)
{
Result = Result + * (sample + I) * Cos (overtoneorder * I * 2*3.1415926/numsam );
}
}
Else
{
For (I = 0; I <numsam; I ++)
{
Result = Result + * (sample + I) * sin (overtoneorder * I * 2*3.1415926/numsam );
}
}
Result = Result * 2/numsam;
Return result;
}
Add the following code to "sigpro. Def,
Exports
Fourier

Call declaration in VB:
Public declare function Fourier lib "sigpro" (byref sample () as long, byval numsam as integer, byval overtoneorder as integer, byval sinorcos as Boolean) as double

 

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.