你贴的东西太少了,出错,出什么错呢?我给你一个例子你自己看看吧。。testdll.cpp的内容:BOOL WINAPI Initimize( LPSTR lpFileName ){ hFile = ::CreateFile( lpFileName, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL ); return ( INVALID_HANDLE_VALUE != hFile );}DWORD WINAPI ReadBuffer( BYTE &lpBuffer, DWORD dwBufferSize ){ if ( INVALID_HANDLE_VALUE == hFile ) return 0; if ( ::SetFilePointer( hFile, FILE_BEGIN, NULL, 0 ) == 0xffffffff && ::GetLastError() != ERROR_SUCCESS ) return 0; DWORD dwReadBytes = 0; if ( ::ReadFile( hFile, (void *)&lpBuffer, dwBufferSize, &dwReadBytes, NULL ) ) { return dwReadBytes; } else return 0;}DWORD WINAPI WriteBuffer( BYTE *lpBuffer, DWORD dwBufferSize ){ if ( INVALID_HANDLE_VALUE == hFile ) return 0; if ( ::SetFilePointer( hFile, FILE_BEGIN, NULL, 0 ) == 0xffffffff && ::GetLastError() != ERROR_SUCCESS ) return 0; DWORD dwWriteBytes = 0; if ( ::WriteFile( hFile, lpBuffer, dwBufferSize, &dwWriteBytes, NULL ) ) return dwWriteBytes; else return 0;}BOOL WINAPI UnInitimize( void ){ if ( INVALID_HANDLE_VALUE == hFile ) return FALSE; if ( ::CloseHandle( hFile ) ) { hFile = INVALID_HANDLE_VALUE; return TRUE; } else return FALSE;}调用方内容:unit Main;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm1 = class(TForm) Button1: TButton; Button2: TButton; Edit1: TEdit; procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;const TestDll = 'TestDll.dll';function Initimize(lpFileName: PAnsiChar): BOOL; stdcall; external TestDll name 'Initimize';function ReadBuffer(var lpBuffer; dwBufferSize: DWORD): DWORD; stdcall; external TestDll name 'ReadBuffer';function WriteBuffer(const lpBuffer; dwBufferSize: DWORD): DWORD; stdcall; external TestDll name 'WriteBuffer';function UnInitimize(): BOOL stdcall; external TestDll name 'UnInitimize';implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);begin Initimize('C:/1.txt');end;procedure TForm1.FormDestroy(Sender: TObject);begin UnInitimize;end;procedure TForm1.Button1Click(Sender: TObject); var s: AnsiString;begin s:= Edit1.Text; WriteBuffer(s[1], Length(s));end;procedure TForm1.Button2Click(Sender: TObject); var s: AnsiString;begin SetLength(s, MAX_PATH); ReadBuffer(s[1], MAX_PATH); Edit1.Text:= s;end;end.