问题一:
dll中有结构体:
struct score {
int No1;
int No2;
int No3;
char *name;
};int __stdcall GetScore(struct score* score_data) { score_data->No1 = 1000;
score_data->No2 = 2000;
score_data->No3 = 3000;
strcpy(score_data->name,"abcdefghhjjjjkkkkkl");
return (0);
}VB中的结构体定义为:
Private Type score
No1 As Long
No2 As Long
No3 As Long
Name As String
End Type
在DLL中可以修改字符串,但不能超过VB中分配的空间,如何在结构体中定义Name的空间?直接写成"Name As String * 50"程序崩溃,有什么办法解决?问题二:
如何使用CreateObject方法调用DLL,需要哪些步骤呀?给个例子程序.谢谢了!
dll中有结构体:
struct score {
int No1;
int No2;
int No3;
char *name;
};int __stdcall GetScore(struct score* score_data) { score_data->No1 = 1000;
score_data->No2 = 2000;
score_data->No3 = 3000;
strcpy(score_data->name,"abcdefghhjjjjkkkkkl");
return (0);
}VB中的结构体定义为:
Private Type score
No1 As Long
No2 As Long
No3 As Long
Name As String
End Type
在DLL中可以修改字符串,但不能超过VB中分配的空间,如何在结构体中定义Name的空间?直接写成"Name As String * 50"程序崩溃,有什么办法解决?问题二:
如何使用CreateObject方法调用DLL,需要哪些步骤呀?给个例子程序.谢谢了!
No1 As Long
No2 As Long
No3 As Long
Name As String
NameMaxLen as Long '定义一个最大长度,dll中判断是否超出
End Type做成Activex dll可以用CreateObject调用
No1 As Long
No2 As Long
No3 As Long
Name As String
NameMaxLen as Long '定义一个最大长度,dll中判断是否超出
End Type做成Activex dll可以用CreateObject调用
除了定义最大长度还有没有别的什么方法,可不可以动态分配空间的?做成Activex dll?能不能说详细点?
struct score {
int No1;
int No2;
int No3;
BSTR name;
};#include <atlconv.h>int __stdcall GetScore(struct score* score_data) {
USES_CONVERSION;
score_data->No1 = 1000;
score_data->No2 = 2000;
score_data->No3 = 3000;
score_data->name = A2BSTR("abcdefghhjjjjkkkkkl");
return (0);
}
加了#include <atlconv.h>编译不能通过呀,报错如下:
c:\program files\microsoft visual studio\vc98\atl\include\atlconv.h(15) : fatal error C1189: #error : ATL requires C++ compilation (use a .cpp suffix)
struct score {
int No1;
int No2;
int No3;
char name[50];
};在VB中就可以
Private Type score
No1 As Long
No2 As Long
No3 As Long
Name As String * 50
End Type