我想用 C(C++) 去寫一個dynamic link library, 內含一個 子程序是傳入陣列
作運算,結果寫入另一陣列, 並將此結果陣列傳回. 這DLL file 是要用VB 的程式
來呼叫使用.
但一直有問題, 主要是傳陣列到DLL中子程序時, 有傳遞參數不合的問題.
相關簡化檔案如下, 有前輩可指點否?
非常感激!!!
C++ file ================================================
#include <windows.h>
#include <ole2.h>
int testadd(short number, float far * x,float far * y)
{
int i;
for (i=0;i<=number;i++)
y[i]=x[i]+x[i];
return 0;
}
Define file ===============================================
; testdll.def
LIBRARY testdll
CODE PRELOAD MOVEABLE DISCARDABLE
DATA PRELOAD MOVEABLE
EXPORTS
testadd @1
VB file ================================================
Option Explicit
Private Declare Sub testadd _
Lib "testdll.dll" ( _
ByVal number As Integer, _
ByRef x() As Single, _
ByRef y() As Single, _
)
Private Sub cmdGo_Click()
Dim x(10) As Single
Dim y(10) As Single
Dim number As Integer
Dim i As Integer
number = 10
For i=0 to number
x(i) = 1# * i
Next i
Call testadd(number, x(), y())
// 用 Call testadd(number, x(0), y(0)) 亦不行 !
For i = 0 To number
Print i, x(i), y(i)
Next i
End Sub