一个有关动态链接库的问题(100分)

  • 主题发起人 主题发起人 sun_8113
  • 开始时间 开始时间
S

sun_8113

Unregistered / Unconfirmed
GUEST, unregistred user!
我用BCB写了个方法如下:
extern "C"
void __declspec(dllexport) __stdcall CreateEncrypt(char * FileName);
extern "C"
void __declspec(dllexport) __stdcall WriteEncrypt(void * buffer,unsigned long FBufferSize);
extern "C"
void __declspec(dllexport) __stdcall CloseEncrypt();

CEvFile *pevf;
void __stdcall CreateEncrypt(char * FileName)
{
pevf = new CEvFile();
pevf->Create(FileName);
}
void __stdcall WriteEncrypt(void * buffer,unsigned long FBufferSize)
{
pevf->Write(buffer,FBufferSize);
}
void __stdcall CloseEncrypt()
{
pevf->Close();
delete pevf;
pevf = NULL;
}

procedure CreateEncrypt(FileName:Pchar);stdcall;
external 'FileEncrypt.dll';
procedure WriteEncrypt(buffer: pointer;
FBufferSize: LongWord);stdcall;
external 'FileEncrypt.dll';
procedure CloseEncrypt();stdcall;
external 'FileEncrypt.dll';
用delphi调用
hFile := FileOpen('d:/30003.vob',fmOpenRead);
if (hfile = INVALID_HANDLE_VALUE) then
ShowMessage('fff');
CreateEncrypt('c:/aa.mpg');
buffer := GetMemory(1024*10);
//(buffer,1024*10);
while truedo
begin
BytesReturn := FileRead(hFile,buffer,1024*10);
if BytesReturn = 0 then
break;
WriteEncrypt(pointer(buffer),BytesReturn);
//这里传指针过去值会丢失,是不是我写的有问题
end;

FreeMemory(buffer);
CloseEncrypt();
FileClose(hFile);
ShowMessage('加密完成');
 
cdecl ,调用者清理堆栈
stdcall,被调用者清理堆栈
因此可能是 WriteEncrypt(pointer(buffer),BytesReturn);
//这里传指针过去值会丢失,是不是我写的有问题,这句在dll中把buffer释放了
 
to: hanpengshan_00
能说具体点吗?
我将stdcall改成了 cdecl
提示dll中无法定位到方法.
为什么?该怎么改?
 
已经可以了
 
接受答案了.
 
后退
顶部