
11.03.2012, 04:15
|
 |
.
|
|
Регистрация: 18.05.2011
Адрес: Омск
Сообщения: 3,970
Версия Delphi: 3,5,7,10,12,XE2
Репутация: выкл
|
|
Если я правильно понял, то нужно что-то подобное:
program
Код:
program Test;
uses
Windows, Messages;
type
PMyRecord = ^TMyRecord;
TMyRecord = record
Name : String;
end;
TSetMessage = procedure; stdcall;
const
MY_MESSAGE = WM_USER + 4242;
szAppName = 'MainForm';
szCaptionName = 'test';
var
Window : HWND;
Msg : TMsg;
WndClass : TWndClassEX;
SizeX, SizeY : Integer;
hDll : HMODULE;
hBtn : HWND;
SetMessage : TSetMessage;
const
cctrl = 'comctl32.dll';
procedure InitCommonControls; external cctrl name 'InitCommonControls';
//---------------------------------------------------------
procedure InitApp(Wnd : HWND);
begin
hDLL := LoadLibrary(PChar('mydll.dll'));
if hDLL = 0 then
Exit;
@SetMessage := GetProcAddress(hDLL, 'SetMessage');
if Addr(SetMessage) = NIL then
Exit;
hBtn := CreateWindow('BUTTON', 'Жми', WS_CHILD or WS_VISIBLE, 280, 400, 80, 25, Wnd, 100, hInstance, NIL);
end;
//---------------------------------------------------------
procedure DeInitApp(Wnd : HWND);
begin
DestroyWindow(hBtn);
if hDll <> 0 then
FreeLibrary(hDLL);
end;
//---------------------------------------------------------
function MainProc(Wnd : HWND; Msg : Integer; wParam, lParam : Longint) : Integer; stdcall;
begin
Result := 0;
case Msg of
WM_CREATE :
begin
InitApp(Wnd);
end;
MY_MESSAGE :
begin
with PMyRecord(lParam)^ do
MessageBox(Wnd, PChar(Name), '', MB_OK);
end;
WM_COMMAND :
case LOWORD(wParam) of
100 :
if hDll <> 0 then
SetMessage;
end;
WM_CLOSE :
begin
DestroyWindow(Wnd);
end;
WM_DESTROY :
begin
DeInitApp(Wnd);
PostQuitMessage(0);
Exit;
end;
end;
Result := DefWindowProc(Wnd, Msg, wParam, lParam);
end;
//---------------------------------------------------------
begin
SizeX := 640;
SizeY := 480;
FillChar(WndClass, SizeOf(TWndClassEx), 0);
WndClass.cbSize := SizeOf(TWndClassEx);
WndClass.style := CS_HREDRAW or CS_VREDRAW;
WndClass.lpfnWndProc := @MainProc;
WndClass.cbClsExtra := 0;
WndClass.cbWndExtra := 0;
WndClass.hInstance := hInstance;
WndClass.hCursor := LoadCursor(0, IDC_ARROW);
WndClass.hbrBackGround := GetSysColorBrush(COLOR_BTNFACE);
WndClass.lpszClassName := szAppName;
if RegisterClassEx(WndClass) = 0 then
Halt(255);
Window := CreateWindowEx(0, szAppName, szCaptionName,
WS_DLGFRAME or WS_SYSMENU or WS_MINIMIZEBOX,
0, 0, SizeX, SizeY, 0, 0, hInstance, NIL);
InitCommonControls;
ShowWindow(Window, SW_SHOW);
while(GetMessage(Msg, 0, 0, 0)) do
begin
TranslateMessage(Msg);
DispatchMessage(Msg);
end;
Halt(Msg.wParam);
end.
library
Код:
library mydll;
uses
Windows, Messages;
const
MY_MESSAGE = WM_USER + 4242;
type
TMyRecord = record
Name : String;
end;
procedure SetMessage;
var
h : HWND;
mr : TMyRecord;
begin
h := FindWindow('MainForm', NIL);
if h <> 0 then
begin
mr.Name := 'Hello World';
SendMessage(h, MY_MESSAGE, 0, DWORD(@mr));
end
else
MessageBox(0, 'fail', 'Error', MB_OK);
end;
exports
SetMessage;
begin
end.
__________________
Je venus de nulle part
55.026263 с.ш., 73.397636 в.д.
|