Public X(1024) As Double
在VB中调用VC所做DLL，关键是找出两者在数据类型及参数传递上的差别。VB中函数调用有传值和传引用两种方式，默认方式为传引用（BYREF）。在VB中传递字符串稍复杂一些。具体如何实现在VB ONLINE BOOK（VB5）和MSDN中都有介绍。另外，可以参照VB中预先声明的API调用方式，来进行DLL函数的编制和声明。
Calling DLL Functions from Visual Basic Applications
Home and Overview and How Do I and FAQ and Details and Sample
In order for Visual Basic applications (or applications in other languages such as Pascal or Fortran) to call functions in a C/C++ DLL, the functions must be exported using the correct calling convention without any name decoration done by the compiler. In Windows 3.x and 16-bit editions of Visual C++, you could use the _pascal keyword as part of the definition of the exported function. However, there is no _pascal keyword in the 32-bit editions of Visual C++. Instead the WINDEF.H header file has PASCAL defined as __stdcall. This creates the correct calling convention for the function (the called function cleans up the stack and parameters are passed from right to left) but decorates the function name differently. So, when __declspec(dllexport) is used on an exported function in a DLL, the decorated name is exported instead of the desired PASCAL style name, which is undecorated and all uppercase.
PASCAL name decoration is simply the undecorated symbol name in uppercase letters. The __stdcall name decoration prefixes the symbol name with an underscore (_) and appends the symbol with an at sign (@) character followed by the number of bytes in the argument list (the required stack space). So, the function when declared as:
int __stdcall func (int a, double b)
is decorated as:
The C calling convention (__cdecl) decorates the name as _func. Whereas the desired PASCAL style name is FUNC.
To get the decorated name, set the Generate Mapfile option in the Linker General category setting. Use of __declspec(dllexport) does the following:
If the function is exported with the C calling convention (_cdecl), it strips the leading underscore (_) when the name is exported.
If the function being exported does not use the C calling convention (for example, __stdcall ), it exports the decorated name.
So to simulate PASCAL name decoration and calling conventions, you must have the "Called Function stack clean-up" provided by using __stdcall and the undecorated uppercase name.
Because there is no way to override where the stack clean up occurs, you must use __stdcall. To undecorate names with __stdcall, you must specify them by using aliases in the EXPORTS section of the .DEF file. This is shown below for the following function declaration:
int __stdcall MyFunc (int a, double b);
void __stdcall InitCode (void);
In the .DEF file:
For DLLs to be called by programs written in the 32-bit version of Visual Basic version 4.0, the alias technique shown in this article is needed in the .DEF file. If alias is done in the Visual Basic program, use of aliasing in the .DEF file is not necessary. It can be done on the Visual Basic program by adding an alias clause to the declare statement as shown here:
Declare Function MyFunc Lib "dlllibname" Alias "_MyFunc@12" (...)
The complete syntax for the Visual Basic declare statement follows:
[Public and Private ] Declare Function name Lib
"libname" [Alias "aliasname" ] [([arglist])][As type]
Note A very good discussion (with example code) of calling a C DLL from Visual Basic can be found in the file VB4DLL.TXT in the VB directory
long funproc(double *lpBuffer)
//lpbuffer 即指向 第一个double元素。
Private Declare Function FunProc Lib "funproc.dll" _
(DoubleArray As Any) as long
dim da(99) as double
ret = FunProc(da(0))