delphi嵌匯編是非常好的容易的
library delphi_api_dll;
uses
Windows, Messages, Shellapi, Dialogs;
//{$R *.res}
const
wM_User = $400;
function Msg(wParam, lParam: Cardinal): Cardinal; stdcall
begin
ShowMessage(char(wParam) + char(lParam));
end;
function WinProc(hWnd: THandle; nMsg: UINT;
wParam, lParam: Cardinal): Cardinal; export; stdcall;
begin
case nMsg of
wM_User + 401: //對話(huà)消息
Msg(wParam, lParam);
end;
result := DefWindowProc(hWnd, nMsg, wParam, lParam);
end; //消息回調函數
procedure WinMain;
var
hWnd: THandle;
Msg: TMsg;
WndClassEx: TWndClassEx; //注冊窗口類(lèi)
begin
WndClassEx.cbSize := SizeOf(TWndClassEx);
WndClassEx.lpszClassName := 'api_dll';
WndClassEx.style := cs_VRedraw or cs_HRedraw;
WndClassEx.hInstance := Hinstance;
WndClassEx.lpfnWndProc := @WinProc;
WndClassEx.cbClsExtra := 0;
WndClassEx.cbWndExtra := 0;
WndClassEx.hIcon := LoadIcon(Hinstance, Pchar('MAINICON'));
WndClassEx.hIconSm := LoadIcon(Hinstance, Pchar('MAINICON'));
WndClassEx.hCursor := LoadCursor(0, idc_Arrow);
WndClassEx.hbrBackground := GetStockObject(gray_Brush);
WndClassEx.lpszMenuName := nil;
if RegisterClassEx(WndClassEx) <> 0 then
begin
hWnd := CreateWindowEx(WS_EX_TOPMOST or WS_EX_ACCEPTFILES,
WndClassEx.lpszClassName,
'api_dll', ws_OverlappedWindow,
0, 0, 0, 0, 0, 0,
Hinstance, nil); //創(chuàng )建窗口HeroXs
if hWnd <> 0 then
begin
ShowWindow(hWnd, SW_HIDE); //隱藏DLL窗口
//ShowWindow(hWnd, SW_ShowNormal);//顯示DLL窗口
while GetMessage(Msg, hWnd, 0, 0) do
begin
TranslateMessage(Msg);
DispatchMessage(Msg);
end;
end;
end;
end; //DLL消息循環(huán)窗口
procedure DllMain(hModule: HMODULE; Reason: Integer; lpReserved: Pointer);
var
TheThread: DWORD; //返回線(xiàn)程ID
begin
case Reason of
DLL_PROCESS_ATTACH:
CreateThread(nil, 0, @WinMain, nil, 0, TheThread);
end;
end; //DLL進(jìn)入時(shí)創(chuàng )建窗口線(xiàn)程
exports
Msg; //導出
begin
DLLProc := @DllMain;
DllMain(hInstance, DLL_PROCESS_ATTACH, nil);
end.
本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請
點(diǎn)擊舉報。