用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;

解决方案 »

  1.   

    1、你在Delphi中使用了packed record,在VC中如何进行字节对位的?
    2、你的函数调用方式是否用了 Var (Delphi )和 & (VC)?
     
      

  2.   

    VC中若用#pragma pack(1)指定编译,则要用packed 申明Record ,否则不要.
      

  3.   

    #pragma pack(1)和packed 我都用过,可不行,真是奇怪啊
      

  4.   

    和是否是Packed Record没有关系吧为什么不换成一个指向记录的指针呢?
      

  5.   

    Sorry,没有看清楚,是指针!另外Dll函数使用变参后,被传递形参的内容一般是要发生改变的
    而且你在VC中和Delphi中定义的记录各个域的类型是否保证了可取值范围的一致?
      

  6.   

    function test(var tmp: TSale):integer;stdcall;extern "testdll";
    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;
      

  7.   

    请将VC 的function test(var tmp:PSale):integer;stdcall;extern "testdll"; 贴出来,
    应该是: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前边的*去掉。
      

  8.   

    修改的方法有两个,取决与你是用变量传递参数(Delphi Var 对应 VC &),还是用指针(Delphi @ 对应 VC *):
    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维持现在的定义。
      

  9.   

    你原来说明的function test(var tmp:PSale):integer;中PSale是个指针,用Var参数传递凡是时,实际上是直接将tmp这个变量传给test函数,而在函数中,只要出现tmp这个变量,就是对原来的tmp的直接操作,如果有tmp==或类似的语句,则tmp原来的值就被破坏了。因此,如果用指针方式,就不要在用Var。