主题:一个C++转Delphi的问题,求救了
C代码是
SCSISDK.h
// The following ifdef block is the standard way of creating macros which make exporting
// from a DLL simpler. All files within this DLL are compiled with the SCSISDK_EXPORTS
// symbol defined on the command line. this symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see
// SCSISDK_API functions as being imported from a DLL, wheras this DLL sees symbols
// defined with this macro as being exported.
#ifdef SCSISDK_EXPORTS
#define SCSISDK_API extern "C" __declspec(dllexport)
#else
#define SCSISDK_API extern "C" __declspec(dllimport)
#endif
SCSISDK_API BOOL SCSIReadData(CHAR cDriveLetter,PUCHAR pCDB,PUCHAR pReadBuf,DWORD dwReadLen);
SCSISDK_API BOOL SCSIWriteData(CHAR cDriveLetter,PUCHAR pCDB,PUCHAR pWriteBuf,DWORD dwWriteLen);
SCSISDK_API BOOL SCSISendCommand(CHAR cDriveLetter,PUCHAR pCDB);
///////////////////////////////
example.c
#include "SCSISDK.h"
void Disk_To_Comport()
{
char driveLetter='C';
int i;
BYTE CDB[16]={0xEE,0x01,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
BYTE DataBuf[4]={0};
for(i = 2 ; i < 26 ; i++)
{
driveLetter=i+'A';
SCSISendCommand(driveLetter,CDB);
}
}
转成Delphi 是
const CDB:Array[0..15] of Byte=(238,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
implementation
{$R *.dfm}
procedure TfrmAutoRun.Button1Click(Sender: TObject);
Var
LibHandle: THandle;
FunAddress:Function (DataBuf:pchar;CDB:Array of Byte):WordBool;Stdcall;
driveLetter:String;
Rtn: WordBool;
tmploop:Integer;
begin
LibHandle:=LoadLibrary(PChar(ExtractFilePath(Application.ExeName)+'SCSISDK.dll'));
FunAddress:=GetProcAddress(LibHandle,'SCSISendCommand');
driveLetter:='C';;
for tmploop:=2 to 25 do
begin
driveLetter:=driveLetter+'A';
Rtn:=FunAddress(PChar(driveLetter),(CDB));
end;
FreeLibrary(LibHandle);
end;
但结果始终不对,求教各位大哥了。
SCSISDK.h
// The following ifdef block is the standard way of creating macros which make exporting
// from a DLL simpler. All files within this DLL are compiled with the SCSISDK_EXPORTS
// symbol defined on the command line. this symbol should not be defined on any project
// that uses this DLL. This way any other project whose source files include this file see
// SCSISDK_API functions as being imported from a DLL, wheras this DLL sees symbols
// defined with this macro as being exported.
#ifdef SCSISDK_EXPORTS
#define SCSISDK_API extern "C" __declspec(dllexport)
#else
#define SCSISDK_API extern "C" __declspec(dllimport)
#endif
SCSISDK_API BOOL SCSIReadData(CHAR cDriveLetter,PUCHAR pCDB,PUCHAR pReadBuf,DWORD dwReadLen);
SCSISDK_API BOOL SCSIWriteData(CHAR cDriveLetter,PUCHAR pCDB,PUCHAR pWriteBuf,DWORD dwWriteLen);
SCSISDK_API BOOL SCSISendCommand(CHAR cDriveLetter,PUCHAR pCDB);
///////////////////////////////
example.c
#include "SCSISDK.h"
void Disk_To_Comport()
{
char driveLetter='C';
int i;
BYTE CDB[16]={0xEE,0x01,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
BYTE DataBuf[4]={0};
for(i = 2 ; i < 26 ; i++)
{
driveLetter=i+'A';
SCSISendCommand(driveLetter,CDB);
}
}
转成Delphi 是
const CDB:Array[0..15] of Byte=(238,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
implementation
{$R *.dfm}
procedure TfrmAutoRun.Button1Click(Sender: TObject);
Var
LibHandle: THandle;
FunAddress:Function (DataBuf:pchar;CDB:Array of Byte):WordBool;Stdcall;
driveLetter:String;
Rtn: WordBool;
tmploop:Integer;
begin
LibHandle:=LoadLibrary(PChar(ExtractFilePath(Application.ExeName)+'SCSISDK.dll'));
FunAddress:=GetProcAddress(LibHandle,'SCSISendCommand');
driveLetter:='C';;
for tmploop:=2 to 25 do
begin
driveLetter:=driveLetter+'A';
Rtn:=FunAddress(PChar(driveLetter),(CDB));
end;
FreeLibrary(LibHandle);
end;
但结果始终不对,求教各位大哥了。