It's still early days for me with dlls.
My objective is to create a window in the exe and create then subclass a child window on it in the dll. I have established that DDT cannot be used in this way, not for the subclassed control anyway.
Whenever control is passed to the subclass proc, things start to go wrong, usually ending in a GPF. I've gone around it a couple of times without success - any suggestions?
the dll code
the exe code
My objective is to create a window in the exe and create then subclass a child window on it in the dll. I have established that DDT cannot be used in this way, not for the subclassed control anyway.
Whenever control is passed to the subclass proc, things start to go wrong, usually ending in a GPF. I've gone around it a couple of times without success - any suggestions?
the dll code
Code:
' dll and subclass problem #compile dll #dim all #include "commctrl.inc" global hCtlStatic as dword global hDlg as dword global OldProc as dword '------------------------------------------------------------------------------ function SCProc ( hWnd as dword, byval wMsg as dword, byval wparam as dword, byval lparam as dword) export as long local s as string ? "SubClassProc" s = "replacement title" 'hex$(wmsg) sendmessage hDlg, %WM_SETTEXT, 0, strptr(s) function = callWindowProc(OldProc, hWnd, Wmsg, wParam, lParam) 'function = defWindowProc(hWnd, Wmsg, wParam, lParam) end function '---------------------------------------------------------------------------- function CrWnd alias "CrWnd" ( hd as dword, lCtlStatic as long) export as dword local hinst, dw as dword local l as long initcommoncontrols hCtlStatic = CreateWindowEx(0,"Static","", _ %ws_child or %ws_visible or %ws_tabstop or %ws_border, _ 205, 5, 200, 150, _ hd, lCtlStatic, getmodulehandle(byval 0), byval %NULL) hDlg = hD ? "hWnd=" + str$(hCtlStatic) + str$(hd) ? "pre subclass" OldProc = SetWindowLong(hCtlStatic, %GWL_WNDPROC, codeptr(SCProc)) ? "post subclass" end function
Code:
' DDT DLL problem ' Chris Holbrook 22-DEC-2008 #compile exe #dim all #include "WIN32API.INC" %IDD_DIALOG1 = 101 %IDC_Static = 1002 declare function CrWnd lib "dllscproblem.dll" alias "CrWnd" ( hd as dword, lctlStatic as long) as dword 'declare function SCProc lib "dllscproblem.dll" alias "SCProc" ( hWnd as dword, byval wMsg as dword, byval wparam as dword, byval lparam as dword) as long '----------------------------------------------------------------------- function My_MainWndProc _ ( _ byval hWnd as dword, _ ' window handle byval uMsg as dword, _ ' type of message byval wParam as dword, _ ' first message parameter byval lParam as long _ ' second message parameter ) export as long select case uMsg case %wm_destroy PostQuitMessage 0 exit function case %wm_create CrWnd( hWnd, %IDC_Static)' Create a STATIC control function = 0 exit function end select function = defWindowProc(hWnd, uMsg, wParam, lParam) end function '----------------------------------------------------------------------- function winmain _ ( byval hInstance as long, _ ' handle of current instance byval hPrevInstance as long, _ ' handle of previous instance(not used in Win32) byval pszCmdLine as asciiz ptr, _ ' address of command line byval nCmdShow as long _ ' show state of window ) as long local szClassName as asciiz * 32 ' class name local tWCX as WNDCLASSEX ' class information local tmsg as tagMsg ' message information local hWnd, i, lresult as dword ' Register the Form1 window szClassName = "MY_CLASS" tWCX.cbSize = sizeof(tWCX) ' size of WNDCLASSEX structure tWCX.style = %CS_DBLCLKS or %CS_HREDRAW or %CS_VREDRAW ' class styles tWCX.lpfnWndProc = codeptr(My_MainWndProc) ' address of window procedure used by class tWCX.cbClsExtra = 0 ' extra class bytes tWCX.cbWndExtra = 0 ' extra window bytes tWCX.hInstance = hInstance ' instance of the EXE/DLL that is registering the window tWCX.hIcon = LoadIcon(%NULL, byval %IDI_APPLICATION) ' handle of class icon tWCX.hCursor = LoadCursor(%NULL, byval %IDC_ARROW) ' handle of class cursor tWCX.hbrBackground = getstockobject(%white_brush) ' brush used to fill background of window's client area tWCX.lpszMenuName = %NULL ' resource identifier of the class menu tWCX.lpszClassName = varptr(szClassName) ' class name tWCX.hIconSm = LoadIcon(%NULL, byval %IDI_APPLICATION) ' handle of small icon shown in caption/system Taskbar if isfalse RegisterClassEx(tWCX) then function = %FALSE exit function end if ' Create main window hWnd = CreateWindowEx(%ws_ex_windowedge, _ szClassName, _ "One day...",_ %ws_overlapped or %ws_visible or %ws_sysmenu, _ 100, 100, 200, 100, _ %NULL, %NULL, hInstance, byval %NULL) ' fail if window is not created if isfalse hWnd then function = %FALSE exit function end if ' Activate window ShowWindow hWnd, %sw_show UpdateWindow hWnd while istrue GetMessage(tmsg, byval %NULL, 0, 0) if isfalse IsDialogMessage(hWnd, tmsg) then TranslateMessage tmsg DispatchMessage tmsg end if wend end function '-------------------------------------------------------------------------
Comment