I am writing a menu plugin which allows users to display proper Windows Menus in their DBP apps. Currently I can get the menus to display fine in the DBP program, with all the various features. However I need to process the WM messages send to the Window in order to find out when a particular menu item is selected.
I can process messages fine, however apparently I need to subclass the application in order to trap the WM messages sent to the Window.
Currently I get the address of my replacement function using GetProcAddress() (the module handle is 38329 or something and the address when I dereference to pointer is -45240924204 which surely can't be right?), then I use SetWindowLong to replace DBP's message processing function.
The Window handle for the DBP app is correct because I am using it to assign the menu to the app's Window.
However, whenever I call the SetWindowLong function, I get an Access Violation error. What MSDN didn't make very clear is whether or not a DLL is allowed to make this change to its parent process or not. Currently I have just copied the basic Window message handling function from MSDN to test it (which just redirects all messages to the original processing function). I think that the replacement function is not the problem though.
Delphi Source:
function CreateMenu(AppTitle: PChar):Int64;
var
hndl: Int64;
prochndl: ^Int64;
begin
menu := TMenu.Create(nil);
winhandle := FindWindow(nil,PChar(AppTitle));
hndl := Windows.GetModuleHandle('menusdll');
prochndl := GetProcAddress(hndl,'GetMenuItem');
SetWindowLong(winhandle,GWL_WNDPROC,prochndl^);
ShowMessage('test');
SetMenu(winhandle,menu.Handle);
Result := menu.Handle;
end;
DBPSource:
load dll "menusdll.dll",1
make object cube 1,5
call dll 1,"CreateMenu","Menus"
call dll 1,"AddMainMenuItem","File"
call dll 1,"AddMainMenuItem","Object"
call dll 1,"AddMainMenuItem","Help"
call dll 1,"AddSubMenuItem",0,"Exit"
call dll 1,"AddSubMenuItem",1,"Shape"
call dll 1,"AddSubMenuItem",2,"About"
do
xrotate object 1,object angle x(1)+1
yrotate object 1,object angle y(1)+1
loop
Current Project: Retro Compo. Entry.