一般的在Dephi中调用VC所编写的DLL,大家讨论的很多了,我在实际使用中也发现确实可用,
但是现在碰到这样一个问题:
VC定义: 
extern "C" __declspec(dllexport) int myfunc( char *str1, char *str2 );
Dephi中调用:
function myfunc( str1 : PChar; str2 : PChar ) : Integer; cdecl; external 'mydll.dll';
....
myfunc( 'hello', 'world' );
....
程序调试,跟踪到VC中,发现str1和str2均为无效指针。但是,如果在两个字符串中间多加一个参数,比如Integer,则没有任何问题,VC中的函数可以正确解析两个字符串。请问,这是什么原因?

解决方案 »

  1.   

    myfunc( 'hello', 'world' );
    有可能是NULL终结符的原因 因为myfunc('hell','world'); 这会被生成临时的字符串 但是这个字符串不清楚是什么样子的 比如NULL终结符之类的
    你这样试试var
      a: array[1..20] of char;
      b: array[1..20] of char;ZeroMemory(a,20);
    ZeroMemory(b,20);
    Move('Hello', a, 5);
    Move('World', b, 5);
    myfunc(a, b); 或者
    myfunc(@a, @b);
    // 在C++中 数组名就是 数组首址
      

  2.   

    sorry. 我对Dephi不太熟悉。
    你上面所说的方法好像编译不通过:Incompatible types: Array and PChar