int DLL_DECLARE ReadResult(int * pnResult, double * pRisk, int nNum, int * pnFlag, int nFlagLength, 
   int * pYRange, int nYRangeLength,
   int * pXRange, int nXRangeLength, double * plfAngle);
上面是动态连接库中函数的原型
下面是bcb中的调用 int g_nRecogResult[5], g_nRecogFlag[6];
 int g_nRecogYRange[2], g_nRecogXRange[10];
 double g_lfRecogRisk[5], g_lfRecogAngle;    ReadResult(g_nRecogResult, g_lfRecogRisk, 5,
               g_nRecogFlag, 6,
               g_nRecogYRange, 2,
               g_nRecogXRange, 10,
               &g_lfRecogAngle);现在我想在delphi中调用这个函数,请问函数如何申明?如何调用?

解决方案 »

  1.   

    var
    g_nRecogResult: array [0..4] of integer;
    g_nRecogFlag: array [0..5] of integer;
    g_nRecogYRange: array [0..1] of integer;
    g_nRecogXRange: array [0..9] of integer;
    g_lfRecogRisk: array [0..4] of Double;
    g_lfRecogAngle: Double;    ReadResult(g_nRecogResult, g_lfRecogRisk, 5,
                  g_nRecogFlag, 6,
                  g_nRecogYRange, 2,
                  g_nRecogXRange, 10,
                  @g_lfRecogAngle);
      

  2.   


    在delphi中这个函数怎么申明呢?
      

  3.   

    我是这样申明的
    function ReadResult(var pnResult:array of integer; var pRisk:array of ouble;
                        nNum:LongInt;var pnFlag:array of Integer;nFlagLength:LongInt;
            var pYRange:array of Integer;nYRangeLength:longint;
                        var pXRange:array of integer;nXRangeLength:LongInt;
                        var plfAngle:double):LongInt;stdcall; 
                        external 'Dll.dll' name '_ReadResult@40';调用如下:
    var 
      mY:array[0..1] of Integer;
      mX:array[0..9] of Integer;
      nRisk:array[0..4] of double;
      nRecogResult:array[0..4] of Integer;
      nRecogFlag:array[0..5] of Integer;
      lfAngle:Double;  ReadResult(nRecogResult,nRisk,5,nRecogFlag,6,mY,2,mX,10,lfAngle);可调用是出现这个错误提示,不知道哪有问题?
    Access violation at address 00000000.Read of address 00000000
      

  4.   

    首先你要在  interface 里申明
    var
    ...
    2楼的var
    ...
    function ReadResult(...2楼的函数声明...):integer:Stdcall;
    //然后在
    implementation 
    function ReadResult; External abc.dll{这里写DLL文件名} name 'ReadResult';
    就可以用了
      

  5.   

    這原型與定義的怎麼差這麼遠??一個是整型指針?? 怎麼BCB是這樣整的??
      

  6.   

    声明错了
    procedure (var X: array of Integer); stdcall;
    实际上传了两个参数,相当于
    void __stdcall (int *, int)
    第一个参数是数组首地址,第二个参数是High(X),也就是Length(X)-1
      

  7.   

    把 var 多去掉就可以了
      

  8.   


    int DLL_DECLARE ReadResult(int * pnResult, double * pRisk, int nNum, int * pnFlag, int nFlagLength, 
      int * pYRange, int nYRangeLength, 
      int * pXRange, int nXRangeLength, double * plfAngle); pRisk和plfAngle在声明中有区别么?
    都只传了一个指针,谁说传了多个值的
      

  9.   

    一开始是没有加var 的,发现不行,然后看到这几个参数是传出值的,所以后来加了var
      

  10.   

    但是在BCB中pRisk是传出多个值,所以那里它定义了数组;plfAngle传出一个值。
      

  11.   


    请问starluck:  如果不管BCB是怎么整的,光看原型,在delphi中应该怎么申明和调用啊?谢谢!
      

  12.   

    加不加var传的东西都是一样的怎么这么费劲呢,怎么传它都只传了一个指针,你爱写 var X: Integer/Double 还是 X: PInteger/PDouble 传都可以,反正传的都是一个东西。唯独 var/const/out/(没有) X: array of Integer/Double 不行,因为它会多传一个参数
      

  13.   

    to Seamour :我现在改成这样了function ReadResult(pnResult:pinteger; pRisk:pdouble;nNum:LongInt;pnFlag:pInteger;
                        nFlagLength:LongInt;pYRange:pInteger;nYRangeLength:longint;
                        pXRange:pInteger;nXRangeLength:LongInt;plfAngle:double):LongInt;stdcall; 
                        external 'Dll.dll' name '_ReadResult@40';
    调用:
    var 
      mY:array[0..1] of Integer; 
      mX:array[0..9] of Integer; 
      nRisk:array[0..4] of double; 
      nRecogResult:array[0..4] of Integer; 
      nRecogFlag:array[0..5] of Integer; 
      lfAngle:Double;   ReadResult(@nRecogResult,@nRisk,5,@nRecogFlag,6,@mY,2,@mX,10,lfAngle);运行时,出现这个提示:
    Access violation at address 00481933 in module 'xxx.dll'.Write of address 00000000.
    麻烦你看看哪里还有问题,不好意思,一个小问题给你添麻烦了。
      

  14.   

    plfAngle:double前面是要加上var的
    function ReadResult(pnResult: PInteger;  pRisk: PDouble;  nNum: LongInt;
                        pnFlag: PInteger;  nFlagLength: LongInt;
                        pYRange: PInteger;  nYRangeLength: Longint; 
                        pXRange: PInteger;  nXRangeLength: LongInt; 
                        var plfAngle: Double): LongInt;  stdcall; 
                        external 'Dll.dll' name '_ReadResult@40'; 
      

  15.   

    前面我说加不加var都一样是针对 x: array of T 这种参数形式说的,可能你理解错了……
    var X: Double 和 PX: PDouble 传的东西是一样的。X: array of Double 和 var X: array of Double 传的东西是一样的
      

  16.   


    非常感谢您!问题已经解决了,按照 jadeluo 的提示,把申明改成function ReadResult(pnResult: PInteger;  pRisk: PDouble;  nNum: LongInt;
                        pnFlag: PInteger;  nFlagLength: LongInt;
                        pYRange: PInteger;  nYRangeLength: Longint; 
                        pXRange: PInteger;  nXRangeLength: LongInt; 
                        var plfAngle: Double): LongInt;  stdcall; 
                        external 'Dll.dll' name '_ReadResult@40'; 就可以了。var plfAngle: Double  这里加了var 就通过了。
      

  17.   

    这里还有个函数,下面是原型
    int DLL_DECLARE ProcessMain(int * m_RESULTHIS, int * m_RISKHIS, int * m_FLAGHIS,
    int * m_result,    int*  m_risk, int m_num, 
    int * m_flag, int m_flag_length,
    unsigned char * image, int m_wide,int m_height, 
    int * m_y, int m_lengthy, int * m_x, int m_lengthx, 
    float * m_vangle, unsigned char * m_SHOW);delphi里我是这么申明的procedure ProcessMain(m_RESULTHIS,m_RISKHIS,m_FLAGHIS,m_result,m_risk:pInteger;m_num:LongInt;
                       m_flag:pInteger;m_flag_length:LongInt;image:pchar;
    m_wide,m_height:longint;m_y:pInteger;m_lengthy:LongInt;m_x:pInteger;
    m_lengthx:LongInt;m_vangle:pdouble;var m_SHOW:pchar);Stdcall; external 'Dll.dll' name '_ProcessMain@68';然后这么调用的var
      mResultThis,mRiskThis:array[0..14] of Integer;
      mFlagThis:array[0..5] of Integer;
      mVangle:array[0..3] of Double;
      mY:array[0..1] of Integer;
      mX:array[0..9] of Integer;
      mShow:PChar;
      nRisk:array[0..5] of Integer;
      nRecogResult:array[0..4] of Integer;
      nRecogFlag:array[0..5] of Integer;
      g_ucPicture:pchar;  getmem(g_ucPicture,size);
      getmem(mShow,size);  //这里size足够大的
      
      ProcessMain(@mResultThis,@mRiskThis,@mFlagThis,@nRecogResult,@nRisk,5,@nRecogFlag,6,
    g_ucPicture,PICTURE_WIDTH, PICTURE_HEIGHT,@mY,2,@mX,10,@mVangle,mShow);运行时出现如下提示:
    Access violation at address 0038f10a in module 'xxx.dll'.Read of address fd002cfc.请各位帮我看看问题所在。谢谢各位了。
      

  18.   

    试试我的//declare
    someFunDeclare( pc:pchar );//不要加var
      
    //invoke
     pc:array[0..MaxSize] of char;
    someFun (pc);
      

  19.   


    按照你的改了,还是那个错误提示
    //declare
    procedure ProcessMain(m_RESULTHIS,m_RISKHIS,m_FLAGHIS,m_result,m_risk:pInteger;m_num:LongInt;m_flag:pInteger;m_flag_length:LongInt;image:pchar;m_wide,m_height:longint;
    m_y:pInteger;m_lengthy:LongInt;m_x:pInteger;m_lengthx:LongInt;m_vangle:pdouble;m_SHOW:pchar);Stdcall; external 'RecogDll.dll' name '_ProcessMain@68';//invoke
      g_ucPicture:array[0..size] of char;
      mShow:array[0..size] of char;  ProcessMain(@mResultThis,@mRiskThis,@mFlagThis,@nRecogResult,@nRisk,5,@nRecogFlag,6,g_ucPicture,PICTURE_WIDTH, PICTURE_HEIGHT,@mY,2,@mX,10,@mVangle,mShow);
      

  20.   

    终于搞定了,问题出在float类型转到delphi时要用single,不能double下面是正确的申明和调用
    procedure ProcessMain(m_RESULTHIS,m_RISKHIS,m_FLAGHIS,m_result,m_risk:pInteger;m_num:LongInt; 
                      m_flag:pInteger;m_flag_length:LongInt;image:pchar; 
    m_wide,m_height:longint;m_y:pInteger;m_lengthy:LongInt;m_x:pInteger; 
    m_lengthx:LongInt;m_vangle:psingle;var m_SHOW:pchar);Stdcall; external 'Dll.dll' name '_ProcessMain@68'; 
    var 
      mResultThis,mRiskThis:array[0..14] of Integer; 
      mFlagThis:array[0..5] of Integer; 
      mVangle:array[0..3] of single
      mY:array[0..1] of Integer; 
      mX:array[0..9] of Integer; 
      mShow:PChar; 
      nRisk:array[0..5] of Integer; 
      nRecogResult:array[0..4] of Integer; 
      nRecogFlag:array[0..5] of Integer; 
      g_ucPicture:pchar;   getmem(g_ucPicture,size); 
      getmem(mShow,size);  //这里size足够大的 
      
      ProcessMain(@mResultThis,@mRiskThis,@mFlagThis,@nRecogResult,@nRisk,5,@nRecogFlag,6, 
    g_ucPicture,PICTURE_WIDTH, PICTURE_HEIGHT,@mY,2,@mX,10,@mVangle,mShow); 
    终于可以结贴了,在此谢谢大家的帮助
    特别要感谢的是Seamour、jadeluo