Recent

Author Topic: fpc 3.2.2 + win32api Call's - can't properly use RegisterClassEx  (Read 125 times)

paule32

  • Hero Member
  • *****
  • Posts: 516
  • One in all. But, not all in one.
when I use this code fragment, I get segfault with the gdb on RegisterClassEx

Code: Pascal  [Select][+][-]
  1. function GlobalWndProc(id: HWND; Msg: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall; export;
  2. var
  3.   winCtrl: TWinControl;
  4. begin
  5.   if msg = WM_NCCREATE then
  6.   begin
  7.     winCtrl := TWinControl(GetWindowLongPtrA(id, GWLP_USERDATA));
  8.     SetWindowLongPtrA(id, GWLP_USERDATA, NativeInt(winCtrl));
  9.     winCtrl.FHandle := id;
  10.   end else
  11.   winCtrl := TWinControl(GetWindowLongPtrA(id, GWLP_USERDATA));
  12.  
  13.   if Assigned(winCtrl) then
  14.   Result := winCtrl.HandleMessage (id, Msg, wParam, lParam) else
  15.   Result := DefWindowProcA        (id, Msg, wParam, lParam) ;
  16. end;
  17.  
  18. function TWinControl_Create(p: TWinControl): TWinControl; stdcall; export;
  19. var
  20.   _msg: TMsg;
  21.   cls : TWndClassEx;
  22.   wrd : WordBool;
  23.   hin : HINSTANCE;
  24. begin
  25.   {$ifdef DLLDEBUG}
  26.   writeln('TWinControl: Create');
  27.   {$endif DLLDEBUG}
  28.  
  29.   if p = nil then
  30.   begin
  31.     ShowError(sError_TWinControl_ref);
  32.     exit(nil);
  33.   end;
  34.  
  35.   hin := GetModuleHandleA(nil);
  36.  
  37.   FillChar(cls, sizeof(cls), 0);
  38.   cls.cbSize          := sizeof(cls);        { must be initialized   }
  39.  
  40.   if not GetClassInfoEx (hin, 'AppName', @cls) then
  41.   begin
  42.     with cls do
  43.     begin
  44.       style           := CS_BYTEALIGNCLIENT;
  45.       lpfnWndProc     := @GlobalWndProc;              { window class handler  }
  46.       cbClsExtra      := 0;
  47.       cbWndExtra      := 0;
  48.       hInstance       := hin;                         { qualify instance!     }
  49.       hIcon           := LoadIconA(hin, 'APPICON');
  50.       hCursor         := LoadCursorA(0, 'idc_arrow');
  51.       hbrBackground   := GetSysColorBrush(COLOR_WINDOW);
  52.       lpszMenuName    := 'APPMENU';                   { Menu name             }
  53.       lpszClassName   := 'AppName';                   { Window Class name     }
  54.       (*hIconSm         := LoadImage(
  55.       hin,
  56.       APPICON,
  57.       IMAGE_ICON,
  58.       16,
  59.       16,
  60.       LR_DEFAULTCOLOR*
  61.       );*)
  62.     end;
  63.  
  64.     // the line below is always 0 - why ? - not correct cls init
  65.     if RegisterClassExA(@cls) = 0 then
  66.     begin
  67.       ShowError('regois error.');
  68.       Halt(255);
  69.     end;
  70.   end;

I get no compiler error's or warnings
MS-IIS - Internet Information Server, Apache, PHP/HTML/CSS, MinGW-32/64 MSys2 GNU C/C++ 13 (-stdc++20), FPC 3.2.2
A Friend in need, is a Friend indeed.

 

TinyPortal © 2005-2018