Z
ZBilly
Unregistered / Unconfirmed
GUEST, unregistred user!
有VC编写的DLL文件 packet.dll 其给C调用的头文件部分如下:
packet32.h
...
#ifdef __cplusplus
extern "C" {
#endif
ULONG PacketGetAdapterNames(PTSTR pStr,PULONG BufferSize);
...
#ifdef __cplusplus
}
#endif
...
将此头文件转换成 packet.pas 节选如下:
unit packet32;
interface
uses windows;
const
NDIS_PACKET_TYPE_DIRECTED = $0001;
NDIS_PACKET_TYPE_MULTICAST = $0002;
NDIS_PACKET_TYPE_ALL_MULTICAST = $0004;
NDIS_PACKET_TYPE_BROADCAST = $0008;
NDIS_PACKET_TYPE_SOURCE_ROUTING = $0010;
NDIS_PACKET_TYPE_PROMISCUOUS = $0020;
//for snoop
NDIS_PACKET_TYPE_SMT = $0040;
NDIS_PACKET_TYPE_MAC_FRAME = $8000;
NDIS_PACKET_TYPE_FUNCTIONAL = $4000;
NDIS_PACKET_TYPE_ALL_FUNCTIONAL = $2000;
NDIS_PACKET_TYPE_GROUP = $1000;
//
MAX_LINK_NAME_LENGTH = 5;
... ...
function PacketGetAdapterNames(
pAdapterDescs: PWideChar;
pnAdapterDescsMax: PULONG ): ULONG;
stdcall;
implementation
const Packet32Lib = 'Packet.dll';
function PacketGetAdapterNames;
external 'Packet.dll' name 'PacketGetAdapterNames';
end.
调用 packet.dll 的程序:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls, ToolWin, Menus, ExtCtrls, ImgList, Packet32;
const
MAX_LINK_NAME_LENGTH = 5;
MAX_ADAPTER_COUNT = 512;
type
TForm1 = class(TForm)
MainMenu1: TMainMenu;
N1: TMenuItem;
N2: TMenuItem;
N3: TMenuItem;
N4: TMenuItem;
N5: TMenuItem;
N6: TMenuItem;
N7: TMenuItem;
N8: TMenuItem;
ToolBar1: TToolBar;
ToolButton1: TToolButton;
ToolButton2: TToolButton;
ToolButton3: TToolButton;
Panel1: TPanel;
ListView1: TListView;
StatusBar1: TStatusBar;
ImageList1: TImageList;
PopupMenu1: TPopupMenu;
N9: TMenuItem;
New1: TMenuItem;
procedure ToolButton1Click(Sender: TObject);
procedure ToolButton2Click(Sender: TObject);
procedure N4Click(Sender: TObject);
private
FAdapterDescs: array[0..511] of WCHAR;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
i:integer;
//AdapterName[512]:WCHAR
implementation
{$R *.DFM}
procedure TForm1.ToolButton1Click(Sender: TObject);
begin
i:=512;
if (PacketGetAdapterNames(@FAdapterDescs[0],@i)=1) then
begin
showmessage('ttt');
end;
end;
procedure TForm1.ToolButton2Click(Sender: TObject);
begin
showmessage('ttt');
end;
procedure TForm1.N4Click(Sender: TObject);
begin
Form1.DoDestroy ;
Application.Destroy ;
end;
end.
在WIN2K,DELPHI5上编译通过。运行时发生错误,提示
"Privileged instruction."
请说明一下错误发生的原因,最好能给出正确的代码,分不够可以加。
请提供 VC 中的数据类型 与DELPHI中的数据类型转换表。
THX
packet32.h
...
#ifdef __cplusplus
extern "C" {
#endif
ULONG PacketGetAdapterNames(PTSTR pStr,PULONG BufferSize);
...
#ifdef __cplusplus
}
#endif
...
将此头文件转换成 packet.pas 节选如下:
unit packet32;
interface
uses windows;
const
NDIS_PACKET_TYPE_DIRECTED = $0001;
NDIS_PACKET_TYPE_MULTICAST = $0002;
NDIS_PACKET_TYPE_ALL_MULTICAST = $0004;
NDIS_PACKET_TYPE_BROADCAST = $0008;
NDIS_PACKET_TYPE_SOURCE_ROUTING = $0010;
NDIS_PACKET_TYPE_PROMISCUOUS = $0020;
//for snoop
NDIS_PACKET_TYPE_SMT = $0040;
NDIS_PACKET_TYPE_MAC_FRAME = $8000;
NDIS_PACKET_TYPE_FUNCTIONAL = $4000;
NDIS_PACKET_TYPE_ALL_FUNCTIONAL = $2000;
NDIS_PACKET_TYPE_GROUP = $1000;
//
MAX_LINK_NAME_LENGTH = 5;
... ...
function PacketGetAdapterNames(
pAdapterDescs: PWideChar;
pnAdapterDescsMax: PULONG ): ULONG;
stdcall;
implementation
const Packet32Lib = 'Packet.dll';
function PacketGetAdapterNames;
external 'Packet.dll' name 'PacketGetAdapterNames';
end.
调用 packet.dll 的程序:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls, ToolWin, Menus, ExtCtrls, ImgList, Packet32;
const
MAX_LINK_NAME_LENGTH = 5;
MAX_ADAPTER_COUNT = 512;
type
TForm1 = class(TForm)
MainMenu1: TMainMenu;
N1: TMenuItem;
N2: TMenuItem;
N3: TMenuItem;
N4: TMenuItem;
N5: TMenuItem;
N6: TMenuItem;
N7: TMenuItem;
N8: TMenuItem;
ToolBar1: TToolBar;
ToolButton1: TToolButton;
ToolButton2: TToolButton;
ToolButton3: TToolButton;
Panel1: TPanel;
ListView1: TListView;
StatusBar1: TStatusBar;
ImageList1: TImageList;
PopupMenu1: TPopupMenu;
N9: TMenuItem;
New1: TMenuItem;
procedure ToolButton1Click(Sender: TObject);
procedure ToolButton2Click(Sender: TObject);
procedure N4Click(Sender: TObject);
private
FAdapterDescs: array[0..511] of WCHAR;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
i:integer;
//AdapterName[512]:WCHAR
implementation
{$R *.DFM}
procedure TForm1.ToolButton1Click(Sender: TObject);
begin
i:=512;
if (PacketGetAdapterNames(@FAdapterDescs[0],@i)=1) then
begin
showmessage('ttt');
end;
end;
procedure TForm1.ToolButton2Click(Sender: TObject);
begin
showmessage('ttt');
end;
procedure TForm1.N4Click(Sender: TObject);
begin
Form1.DoDestroy ;
Application.Destroy ;
end;
end.
在WIN2K,DELPHI5上编译通过。运行时发生错误,提示
"Privileged instruction."
请说明一下错误发生的原因,最好能给出正确的代码,分不够可以加。
请提供 VC 中的数据类型 与DELPHI中的数据类型转换表。
THX