B
Boblee
Unregistered / Unconfirmed
GUEST, unregistred user!
代码如下:
commfuns.dll:
library commFuns;
{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }
uses
SysUtils,
WinSock,
Registry,
Graphics,
Windows,
MemMap,
Search,
Classes;
type
TCollector=set of char;//定义一个char类型集合。
{$R *.res}
{其它的函数定义。。}
{
function Name: getSelfPCName
para:无
function:
返回本机的机器名。
Return:
type:Sting
Value:返回本机的机器名。
}
function getSelfPCName:String;stdcall;export;
var
wVersionRequested : WORD;
wsaData : TWSAData;
p : PHostEnt;
s : array[0..128] of char;
begin
wVersionRequested := MAKEWORD(1, 1);
WSAStartup(wVersionRequested, wsaData);
GetHostName(@s, 128);
p := GetHostByName(@s);
WSACleanup;
Result := p^.h_Name;
end;
exports
getIPByHostName index 1,
getSelfPCName index 2, //测试函数,其它函数我就不列出来了。
getWorkGroupList index 3,
getNetNeighborList index 4,
IsDBCSLeadByte index 5,
getKeyValueFromRegistry index 6,
checkKeyValueExistsInRegistry index 7,
addKeyValueToRegistry index 8,
ColorToStringEx index 9,
ColorToStringExStd index 10,
UnescapeStr index 11,
EscapeStr index 12,
keyboardInpuFilter index 13,
GetDirectoryName index 14,
FindFiles index 15,
searchAndDelCommentsEx index 16;
begin
end.
testDll.dpr:
unit testDll;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, OoMisc, AdPager;
type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
ApdSNPPPager1: TApdSNPPPager;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
function getSelfPCName:string;stdcall;external 'CommFuns.dll';
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
showmessage(getSelfPCName);
end;
end.
commfuns.dll:
library commFuns;
{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }
uses
SysUtils,
WinSock,
Registry,
Graphics,
Windows,
MemMap,
Search,
Classes;
type
TCollector=set of char;//定义一个char类型集合。
{$R *.res}
{其它的函数定义。。}
{
function Name: getSelfPCName
para:无
function:
返回本机的机器名。
Return:
type:Sting
Value:返回本机的机器名。
}
function getSelfPCName:String;stdcall;export;
var
wVersionRequested : WORD;
wsaData : TWSAData;
p : PHostEnt;
s : array[0..128] of char;
begin
wVersionRequested := MAKEWORD(1, 1);
WSAStartup(wVersionRequested, wsaData);
GetHostName(@s, 128);
p := GetHostByName(@s);
WSACleanup;
Result := p^.h_Name;
end;
exports
getIPByHostName index 1,
getSelfPCName index 2, //测试函数,其它函数我就不列出来了。
getWorkGroupList index 3,
getNetNeighborList index 4,
IsDBCSLeadByte index 5,
getKeyValueFromRegistry index 6,
checkKeyValueExistsInRegistry index 7,
addKeyValueToRegistry index 8,
ColorToStringEx index 9,
ColorToStringExStd index 10,
UnescapeStr index 11,
EscapeStr index 12,
keyboardInpuFilter index 13,
GetDirectoryName index 14,
FindFiles index 15,
searchAndDelCommentsEx index 16;
begin
end.
testDll.dpr:
unit testDll;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, OoMisc, AdPager;
type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
ApdSNPPPager1: TApdSNPPPager;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
function getSelfPCName:string;stdcall;external 'CommFuns.dll';
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
showmessage(getSelfPCName);
end;
end.