用VC写了一个DLL,想用struct类型返回多个参数。
在DELPHI调用这个DLL,用一个RECORD作为传出参数。可参数总是不能正确传递。请问是什么原因?
C中声明如下:
typedef struct
{
double f_remain;
char ch_meter[11];
unsigned char u__st;
int i_num;
}*sale_ic;
int test(sale_ic tmp)在DELPHI中声明如下:
function test(var tmp:PSale):integer;stdcall;extern "testdll";
type
PSale=^TSale;
TSale= packed record
f_remain:double;
ch_meter:array[0..10] of char;
u_st:byte;
i_num:integer
end;
在DELPHI调用这个DLL,用一个RECORD作为传出参数。可参数总是不能正确传递。请问是什么原因?
C中声明如下:
typedef struct
{
double f_remain;
char ch_meter[11];
unsigned char u__st;
int i_num;
}*sale_ic;
int test(sale_ic tmp)在DELPHI中声明如下:
function test(var tmp:PSale):integer;stdcall;extern "testdll";
type
PSale=^TSale;
TSale= packed record
f_remain:double;
ch_meter:array[0..10] of char;
u_st:byte;
i_num:integer
end;
解决方案 »
- 求一个SQL语句,ACCESS库
- 如何判断当前登录用户是否属于Adminitrators组?
- Delphi有没有内存块复制函数?
- 我根据SGIP(联通短信协议)编写的短信接口程序,大家观摩多提意见!!
- 讨论:网络数据库的安全性与客户端程序的角色
- 联合查询 类似于excel的自动筛选功能
- 几个关于动态生成控件的问题,请教高手!!分不够再加!!!
- ■■■ .cmb 是什么文件格式? 用什么软件可以打开? ■■■
- 总出错,请问如何用delphi 动态地添加一个worksheet给一个Excel文件
- 那么如何为不同操作员建立功能权限的数据库呢(ACTIONLIST)?可否有例子
- 如何利用程序来控制NAT设备,建立端口映射
- 向曾经使用过delphi5.0的程序员请教
2、你的函数调用方式是否用了 Var (Delphi )和 & (VC)?
而且你在VC中和Delphi中定义的记录各个域的类型是否保证了可取值范围的一致?
type
TSale= record
f_remain:double;
ch_meter:array[0..10] of char;
u_st:byte;
i_num:integer
end;orfunction test(tmp:PSale):integer;stdcall;extern "testdll";
type
PSale=^TSale;
TSale= record
f_remain:double;
ch_meter:array[0..10] of char;
u_st:byte;
i_num:integer
end;
应该是:integer test(sale_ic& tmp)typedef struct
{
double f_remain;
char ch_meter[11];
unsigned char u__st;
int i_num;
}*sale_ic;你应该将sale_ic前边的*去掉。
1、用变量传递参数:
function test(var tmp:TSale):integer;
int test(sale_ic& tmp)
注意此时sale_ic不应该是指针,而是结构,所以前边的*要去掉。
2、用指针:
function test(tmp:PSale):integer;
int test(sale_ic tmp) sale_ic维持现在的定义。