请教 delphi7 调用 vfp5 提供的 fpole.dll 的函数。
我在 Form1 上放了一个 Button1, 下面是所有的代码。但是它产生错误
Project test_fpole.exe raised exception class EAccessViolation wit message 'Access violation at address 010c2c76 in module 'fpole.dll'. Read of address 00000000'.
****************
文件 test_fpole.dpr
****************
program test_fpole;
uses
  Forms,
  callfpole in 'callfpole.pas' {Form1};
{$R *.res}
begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.
****************
文件 callfpole.pas
****************
unit callfpole;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;
type
  TFoxDoCmd = function(i:string;j:string):Integer;stdcall; //FoxDoCmd
  TFoxEval = function(i:string;j:string;k:integer):Integer;stdcall; //FoxEval
  TSetErrMode = function(i:integer):Integer;stdcall; //SetErrMode
  TSetOleObject = function(i:string):Integer;stdcall; // SetOleObject
  TCloseIt = function():Integer;stdcall; // CloseIt
  TGetLastErr = function(i:string;j:integer):Integer;stdcall; //GetLastErr
  TForm1 = class(TForm)
  Button1: TButton;
  procedure Button1Click(Sender: TObject);
 private
   { Private declarations }
 public
   { Public declarations }
 end;
var
  Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
 hDLL: THandle;
 f1:TFoxDoCmd;
 f2:TFoxEval;
 f3:TSetErrMode;
 f4:TSetOleObject;
 f5:TCloseIt;
 f6:TGetLastErr;
 cString1: string;
 cString2: string;
begin
 hDLL := LoadLibrary('fpole.dll');
 if (hDLL <> 0) then
 begin
   @f1 := GetProcAddress(hDLL, Pchar('FoxDoCmd'));
   @f4 := GetProcAddress(hDLL, Pchar('SetOleObject'));
   cString1:='visualfoxpro.application';
   ShowMessage(IntToStr(f4(cString1)));
   cString1:='close all';
   cString2:='';
   ShowMessage(IntToStr(f1(cString1,cString2)));
   FreeLibrary(hDLL);
 end;
end;
end.
****************
fpole.dll 说明
****************
使用 FPOLE.DLL,您可以从允许调用 API 但不支持自动化的应用程序中,运行 Visual FoxPro 命令并计算 Visual FoxPro 表达式。FPOLE.DLL 包含下列六个函数。
运行 Visual FoxPro 命令 FoxDoCmd( )
计算 Visual FoxPro 表达式 FoxEval( )
指定是否在消息框中显示错误信息 SetErrMode( )
指定 FoxDocmd( ) 和 FoxEval( ) 创建的 OLE 类 SetOleObject( )
关闭使用 FoxDoCmd( ) 或 FoxEval( ) 时创建的 OLE 类 CloseIt( )
检索最近发生过的错误 GetLastErr( )
****************
SetOLEObject( ) 函数 
指定调用 FoxDoCmd( ) 和 FoxEval( ) 时创建的 OLE 类。
语法
nSuccess = SetOleObject(cOLEClass)
返回值
整数
说明
如果指定类成功,则返回 -1;否则返回 0。
在 SetOLEObject( ) 中指定您的应用程序,这样可以使不支持自动化的应用程序能够使用自动化。
****************
FoxDoCmd( ) 函数
从允许 API 调用的应用程序中运行 Visual FoxPro 命令。
语法
nSuccess = FoxDoCmd(cFoxCommand, cOptions)
返回值
整数
参数
cFoxCommand   指定要运行的 Visual FoxPro 命令。
cOptions   下列值:
设置 说明
(空格)运行指定命令,但不激活 Visual FoxPro 主窗口。
a 激活 Visual FoxPro 窗口,并运行指定命令。
i 如果未运行 Visual FoxPro,激活 Visual FoxPro,但不显示Visual FoxPro 主窗口。
t 如果正在Visual FoxPro中运行另一个程序,显示错误信息,而不执行 cFoxCommand。
说明
如果 Visual FoxPro 命令执行成功,则返回 -1;否则返回 0。
如果已经运行 Visual FoxPro 5.0,FoxDocmd( ) 向 Visual FoxPro 发送命令。如果还没有运行 Visual FoxPro,FoxDoCmd( ) 运行 Visual FoxPro,然后发送命令。
****************