vc中写dll如下.h 中 #ifndef __INIT_VB_DATA_H__ #define __INIT_VB_DATA_H__extern "C" __declspec( dllexport ) char * __stdcall h2d( IN char *h, OUT char *d );#endif.cpp中// init_vb_data.cpp : Defines the entry point for the DLL application. //#include "stdafx.h" #include "init_vb_data.h"int __stdcall vcinit( unsigned char *data, size_t length ) { size_t i, j; for( i = 0; i < length; i += 256 ) { for( j = 0; j < length - i; j++ ) { *( data + i + j ) = ( unsigned char )j; } } return 0; }.def中 [code=BatchFile]; init_vb_data.def : 声明 DLL 的模块参数。LIBRARY "init_vb_data"DESCRIPTION 'vcinit'EXPORTS ;
vcinit[/code]vb中Option Explicit Private Declare Function vcinit Lib "D:\JennyVenus\源程序\vc\init_vb_data\Debug\init_vb_data.dll" (ByRef buf As Byte, ByVal length As Long) As LongPrivate Sub Command2_Click() Dim a(0 To 99) As Byte Dim i As Long a(1) = 99 Call vcinit(a(0), 100) For i = 0 To 99 Debug.Print a(i) Next i End Sub
中
#ifndef __INIT_VB_DATA_H__
#define __INIT_VB_DATA_H__extern "C" __declspec( dllexport ) char * __stdcall h2d( IN char *h, OUT char *d );#endif.cpp中// init_vb_data.cpp : Defines the entry point for the DLL application.
//#include "stdafx.h"
#include "init_vb_data.h"int __stdcall
vcinit( unsigned char *data, size_t length )
{
size_t i, j;
for( i = 0; i < length; i += 256 )
{
for( j = 0; j < length - i; j++ )
{
*( data + i + j ) = ( unsigned char )j;
}
} return 0;
}.def中
[code=BatchFile]; init_vb_data.def : 声明 DLL 的模块参数。LIBRARY "init_vb_data"DESCRIPTION 'vcinit'EXPORTS
;
vcinit[/code]vb中Option Explicit
Private Declare Function vcinit Lib "D:\JennyVenus\源程序\vc\init_vb_data\Debug\init_vb_data.dll" (ByRef buf As Byte, ByVal length As Long) As LongPrivate Sub Command2_Click()
Dim a(0 To 99) As Byte
Dim i As Long
a(1) = 99
Call vcinit(a(0), 100)
For i = 0 To 99
Debug.Print a(i)
Next i
End Sub
#define __INIT_VB_DATA_H__extern "C" __declspec( dllexport ) int __stdcall vcinit( unsigned char *buf, size_t length );#endif