谁来讲解这个Dll。(0分)

  • 主题发起人 主题发起人 KenLee
  • 开始时间 开始时间
K

KenLee

Unregistered / Unconfirmed
GUEST, unregistred user!
1.详细讲解该DLL的格式尤其是数据结构定义部分
2.cdecl ;export;packet record的意义。readini、writeini两个函数;
3.详细讲解其它DLL格式(听说另外有两种)
Unit demo;

Interface

uses windows, shlobj, SysUtils;

type
LongPtr = ^longint;

var
FuncResult : longint;
Apphand : THandle;

Function MAGIC_BIND : pointer; cdecl ;export;

Function ReadINI (Section, Key, Filename : pchar):pchar; cdecl;
Function WriteINI (Section, Key, Value, Filename : pchar):longptr; cdecl;

Function DirBrowse(Apphandptr:LongPtr): pchar;cdecl;

Function BrowseCallback(hWnd: HWND; uMsg: UINT; lParam: LPARAM;
lpData: LPARAM): Integer;stdcall;export;

Implementation

Type
MagicFunction = packed Record
Name : Pchar; { Function Name }
Address : Pointer; { Function Address }
NArgs : SmallInt; { Argument Count }
ArgTypes : Pchar; { Argument Attributes + 1 Extra }
{ for the return type of UserFuncs }
{ 'A','L','D' }
end;
MagicModule = packed Record
UseCount : SmallInt;
InitFunct,
ExitFunct : Pointer;
NFuncs : SmallInt;
FuncTable : Pointer;
ModuleName : Pchar;
Context : SmallInt;
end;

Const
NFUNC = 3; { No of Functions Exported }

FuncTable : array [1..NFUNC] of MagicFunction = (
( Name: 'ReadINI';
Address: Addr(ReadINI);
NArgs: 3;
ArgTypes: 'AAAA' ),
( Name: 'WriteINI';
Address: Addr(WriteINI);
NArgs: 4;
ArgTypes: 'AAAAL' ),
( Name: 'DirBrowse';
Address: Addr(DirBrowse);
NArgs: 1;
ArgTypes: 'LA' )
);

Module : MagicModule = (
UseCount: 0;
InitFunct: NIL;
ExitFunct: NIL;
NFuncs: NFUNC;
FuncTable: Addr( FuncTable );
ModuleName: 'mgdelphi';
Context: 0
);

Function MAGIC_BIND : pointer;
begin
Result := Addr( Module );
end;


Function ReadINI (Section, Key, Filename : pchar):pchar; cdecl;
var
value : array[0..255] of char;
s : PChar;
begin
value := '';
s := PChar(ExtractFilePath(ParamStr(0))+fileName);
getprivateprofilestringa(Section,Key,'',Value,
256, s);
ReadINI := Value;
end;


Function WriteINI (Section, Key, Value, Filename : pchar):Longptr; cdecl;
var
s : PChar;
begin
s := PChar(ExtractFilePath(ParamStr(0))+fileName);
writeprivateprofilestringa(Section,Key,Value,s);
FuncResult := 0;
WriteINI := @Funcresult;
end;


{The code for this was ripped from The Tomes of Delphi 3
Buy it, you can't live without it }

Function DirBrowse(Apphandptr:LongPtr): pchar;cdecl;
var
IDList: PItemIDList; // an item identifier list
BrowseInfo: TBrowseInfo; // the browse info structure
PathName: array[0..MAX_PATH] of char; // the path name
DisplayName: array[0..MAX_PATH] of char; // the file display name

begin
apphand := apphandptr^;
{initialize the browse information structure}
BrowseInfo.hwndOwner := apphand;
BrowseInfo.pidlRoot := nil;
BrowseInfo.pszDisplayName := DisplayName;
BrowseInfo.lpszTitle := 'Choose a folder';
BrowseInfo.ulFlags := BIF_STATUSTEXT; // display a status line
BrowseInfo.lpfn := @BrowseCallback;
BrowseInfo.lParam := 0;

{show the browse for folder dialog box}
IDList := SHBrowseForFolder(BrowseInfo);

{retrieve the path from the item identifier list
that was returned}
SHGetPathFromIDList(IDList, @PathName);

DirBrowse := pathname;
end;

{this callback function is called whenever an action takes
place inside the browse for folder dialog box}
Function BrowseCallback(hWnd: HWND; uMsg: UINT; lParam: LPARAM;
lpData: LPARAM): Integer;
var
PathName: array[0..MAX_PATH] of Char; // holds the path name
begin
{if the selection in the browse for folder
dialog box has changed...}
if uMsg=BFFM_SELCHANGED then
begin
{...retrieve the path name from the item identifier list}
SHGetPathFromIDList(PItemIDList(lParam), @PathName);

{display this path name in the status line of the dialog box}
SendMessage(hWnd, BFFM_SETSTATUSTEXT, 0, Longint(PChar(@PathName)));
end;
Result := 0;
end;

initialization

finalization

end.
 
后退
顶部