这是我写的DELPHI的代码
:
:
TYPE TSParam=RECORD
    //DMAon:BOOL;                  // using dma, >>-keshun
    WordAlign:bool;              // using word alignment >>+keshun
    LightOn:bool;                // light on during scanning
    MotorOn:BOOL;                // motor on during scanning
    TestPatternOn:BOOL   ; 
 // using hardware-fix scanning pattern : 0 ... 255
    ScanMode:SHORT ;               // SCAN_xxxxx
    ScanDPI:short;   
// Exposure:array[0..3] of integer; 
// 0 ~ 255     [0=total], [1=R], [2=G],[3=B}
    PaperSource:short  ;            // ATTACH_XXXX
    ImgChannel:short ;             // IMG_CHANNEL_xxxxx
    BWThreshold: BYTE;            // 0 ~ 255
    RegionID:short ;   
   //  0 => means single region (first & last)
                                  
//  -1 means the last region for multiple region
                                    
//  1,2, ...   => n-th region for multiple region
                                   
 //  the first region 0 or 1   => fine tune home && calibrate before 
//csan if needed
                                   
 //  the laset region 0 or -1  => move motor to home after scan (no 
//need to be accurate)
    Left,Top,Right,Bottom:Currency;  // inch
  END;  TYPE TSPost=RECORD
       BwCorrect:BOOLEAN;
       GrayCorrect:BOOL;
       ColorCorrect:BOOL;
       Invert:BOOL;      // 0 : no inverse image 1: inverse image
       HistoEqualize:BOOL;       ToneCorrect:BOOL;
       Brightness:array[0..3] of integer;    
 // -100% ~ 100%    ;[0]=Gray, [1]=R, [2]=G, [3]=B
       Contrast:array[0..3] of integer;      // -100% ~ 100%
       Highlight:array[0..3] of integer;     // -100% ~ 100%
       Gamma:array[0..3] of integer;          // -100% ~ 100%
       Shadow:array[0..3] of integer;          // -100% ~ 100%       FilterID:short;       
  // FILTER_xxxxx   ;FILTER_NONE=0, ...
       HTPatternID:short;    
   // HT_xxxxx
       HTSize:short;            
 // use for user defined HT size
       HTPattern:pchar;//^BYTE;
   // use for user defined HT pattern (just a link)       DarkEdge:BOOL;      
     // Fill the Dark Edge with white (not for preview)
       DeskewAng:double;      
    // unit : deg.  (not for preview)
       BmpFmt:BOOL;
  END;  type TScanParam =record
    Param:TSParam;
    Post:TSPost;
  end;
 :
 : 
 :
FUNCTION SS_ScanInit(var sd_struct:TSCANPARAM;bmpinfo:BITMAPINFOHEADER;linebyte:LONGINT ;forwardscan:BOOLean):BOOLEAN ;cdecl ;external 'sxdrv32.dll';implementation
CONST
//**********
        SCAN_GRAY_RGB= -1;
        SCAN_RGB=0;
        SCAN_GRAY=1;
        SCAN_BW=2;
        SCAN_HT=3;
//**********
        ATTACH_NONE=0;
        ATTACH_ADF=1;
        ATTACH_SLIDE=2;
        ATTACH_NFILM=3;
        ATTACH_A4TRANS=4;
//************
        IMG_CHANNEL_TRUE=0;
        IMG_CHANNEL_RED=1;
        IMG_CHANNEL_GREEN=2;
        IMG_CHANNEL_BLUE=3;
//************{$R *.DFM}procedure TForm1.Button1Click(Sender: TObject);
VAR     SCANPARAM:TSCANPARAM;
    BIH:BITMAPINFOHEADER;
    lLineByte:LONGINT ;
    bret,bForward:BOOLean ;
    I:INTEGER;
BEGIN
//***********
    ScanParam.Param.WordAlign:= TRUE;         
     // using word alignment
    ScanParam.Param.LightOn := TRUE;            
    // light on during scanning
    ScanParam.Param.MotorOn := TRUE;           
     // motor on during scanning
    ScanParam.Param.TestPatternOn:= FALSE;       
   // using hardware-fix scanning pattern : 0 ... 255
    ScanParam.Param.ScanMode:= SCAN_RGB;          
  // SCAN_xxxxx
    ScanParam.Param.ScanDPI := 100;    // setting the exposure, no use for current model
    for i:=0 TO 3 DO
        ScanParam.Param.Exposure[I]:=0;  
          // 0 ~ 255     [0=total], [1=R], [2=G],[3=B}    // setting the attachment, not ready for current model
    ScanParam.Param.PaperSource:= ATTACH_NONE;    // choose the image channel, no use for current model
    ScanParam.Param.ImgChannel:= IMG_CHANNEL_GREEN;
                            // IMG_CHANNEL_xxxxx    // threshold for black/white image
    ScanParam.Param.BWThreshold:= 128;    // setting the region, not use for current model
    ScanParam.Param.RegionID:=0;    // setting the scan area in unit of inch
    ScanParam.Param.Left:=0;
    ScanParam.Param.Top:=0;
    ScanParam.Param.Right:=8.5;
    ScanParam.Param.Bottom:=11.7;    //
    ScanParam.Post.BwCorrect := FALSE;
    ScanParam.Post.GrayCorrect := FALSE;
    ScanParam.Post.ColorCorrect := FALSE;
    ScanParam.Post.Invert := FALSE;
    ScanParam.Post.HistoEqualize:= FALSE;    ScanParam.Post.ToneCorrect := TRUE;
    for i:=0 TO 3 DO
     BEGIN
        ScanParam.Post.Brightness[i]:=0;
                 // -100% ~ 100%    ;
                //[0]=Gray, [1]=R, [2]=G, [3]=B
        ScanParam.Post.Contrast[i]:=0;        // -100% ~ 100%
        ScanParam.Post.Highlight[i]:=0;       // -100% ~ 100%
        ScanParam.Post.Gamma[i]:=0;           // -100% ~ 100%
        ScanParam.Post.Shadow[i]:=0;          // -100% ~ 100%
     END;    ScanParam.Post.FilterID:= 0;
    ScanParam.Post.HTPatternID:=0;       // HT_xxxxx
    ScanParam.Post.HTSize:=0;             // use for user defined HT size
    ScanParam.Post.HTPattern:=nil;       // use for user defined
                                      // HT pattern (just a link)    ScanParam.Post.DarkEdge:= FALSE;  // Fill the Dark Edge with white
                                   // (not for preview)
    ScanParam.Post.DeskewAng:=0;    
      // unit : deg. (not for preview)
    ScanParam.Post.BmpFmt:= TRUE;    //*********
 bRet := SS_ScanInit(ScanParam,BIH,lLineByte,bForward);
END;

解决方案 »

  1.   

    在执行到 bRet := SS_ScanInit(ScanParam,BIH,lLineByte,bForward);
    这行语句时出错。
      

  2.   

    typedef struct Tag_ScanParam
    转换成 Delphi 如下:
    type 
       Tag_ScanParam = packed record
           // 自己写吧,类型对应就行了。
           // ... ...
       end;这涉及到 SizeOf(Tag_ScanParam) 的问题,因为 Tag_ScanParam 分配的变量数据空间是在连续的 SizeOf(Tag_ScanParam) 上。
      

  3.   

    没有来得及仔细看,
    你试试把
    TYPE TSParam=RECORD 之类的
    都改成
    TYPE TSParam=packed RECORD
      

  4.   

    没有来得及仔细看,
    你试试把
    TYPE TSParam=RECORD 之类的
    都改成
    TYPE TSParam=packed RECORD
      

  5.   

    我感觉象是定义类型有错,但不知道那地方错了。这是SS_ScanInit的调用原型
    DLLEXPORT  BOOL    SS_ScanInit(const SScanStruct *sd_struct,BITMAPINFOHEADER *bmpinfo,LONG *linebyte,BOOL *forwardscan);
    这是在C++中调用的语句
     bRet = SS_ScanInit(&ScanParam, &BIH, &lLineByte,&bForward);
    这是在delphi中的定义和调用的语句
    定义
    FUNCTION SS_ScanInit(var sd_struct:TSCANPARAM;bmpinfo:BITMAPINFOHEADER;linebyte:LONGINT ;forwardscan:BOOLean):BOOLEAN ;cdecl ;external 'sxdrv32.dll';
    调用
    bRet := SS_ScanInit(ScanParam,BIH,lLineByte,bForward);
      

  6.   

    请加上 stdcall 标准调用试试。
      

  7.   

    不是因为stdcall的原因,有可能是上面我提到的原因,但我不知道具体
    是哪个变量的类型错了。
      

  8.   

    说得没错,就错在:
    SS_ScanInit(sd_struct: TSCANPARAM;bmpinfo:BITMAPINFOHEADER...);应该写为:
    type 
       PBool = ^BOOL;
       PScanParam = ^TSCANPARAM;
       PBITMAPINFOHEADER = ^BITMAPINFOHEADER;
    function SS_ScanInit(const AScan: PScanParam; ABmp: PBITMAPINFOHEADER; ALine: PInteger; AForward: PBool): BOOL;其他若有问题,可按上述方式改。
      

  9.   

    这个问题好了,又有新的问题了也是出现非法关闭的提示错误。
    C到DELPHI的类型转换太烦人了
    C++的
    DLLEXPORT  short   SS_Scan(BYTE huge *buf,short bufnline); 
        nline=100;
        HGLOBAL hBuf = GlobalAlloc(GMEM_FIXED, lLineByte* nline);
        LPBYTE lpBuf = NULL;
        lpBuf = (LPBYTE)GlobalLock(hBuf);
        SS_Scan(lpBuf, nline)转换成delphi的
    function SS_Scan(var buf: BYTE;bufnline:SmallInt)
    VAR hbuf:HGLOBAL; lpbuf:PBYTE;
    nline=100;
    hBuf := GlobalAlloc(GMEM_FIXED, lLineByte* nline);
    lpBuf := GlobalLock(hBuf);
      

  10.   

    function SS_Scan(buff:pchar;bufnline:SmallInt)
      

  11.   

    请将SS_Scan在DEF中声明输出,在DEPHI中调用时采用静态调用,并加stdcall声明.应可解决退出时出错的问题!
      

  12.   

    请将SS_Scan在*.DEF中声明输出,在DEPHI中调用时采用静态调用,并加stdcall声明.应可解决退出时出错的问题!
      

  13.   

    to zjqyb:
       为什么定义成PCHAR?,在C的定义是PBYTE呀
      

  14.   

    C: PBYTE=BYTE * p
    delphi:pchar=^char=^byte