【发布时间】:2015-01-01 19:25:02
【问题描述】:
我对 Delphi 的基本了解很少(事实上我已经使用了几年了)...
我用 DLL 碰壁了(从来没有真正玩过这个)。
考虑这个例子:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
Type FT_Result = Integer;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
FT_HANDLE : DWord = 0;
implementation
{$R *.dfm}
function I2C_GetNumChannels(numChannels: dword):FT_Result; stdcall; external 'libmpsse.dll' name 'I2C_GetNumChannels';
function I2C_OpenChannel(index:dword;handle:pointer):FT_Result; stdcall; external 'libmpsse.dll' name 'I2C_OpenChannel';
procedure TForm1.Button1Click(Sender: TObject);
var
numofchannels:dword;
begin
i2c_getnumchannels(numofchannels);
showmessage(inttostr(numofchannels));
end;
end.
我需要从 FTDI 连接 libmpsse.dll 以访问 USB 端口上的 I2C 设备。
当我调用函数 I2C_GetNumChannels 时,我得到了大量的 AccessViolation...
我只是想知道dll函数出了什么问题?
I2C_GetNumChannels 也应该返回 2 个值...
来自官方 API 指南 -->http://www.ftdichip.com/Support/Documents/AppNotes/AN_177_User_Guide_For_LibMPSSE-I2C.pdf
非常感谢!
问候
【问题讨论】:
-
numChannels是指向DWORD而不是DWORD的指针。你的函数声明是错误的。 -
我已经相应地更正了代码...谢谢!