FrontSealcard,BackSealcard这字符指针式两个jpg文件;flen,blen表示二进制文件的长度。
说明:
c++builder的实现方式是:利用stdio中的fopen函数,通过‘rb’只读二进制方式读取,通过fread( Bbuf, 1, sizeB, fpB )赋值给动态byte数组。然后动态byte数组直接传递给FrontSealcard或者BackSealcard字符指针。这个方法,返回值是0,是正确。
delphi实现方式是:利用TFileStream(其实内存流、文件读取我都试过了),TFileStream.ReadBuffer(Bbuf[0],sizeB)赋值给Bbuf动态byte数组。不一样的情况出现了,我直接把动态数组Bbuf传递给FrontSealcard或者BackSealcard字符指针,编译器报错。我进行转换为ppF := PChar(Fbuf);然后程序返回值永远不正常。
我试验过了多种读取jpg文件的方式,也尝试了多种转换方式。始终得不到正确的返回值。
我想问问大家,有没有什么建议。我现在真的没有招儿了。
8 个解决方案
#1
代码放上来
#2
stdio中的fopen
对应delphi的好像是
open还是openfile还是fileopen
对应delphi的好像是
open还是openfile还是fileopen
#3
传pchar类型,而且你传入 byte数组,byte和char的取值范围都不一样
#4
dll函数:
typedef long (__stdcall *AddSealCard_Type)(char * FrontSealcard, int flen, char * BackSealcard, int blen);
struct stat statbuf;
int sizeF, sizeB;
FILE *fpF, *fpB;
byte *Fbuf, *Bbuf;
AnsiString fileNameF,fileNameB;
Fbuf=new byte[1000000];
Bbuf=new byte[1000000];
try{ fpF=fopen(fileNameF.c_str(),"rb" );//打开方向检查数据文件 if(fpF) { // throw Exception("打开印鉴卡正面文件错误 "); fstat(fileno(fpF), &statbuf); sizeF= statbuf.st_size; fread( Fbuf, 1, sizeF, fpF ); //装入方向检查数据 fclose( fpF ); //fpF=Null; } fpB=fopen(fileNameB.c_str(),"rb" );//打开方向检查数据文件 if(fpB) { // throw Exception("打开印鉴卡正面文件错误 "); fstat(fileno(fpB), &statbuf); sizeB= statbuf.st_size; fread( Bbuf, 1, sizeB, fpB ); //装入方向检查数据 fclose( fpB ); //fpB=Null; } re = m_AddSealCard(Fbuf,sizeF,Bbuf,sizeB); // fpF=Null; fpB=Null;
typedef long (__stdcall *AddSealCard_Type)(char * FrontSealcard, int flen, char * BackSealcard, int blen);
struct stat statbuf;
int sizeF, sizeB;
FILE *fpF, *fpB;
byte *Fbuf, *Bbuf;
AnsiString fileNameF,fileNameB;
Fbuf=new byte[1000000];
Bbuf=new byte[1000000];
try{ fpF=fopen(fileNameF.c_str(),"rb" );//打开方向检查数据文件 if(fpF) { // throw Exception("打开印鉴卡正面文件错误 "); fstat(fileno(fpF), &statbuf); sizeF= statbuf.st_size; fread( Fbuf, 1, sizeF, fpF ); //装入方向检查数据 fclose( fpF ); //fpF=Null; } fpB=fopen(fileNameB.c_str(),"rb" );//打开方向检查数据文件 if(fpB) { // throw Exception("打开印鉴卡正面文件错误 "); fstat(fileno(fpB), &statbuf); sizeB= statbuf.st_size; fread( Bbuf, 1, sizeB, fpB ); //装入方向检查数据 fclose( fpB ); //fpB=Null; } re = m_AddSealCard(Fbuf,sizeF,Bbuf,sizeB); // fpF=Null; fpB=Null;
#5
上面的c++builder是可以通过的。是能够从dll的函数里返回正确值的。
下面的delphi的
dll函数定义:
AddSealCard_Type = function(FrontSealcard: PChar; flen: Integer; BackSealcard: PChar; blen: Integer): DWORD;stdcall;
到re返回值部分我就没有拷贝了。我写了好多种读取方法,发现文件大小,甚至读取的二进制文件前面都是一样的,就是返回值失败。
var picFileNames,oldStr,newStr,fileNameF,fileNameB,sealPath,sealDataFile,sealBMPFile: string; picNameList,sealIndex: TStringList; sizeF, sizeB,Cardnum, SealNum,re,len_b,n,t,f,numread,i: Integer; Fbuf, Bbuf: array of Byte; // Fbuf, Bbuf: array of Char; FF,FB: file; // Fbuf, Bbuf: ^Byte; fpF, fpB: TMemoryStream; ffpF,ffpB: TFileStream; ppF,ppB: PChar; seali: Seal_Info; b: Boolean; ww: Byte; begin //---- Place thread code here ---- proBar.Max := sgInfo.RowCount -1; proBar.Position := 0; oldStr := ';'; newStr := ','; picNameList := TStringList.Create; sealIndex := TStringList.Create; try //struct stat statbuf; for n := 0 to sgInfo.RowCount-1 do begin b := False; m_Clear(); // Sleep(1000); picFileNames := sgInfo.Cells[2,n+1]; sgInfo.Cells[2,n+1] := StringReplace(picFileNames,oldStr,newStr,[rfReplaceAll]); picNameList.Clear(); picNameList.CommaText := sgInfo.Cells[2,n+1]; if (picNameList.Count = 0) then begin sgInfo.Cells[3,n+1] := '状态不过-对应的图像文件'; continue; end; // 开始装载图像 b := false; for t:=0 to picNameList.Count-1 do begin fileNameF := edtCardPath.Text + '\' + picNameList.Strings[t] + 'F.jpg'; fileNameB := edtCardPath.Text + '\' + picNameList.Strings[t] + 'B.jpg'; if ((not (FileExists(fileNameF))) or (not(FileExists(fileNameB)))) then begin sgInfo.Cells[3,n+1] := '状态不过-未发现' + picNameList.Strings[t] + '对应的图像文件'; b := True; Break; end; // SetLength(Fbuf,1000000); // SetLength(Bbuf,1000000); // GetMem(Fbuf, SizeOf(Byte)*1000000); // GetMem(Bbuf, SizeOf(Byte)*1000000); try try //内存流读取 // fpF := TMemoryStream.Create; // fpF.LoadFromFile(fileNameF); // fpF.Position := 0; // if fpF <> nil then // throw Exception("打开印鉴卡正面文件错误 "); // begin // sizeF := fpF.Size; //// SetLength(Fbuf,sizeF); // fpF.Read(Fbuf[0],sizeF); // fpF.Free; // end; // fpB := TMemoryStream.Create;//打开方向检查数据文件 // fpB.LoadFromFile(fileNameB); // fpB.Position := 0; // if fpB <> nil then // throw Exception("打开印鉴卡正面文件错误 "); // begin // sizeB := fpB.Size; //// SetLength(Bbuf,sizeB); // fpB.Read(Bbuf[0],sizeB); // fpB.Free; // end; // 文件读取 AssignFile(FF,fileNameF); FileMode := 0; Reset(FF); sizeF := FileSize(FF); SetLength(Fbuf,1000000); // FillChar(Fbuf, 1000000, Byte('')); numread := 1; BlockRead(FF,Fbuf[0],sizeF,numread); // i :=0; // repeat // BlockRead(FF,Fbuf[i],1,numread); // Inc(i); // until (NumRead = 0); CloseFile(FF); AssignFile(FB,fileNameB); FileMode := 0; Reset(FB); sizeB := FileSize(FB); SetLength(bbuf,1000000); // FillChar(bbuf, 1000000, Byte('')); BlockRead(FB,Bbuf[0],sizeB,numread); CloseFile(FB); // ppF := PChar(Fbuf); // ppB := PChar(Bbuf); //文件流读取 byte // ffpF := TFileStream.Create(fileNameF,fmOpenRead); // ffpF.Position := 0; // sizeF := ffpF.Size; // SetLength(Fbuf,sizeF); // ffpF.ReadBuffer(Fbuf[0],sizeF); // ffpF.Free; // // ffpB := TFileStream.Create(fileNameB,fmOpenRead); // ffpB.Position := 0; // sizeB := ffpB.Size; // SetLength(bbuf,sizeB); // ffpB.ReadBuffer(Bbuf[0],sizeB); // ffpB.Free; // ppF := PChar(Fbuf); // ppB := PChar(Bbuf); //文件流读取 char // ffpF := TFileStream.Create(fileNameF,fmOpenRead); // ffpF.Position := 0; // sizeF := ffpF.Size; // SetLength(Fbuf,sizeF); // ffpF.ReadBuffer(Fbuf[0],sizeF); // ffpF.Free; // // ffpB := TFileStream.Create(fileNameB,fmOpenRead); // ffpB.Position := 0; // sizeB := ffpB.Size; // SetLength(bbuf,sizeB); // ffpB.ReadBuffer(Bbuf[0],sizeB); // ffpB.Free; // ppF := @Fbuf; // ppB := @Bbuf; // ppF := @Fbuf; // ppB := @Bbuf; // Fbuf[sizeF] := Byte($00); // bbuf[sizeB] := Byte($00); // Move(Fbuf,ppF,sizeF); // Move(Bbuf,ppB,sizeB); re := m_AddSealCard(@Fbuf,sizeF,@Bbuf,sizeB); // fpF=Null; fpB=Null;
下面的delphi的
dll函数定义:
AddSealCard_Type = function(FrontSealcard: PChar; flen: Integer; BackSealcard: PChar; blen: Integer): DWORD;stdcall;
到re返回值部分我就没有拷贝了。我写了好多种读取方法,发现文件大小,甚至读取的二进制文件前面都是一样的,就是返回值失败。
var picFileNames,oldStr,newStr,fileNameF,fileNameB,sealPath,sealDataFile,sealBMPFile: string; picNameList,sealIndex: TStringList; sizeF, sizeB,Cardnum, SealNum,re,len_b,n,t,f,numread,i: Integer; Fbuf, Bbuf: array of Byte; // Fbuf, Bbuf: array of Char; FF,FB: file; // Fbuf, Bbuf: ^Byte; fpF, fpB: TMemoryStream; ffpF,ffpB: TFileStream; ppF,ppB: PChar; seali: Seal_Info; b: Boolean; ww: Byte; begin //---- Place thread code here ---- proBar.Max := sgInfo.RowCount -1; proBar.Position := 0; oldStr := ';'; newStr := ','; picNameList := TStringList.Create; sealIndex := TStringList.Create; try //struct stat statbuf; for n := 0 to sgInfo.RowCount-1 do begin b := False; m_Clear(); // Sleep(1000); picFileNames := sgInfo.Cells[2,n+1]; sgInfo.Cells[2,n+1] := StringReplace(picFileNames,oldStr,newStr,[rfReplaceAll]); picNameList.Clear(); picNameList.CommaText := sgInfo.Cells[2,n+1]; if (picNameList.Count = 0) then begin sgInfo.Cells[3,n+1] := '状态不过-对应的图像文件'; continue; end; // 开始装载图像 b := false; for t:=0 to picNameList.Count-1 do begin fileNameF := edtCardPath.Text + '\' + picNameList.Strings[t] + 'F.jpg'; fileNameB := edtCardPath.Text + '\' + picNameList.Strings[t] + 'B.jpg'; if ((not (FileExists(fileNameF))) or (not(FileExists(fileNameB)))) then begin sgInfo.Cells[3,n+1] := '状态不过-未发现' + picNameList.Strings[t] + '对应的图像文件'; b := True; Break; end; // SetLength(Fbuf,1000000); // SetLength(Bbuf,1000000); // GetMem(Fbuf, SizeOf(Byte)*1000000); // GetMem(Bbuf, SizeOf(Byte)*1000000); try try //内存流读取 // fpF := TMemoryStream.Create; // fpF.LoadFromFile(fileNameF); // fpF.Position := 0; // if fpF <> nil then // throw Exception("打开印鉴卡正面文件错误 "); // begin // sizeF := fpF.Size; //// SetLength(Fbuf,sizeF); // fpF.Read(Fbuf[0],sizeF); // fpF.Free; // end; // fpB := TMemoryStream.Create;//打开方向检查数据文件 // fpB.LoadFromFile(fileNameB); // fpB.Position := 0; // if fpB <> nil then // throw Exception("打开印鉴卡正面文件错误 "); // begin // sizeB := fpB.Size; //// SetLength(Bbuf,sizeB); // fpB.Read(Bbuf[0],sizeB); // fpB.Free; // end; // 文件读取 AssignFile(FF,fileNameF); FileMode := 0; Reset(FF); sizeF := FileSize(FF); SetLength(Fbuf,1000000); // FillChar(Fbuf, 1000000, Byte('')); numread := 1; BlockRead(FF,Fbuf[0],sizeF,numread); // i :=0; // repeat // BlockRead(FF,Fbuf[i],1,numread); // Inc(i); // until (NumRead = 0); CloseFile(FF); AssignFile(FB,fileNameB); FileMode := 0; Reset(FB); sizeB := FileSize(FB); SetLength(bbuf,1000000); // FillChar(bbuf, 1000000, Byte('')); BlockRead(FB,Bbuf[0],sizeB,numread); CloseFile(FB); // ppF := PChar(Fbuf); // ppB := PChar(Bbuf); //文件流读取 byte // ffpF := TFileStream.Create(fileNameF,fmOpenRead); // ffpF.Position := 0; // sizeF := ffpF.Size; // SetLength(Fbuf,sizeF); // ffpF.ReadBuffer(Fbuf[0],sizeF); // ffpF.Free; // // ffpB := TFileStream.Create(fileNameB,fmOpenRead); // ffpB.Position := 0; // sizeB := ffpB.Size; // SetLength(bbuf,sizeB); // ffpB.ReadBuffer(Bbuf[0],sizeB); // ffpB.Free; // ppF := PChar(Fbuf); // ppB := PChar(Bbuf); //文件流读取 char // ffpF := TFileStream.Create(fileNameF,fmOpenRead); // ffpF.Position := 0; // sizeF := ffpF.Size; // SetLength(Fbuf,sizeF); // ffpF.ReadBuffer(Fbuf[0],sizeF); // ffpF.Free; // // ffpB := TFileStream.Create(fileNameB,fmOpenRead); // ffpB.Position := 0; // sizeB := ffpB.Size; // SetLength(bbuf,sizeB); // ffpB.ReadBuffer(Bbuf[0],sizeB); // ffpB.Free; // ppF := @Fbuf; // ppB := @Bbuf; // ppF := @Fbuf; // ppB := @Bbuf; // Fbuf[sizeF] := Byte($00); // bbuf[sizeB] := Byte($00); // Move(Fbuf,ppF,sizeF); // Move(Bbuf,ppB,sizeB); re := m_AddSealCard(@Fbuf,sizeF,@Bbuf,sizeB); // fpF=Null; fpB=Null;
#6
var
fileNameF,fileNameB,sealPath,sealDataFile,sealBMPFile: string;
sizeF, sizeB,Cardnum, SealNum,re,len_b,n,t,f,numread,i: Integer;
Fbuf, Bbuf: array of Byte;
FF,FB: file;
ppF,ppB: PChar;
seali: Seal_Info;
b: Boolean;
begin
AssignFile(FF,fileNameF);
FileMode := 0;
Reset(FF);
sizeF := FileSize(FF);
SetLength(Fbuf,1000000);
numread := 1;
BlockRead(FF,Fbuf[0],sizeF,numread);
CloseFile(FF);
AssignFile(FB,fileNameB);
FileMode := 0;
Reset(FB);
sizeB := FileSize(FB);
SetLength(bbuf,1000000);
BlockRead(FB,Bbuf[0],sizeB,numread);
CloseFile(FB);
re := m_AddSealCard(@Fbuf,sizeF,@Bbuf,sizeB); //返回值不正确
fileNameF,fileNameB,sealPath,sealDataFile,sealBMPFile: string;
sizeF, sizeB,Cardnum, SealNum,re,len_b,n,t,f,numread,i: Integer;
Fbuf, Bbuf: array of Byte;
FF,FB: file;
ppF,ppB: PChar;
seali: Seal_Info;
b: Boolean;
begin
AssignFile(FF,fileNameF);
FileMode := 0;
Reset(FF);
sizeF := FileSize(FF);
SetLength(Fbuf,1000000);
numread := 1;
BlockRead(FF,Fbuf[0],sizeF,numread);
CloseFile(FF);
AssignFile(FB,fileNameB);
FileMode := 0;
Reset(FB);
sizeB := FileSize(FB);
SetLength(bbuf,1000000);
BlockRead(FB,Bbuf[0],sizeB,numread);
CloseFile(FB);
re := m_AddSealCard(@Fbuf,sizeF,@Bbuf,sizeB); //返回值不正确
#7
用PByte,试试这样:
function AddSealCard_Type(FrontSealcard: PByte; flen: Integer; BackSealcard: PByte; blen: Integer): DWORD;stdcall;
var
Fbuf, Bbuf: array of PByte;
begin
SetLength(Fbuf,1000000);
SetLength(Bbuf,1000000);
re := m_AddSealCard(Fbuf,sizeF,Bbuf,sizeB);
function AddSealCard_Type(FrontSealcard: PByte; flen: Integer; BackSealcard: PByte; blen: Integer): DWORD;stdcall;
var
Fbuf, Bbuf: array of PByte;
begin
SetLength(Fbuf,1000000);
SetLength(Bbuf,1000000);
re := m_AddSealCard(Fbuf,sizeF,Bbuf,sizeB);
#8
不行。我试过了
#1
代码放上来
#2
stdio中的fopen
对应delphi的好像是
open还是openfile还是fileopen
对应delphi的好像是
open还是openfile还是fileopen
#3
传pchar类型,而且你传入 byte数组,byte和char的取值范围都不一样
#4
dll函数:
typedef long (__stdcall *AddSealCard_Type)(char * FrontSealcard, int flen, char * BackSealcard, int blen);
struct stat statbuf;
int sizeF, sizeB;
FILE *fpF, *fpB;
byte *Fbuf, *Bbuf;
AnsiString fileNameF,fileNameB;
Fbuf=new byte[1000000];
Bbuf=new byte[1000000];
try{ fpF=fopen(fileNameF.c_str(),"rb" );//打开方向检查数据文件 if(fpF) { // throw Exception("打开印鉴卡正面文件错误 "); fstat(fileno(fpF), &statbuf); sizeF= statbuf.st_size; fread( Fbuf, 1, sizeF, fpF ); //装入方向检查数据 fclose( fpF ); //fpF=Null; } fpB=fopen(fileNameB.c_str(),"rb" );//打开方向检查数据文件 if(fpB) { // throw Exception("打开印鉴卡正面文件错误 "); fstat(fileno(fpB), &statbuf); sizeB= statbuf.st_size; fread( Bbuf, 1, sizeB, fpB ); //装入方向检查数据 fclose( fpB ); //fpB=Null; } re = m_AddSealCard(Fbuf,sizeF,Bbuf,sizeB); // fpF=Null; fpB=Null;
typedef long (__stdcall *AddSealCard_Type)(char * FrontSealcard, int flen, char * BackSealcard, int blen);
struct stat statbuf;
int sizeF, sizeB;
FILE *fpF, *fpB;
byte *Fbuf, *Bbuf;
AnsiString fileNameF,fileNameB;
Fbuf=new byte[1000000];
Bbuf=new byte[1000000];
try{ fpF=fopen(fileNameF.c_str(),"rb" );//打开方向检查数据文件 if(fpF) { // throw Exception("打开印鉴卡正面文件错误 "); fstat(fileno(fpF), &statbuf); sizeF= statbuf.st_size; fread( Fbuf, 1, sizeF, fpF ); //装入方向检查数据 fclose( fpF ); //fpF=Null; } fpB=fopen(fileNameB.c_str(),"rb" );//打开方向检查数据文件 if(fpB) { // throw Exception("打开印鉴卡正面文件错误 "); fstat(fileno(fpB), &statbuf); sizeB= statbuf.st_size; fread( Bbuf, 1, sizeB, fpB ); //装入方向检查数据 fclose( fpB ); //fpB=Null; } re = m_AddSealCard(Fbuf,sizeF,Bbuf,sizeB); // fpF=Null; fpB=Null;
#5
上面的c++builder是可以通过的。是能够从dll的函数里返回正确值的。
下面的delphi的
dll函数定义:
AddSealCard_Type = function(FrontSealcard: PChar; flen: Integer; BackSealcard: PChar; blen: Integer): DWORD;stdcall;
到re返回值部分我就没有拷贝了。我写了好多种读取方法,发现文件大小,甚至读取的二进制文件前面都是一样的,就是返回值失败。
var picFileNames,oldStr,newStr,fileNameF,fileNameB,sealPath,sealDataFile,sealBMPFile: string; picNameList,sealIndex: TStringList; sizeF, sizeB,Cardnum, SealNum,re,len_b,n,t,f,numread,i: Integer; Fbuf, Bbuf: array of Byte; // Fbuf, Bbuf: array of Char; FF,FB: file; // Fbuf, Bbuf: ^Byte; fpF, fpB: TMemoryStream; ffpF,ffpB: TFileStream; ppF,ppB: PChar; seali: Seal_Info; b: Boolean; ww: Byte; begin //---- Place thread code here ---- proBar.Max := sgInfo.RowCount -1; proBar.Position := 0; oldStr := ';'; newStr := ','; picNameList := TStringList.Create; sealIndex := TStringList.Create; try //struct stat statbuf; for n := 0 to sgInfo.RowCount-1 do begin b := False; m_Clear(); // Sleep(1000); picFileNames := sgInfo.Cells[2,n+1]; sgInfo.Cells[2,n+1] := StringReplace(picFileNames,oldStr,newStr,[rfReplaceAll]); picNameList.Clear(); picNameList.CommaText := sgInfo.Cells[2,n+1]; if (picNameList.Count = 0) then begin sgInfo.Cells[3,n+1] := '状态不过-对应的图像文件'; continue; end; // 开始装载图像 b := false; for t:=0 to picNameList.Count-1 do begin fileNameF := edtCardPath.Text + '\' + picNameList.Strings[t] + 'F.jpg'; fileNameB := edtCardPath.Text + '\' + picNameList.Strings[t] + 'B.jpg'; if ((not (FileExists(fileNameF))) or (not(FileExists(fileNameB)))) then begin sgInfo.Cells[3,n+1] := '状态不过-未发现' + picNameList.Strings[t] + '对应的图像文件'; b := True; Break; end; // SetLength(Fbuf,1000000); // SetLength(Bbuf,1000000); // GetMem(Fbuf, SizeOf(Byte)*1000000); // GetMem(Bbuf, SizeOf(Byte)*1000000); try try //内存流读取 // fpF := TMemoryStream.Create; // fpF.LoadFromFile(fileNameF); // fpF.Position := 0; // if fpF <> nil then // throw Exception("打开印鉴卡正面文件错误 "); // begin // sizeF := fpF.Size; //// SetLength(Fbuf,sizeF); // fpF.Read(Fbuf[0],sizeF); // fpF.Free; // end; // fpB := TMemoryStream.Create;//打开方向检查数据文件 // fpB.LoadFromFile(fileNameB); // fpB.Position := 0; // if fpB <> nil then // throw Exception("打开印鉴卡正面文件错误 "); // begin // sizeB := fpB.Size; //// SetLength(Bbuf,sizeB); // fpB.Read(Bbuf[0],sizeB); // fpB.Free; // end; // 文件读取 AssignFile(FF,fileNameF); FileMode := 0; Reset(FF); sizeF := FileSize(FF); SetLength(Fbuf,1000000); // FillChar(Fbuf, 1000000, Byte('')); numread := 1; BlockRead(FF,Fbuf[0],sizeF,numread); // i :=0; // repeat // BlockRead(FF,Fbuf[i],1,numread); // Inc(i); // until (NumRead = 0); CloseFile(FF); AssignFile(FB,fileNameB); FileMode := 0; Reset(FB); sizeB := FileSize(FB); SetLength(bbuf,1000000); // FillChar(bbuf, 1000000, Byte('')); BlockRead(FB,Bbuf[0],sizeB,numread); CloseFile(FB); // ppF := PChar(Fbuf); // ppB := PChar(Bbuf); //文件流读取 byte // ffpF := TFileStream.Create(fileNameF,fmOpenRead); // ffpF.Position := 0; // sizeF := ffpF.Size; // SetLength(Fbuf,sizeF); // ffpF.ReadBuffer(Fbuf[0],sizeF); // ffpF.Free; // // ffpB := TFileStream.Create(fileNameB,fmOpenRead); // ffpB.Position := 0; // sizeB := ffpB.Size; // SetLength(bbuf,sizeB); // ffpB.ReadBuffer(Bbuf[0],sizeB); // ffpB.Free; // ppF := PChar(Fbuf); // ppB := PChar(Bbuf); //文件流读取 char // ffpF := TFileStream.Create(fileNameF,fmOpenRead); // ffpF.Position := 0; // sizeF := ffpF.Size; // SetLength(Fbuf,sizeF); // ffpF.ReadBuffer(Fbuf[0],sizeF); // ffpF.Free; // // ffpB := TFileStream.Create(fileNameB,fmOpenRead); // ffpB.Position := 0; // sizeB := ffpB.Size; // SetLength(bbuf,sizeB); // ffpB.ReadBuffer(Bbuf[0],sizeB); // ffpB.Free; // ppF := @Fbuf; // ppB := @Bbuf; // ppF := @Fbuf; // ppB := @Bbuf; // Fbuf[sizeF] := Byte($00); // bbuf[sizeB] := Byte($00); // Move(Fbuf,ppF,sizeF); // Move(Bbuf,ppB,sizeB); re := m_AddSealCard(@Fbuf,sizeF,@Bbuf,sizeB); // fpF=Null; fpB=Null;
下面的delphi的
dll函数定义:
AddSealCard_Type = function(FrontSealcard: PChar; flen: Integer; BackSealcard: PChar; blen: Integer): DWORD;stdcall;
到re返回值部分我就没有拷贝了。我写了好多种读取方法,发现文件大小,甚至读取的二进制文件前面都是一样的,就是返回值失败。
var picFileNames,oldStr,newStr,fileNameF,fileNameB,sealPath,sealDataFile,sealBMPFile: string; picNameList,sealIndex: TStringList; sizeF, sizeB,Cardnum, SealNum,re,len_b,n,t,f,numread,i: Integer; Fbuf, Bbuf: array of Byte; // Fbuf, Bbuf: array of Char; FF,FB: file; // Fbuf, Bbuf: ^Byte; fpF, fpB: TMemoryStream; ffpF,ffpB: TFileStream; ppF,ppB: PChar; seali: Seal_Info; b: Boolean; ww: Byte; begin //---- Place thread code here ---- proBar.Max := sgInfo.RowCount -1; proBar.Position := 0; oldStr := ';'; newStr := ','; picNameList := TStringList.Create; sealIndex := TStringList.Create; try //struct stat statbuf; for n := 0 to sgInfo.RowCount-1 do begin b := False; m_Clear(); // Sleep(1000); picFileNames := sgInfo.Cells[2,n+1]; sgInfo.Cells[2,n+1] := StringReplace(picFileNames,oldStr,newStr,[rfReplaceAll]); picNameList.Clear(); picNameList.CommaText := sgInfo.Cells[2,n+1]; if (picNameList.Count = 0) then begin sgInfo.Cells[3,n+1] := '状态不过-对应的图像文件'; continue; end; // 开始装载图像 b := false; for t:=0 to picNameList.Count-1 do begin fileNameF := edtCardPath.Text + '\' + picNameList.Strings[t] + 'F.jpg'; fileNameB := edtCardPath.Text + '\' + picNameList.Strings[t] + 'B.jpg'; if ((not (FileExists(fileNameF))) or (not(FileExists(fileNameB)))) then begin sgInfo.Cells[3,n+1] := '状态不过-未发现' + picNameList.Strings[t] + '对应的图像文件'; b := True; Break; end; // SetLength(Fbuf,1000000); // SetLength(Bbuf,1000000); // GetMem(Fbuf, SizeOf(Byte)*1000000); // GetMem(Bbuf, SizeOf(Byte)*1000000); try try //内存流读取 // fpF := TMemoryStream.Create; // fpF.LoadFromFile(fileNameF); // fpF.Position := 0; // if fpF <> nil then // throw Exception("打开印鉴卡正面文件错误 "); // begin // sizeF := fpF.Size; //// SetLength(Fbuf,sizeF); // fpF.Read(Fbuf[0],sizeF); // fpF.Free; // end; // fpB := TMemoryStream.Create;//打开方向检查数据文件 // fpB.LoadFromFile(fileNameB); // fpB.Position := 0; // if fpB <> nil then // throw Exception("打开印鉴卡正面文件错误 "); // begin // sizeB := fpB.Size; //// SetLength(Bbuf,sizeB); // fpB.Read(Bbuf[0],sizeB); // fpB.Free; // end; // 文件读取 AssignFile(FF,fileNameF); FileMode := 0; Reset(FF); sizeF := FileSize(FF); SetLength(Fbuf,1000000); // FillChar(Fbuf, 1000000, Byte('')); numread := 1; BlockRead(FF,Fbuf[0],sizeF,numread); // i :=0; // repeat // BlockRead(FF,Fbuf[i],1,numread); // Inc(i); // until (NumRead = 0); CloseFile(FF); AssignFile(FB,fileNameB); FileMode := 0; Reset(FB); sizeB := FileSize(FB); SetLength(bbuf,1000000); // FillChar(bbuf, 1000000, Byte('')); BlockRead(FB,Bbuf[0],sizeB,numread); CloseFile(FB); // ppF := PChar(Fbuf); // ppB := PChar(Bbuf); //文件流读取 byte // ffpF := TFileStream.Create(fileNameF,fmOpenRead); // ffpF.Position := 0; // sizeF := ffpF.Size; // SetLength(Fbuf,sizeF); // ffpF.ReadBuffer(Fbuf[0],sizeF); // ffpF.Free; // // ffpB := TFileStream.Create(fileNameB,fmOpenRead); // ffpB.Position := 0; // sizeB := ffpB.Size; // SetLength(bbuf,sizeB); // ffpB.ReadBuffer(Bbuf[0],sizeB); // ffpB.Free; // ppF := PChar(Fbuf); // ppB := PChar(Bbuf); //文件流读取 char // ffpF := TFileStream.Create(fileNameF,fmOpenRead); // ffpF.Position := 0; // sizeF := ffpF.Size; // SetLength(Fbuf,sizeF); // ffpF.ReadBuffer(Fbuf[0],sizeF); // ffpF.Free; // // ffpB := TFileStream.Create(fileNameB,fmOpenRead); // ffpB.Position := 0; // sizeB := ffpB.Size; // SetLength(bbuf,sizeB); // ffpB.ReadBuffer(Bbuf[0],sizeB); // ffpB.Free; // ppF := @Fbuf; // ppB := @Bbuf; // ppF := @Fbuf; // ppB := @Bbuf; // Fbuf[sizeF] := Byte($00); // bbuf[sizeB] := Byte($00); // Move(Fbuf,ppF,sizeF); // Move(Bbuf,ppB,sizeB); re := m_AddSealCard(@Fbuf,sizeF,@Bbuf,sizeB); // fpF=Null; fpB=Null;
#6
var
fileNameF,fileNameB,sealPath,sealDataFile,sealBMPFile: string;
sizeF, sizeB,Cardnum, SealNum,re,len_b,n,t,f,numread,i: Integer;
Fbuf, Bbuf: array of Byte;
FF,FB: file;
ppF,ppB: PChar;
seali: Seal_Info;
b: Boolean;
begin
AssignFile(FF,fileNameF);
FileMode := 0;
Reset(FF);
sizeF := FileSize(FF);
SetLength(Fbuf,1000000);
numread := 1;
BlockRead(FF,Fbuf[0],sizeF,numread);
CloseFile(FF);
AssignFile(FB,fileNameB);
FileMode := 0;
Reset(FB);
sizeB := FileSize(FB);
SetLength(bbuf,1000000);
BlockRead(FB,Bbuf[0],sizeB,numread);
CloseFile(FB);
re := m_AddSealCard(@Fbuf,sizeF,@Bbuf,sizeB); //返回值不正确
fileNameF,fileNameB,sealPath,sealDataFile,sealBMPFile: string;
sizeF, sizeB,Cardnum, SealNum,re,len_b,n,t,f,numread,i: Integer;
Fbuf, Bbuf: array of Byte;
FF,FB: file;
ppF,ppB: PChar;
seali: Seal_Info;
b: Boolean;
begin
AssignFile(FF,fileNameF);
FileMode := 0;
Reset(FF);
sizeF := FileSize(FF);
SetLength(Fbuf,1000000);
numread := 1;
BlockRead(FF,Fbuf[0],sizeF,numread);
CloseFile(FF);
AssignFile(FB,fileNameB);
FileMode := 0;
Reset(FB);
sizeB := FileSize(FB);
SetLength(bbuf,1000000);
BlockRead(FB,Bbuf[0],sizeB,numread);
CloseFile(FB);
re := m_AddSealCard(@Fbuf,sizeF,@Bbuf,sizeB); //返回值不正确
#7
用PByte,试试这样:
function AddSealCard_Type(FrontSealcard: PByte; flen: Integer; BackSealcard: PByte; blen: Integer): DWORD;stdcall;
var
Fbuf, Bbuf: array of PByte;
begin
SetLength(Fbuf,1000000);
SetLength(Bbuf,1000000);
re := m_AddSealCard(Fbuf,sizeF,Bbuf,sizeB);
function AddSealCard_Type(FrontSealcard: PByte; flen: Integer; BackSealcard: PByte; blen: Integer): DWORD;stdcall;
var
Fbuf, Bbuf: array of PByte;
begin
SetLength(Fbuf,1000000);
SetLength(Bbuf,1000000);
re := m_AddSealCard(Fbuf,sizeF,Bbuf,sizeB);
#8
不行。我试过了