for(j=0;j<value2;j++) { array2[i][j]=array1[i][j]; } //printf("\n"); } for(i=0;i<value1;i++) { for(j=0;j<value2;j++) { array1[i][j]=array2[j][i]; } } return 1; }class CDynamDLL:public CWinApp { public: virtual BOOL Initlnstance(); virtual int ExitInstance(); CDynamDLL(LPCTSTR pszAppName):CWinApp(pszAppName){} }; BOOL CDynamDLL::Initlnstance() { SetDialogBkColor(); return TRUE; } int CDynamDLL::ExitInstance() { return CWinApp::ExitInstance(); } CDynamDLL dynamDLL("dynam.dll"); 下面是VB中的代码,功能是定义了一个数组,并且调用动态连接库中的addem函数,并且显示被处理后的数组结果 Dim Twod(2, 2) As Integer Private Declare Function addem Lib "dynam" (ByVal value1 As Integer, ByVal value2 As Integer, Twod) As Boolean Dim intvalue3 As Integer Dim i As Integer Dim j As Integer Dim booIn As Boolean Private Sub Form_Load() intvalue3 = 3 For i = 0 To 2 Step 1 For j = 0 To 2 Step 1 Twod(i, j) = intvalue3 intvalue3 = intvalue3 + 1 Next j Next i End Sub booIn=addem(3,3,Twod) Private Sub Command1_Click() Dim strs As String strs = " " For i = 0 To 2 Step 1 For j = 0 To 2 Step 1 strs = strs + "," + Str(Twod(i, j)) Next j Next i Label1.Caption = strs End Sub
Private Declare Function addem Lib "dynam" (ByVal value1 As long, ByVal value2 As long, ByRef Twod as long) As longDim Twod(0 to 2, 0 to 2) As longbooIn=addem(3,3,Twod(0,0))但是你在dll中的函数有问题,会出现指针越界的错误
并且处理这个数组,使其转置,并且返回结果,但是在调用过程中有问题,
参数传递好像不正确,请各位大侠指点,不胜感激
#include <afxwin.h>
#include"dynam.h"
extern"C"
bool PASCAL EXPORT addem(int value1,int value2,int array1[50][50])
{
int i,j;
int array2[50][50];
for(i=0;i<100;i++)
{
for(j=0;j<100;j++)
{
array2[i][j]=0;
}
}
for(i=0;i<value1;i++)
{
for(j=0;j<value2;j++)
{
array2[i][j]=array1[i][j];
}
//printf("\n");
}
for(i=0;i<value1;i++)
{
for(j=0;j<value2;j++)
{
array1[i][j]=array2[j][i];
}
} return 1;
}class CDynamDLL:public CWinApp
{
public:
virtual BOOL Initlnstance();
virtual int ExitInstance();
CDynamDLL(LPCTSTR pszAppName):CWinApp(pszAppName){}
};
BOOL CDynamDLL::Initlnstance()
{
SetDialogBkColor();
return TRUE;
}
int CDynamDLL::ExitInstance()
{
return CWinApp::ExitInstance();
}
CDynamDLL dynamDLL("dynam.dll");
下面是VB中的代码,功能是定义了一个数组,并且调用动态连接库中的addem函数,并且显示被处理后的数组结果
Dim Twod(2, 2) As Integer
Private Declare Function addem Lib "dynam" (ByVal value1 As Integer, ByVal value2 As Integer, Twod) As Boolean
Dim intvalue3 As Integer
Dim i As Integer
Dim j As Integer
Dim booIn As Boolean
Private Sub Form_Load()
intvalue3 = 3
For i = 0 To 2 Step 1
For j = 0 To 2 Step 1
Twod(i, j) = intvalue3
intvalue3 = intvalue3 + 1
Next j
Next i
End Sub
booIn=addem(3,3,Twod)
Private Sub Command1_Click()
Dim strs As String
strs = " "
For i = 0 To 2 Step 1
For j = 0 To 2 Step 1
strs = strs + "," + Str(Twod(i, j))
Next j
Next i
Label1.Caption = strs
End Sub