Compile error [Solved]

New to FreeBASIC? Post your questions here.
Nine
Posts: 2
Joined: Apr 09, 2020 18:58

Compile error [Solved]

Postby Nine » Apr 09, 2020 19:08

Hi, I just started with FreeBasic. I found this code but I am getting an error. Can someone tell me what is the problem ?

registerhotkey.bas(11) error 28: Expected pointer, before ')' in 'OrgWndProc = Cast( WNDPROC, GetWindowLong( hwnd, GWLP_WNDPROC))'

Code: Select all

#Include "windows.bi"

Dim As HWND hwnd
Dim Shared As WNDPROC OrgWndProc

Declare Function NewWndProc( hWnd   As HWND, uMsg   As UInteger, _
wParam As WPARAM, lParam As LPARAM) As LRESULT

Screen 18, 32
ScreenControl 2, Cast(Integer,hwnd)'fb.GET_WINDOW_HANDLE = 2
OrgWndProc = Cast( WNDPROC, GetWindowLong( hwnd, GWLP_WNDPROC))
SetWindowLong( hwnd, GWLP_WNDPROC, Cast(Integer, @NewWndProc))
SendMessage( hwnd, WM_USER+&h100, 0, 0)

Do
  Print "Test"
  Sleep 1000
Loop Until MultiKey(1)

Function NewWndProc( hWnd As HWND, uMsg As UInteger, _
  wParam As WPARAM, lParam As LPARAM) As LRESULT

  Select Case uMsg

    Case WM_USER+&h100
      If RegisterHotKey( hWnd, 99, MOD_CONTROL Or MOD_SHIFT , VK_E) = 0 Then 'CTRL + SHIFT + e
        EndDialog(hWnd, 0)
      End If
    Case WM_HOTKEY
      If wParam = 99 Then
          ShowWindow(hWnd,SW_SHOWNORMAL)
          SetForegroundWindow(hWnd)
          MessageBox(hWnd, "CTRL + SHIFT + e", "HOTKEY", MB_OK)
          Cls
      EndIf

    Case WM_DESTROY
      UnregisterHotKey( hwnd, 99)
      SetWindowLong( hWnd, GWLP_WNDPROC, Cast( Integer, @OrgWndProc))

  End Select

  Return CallWindowProc( OrgWndProc, hWnd, uMsg, wParam, lParam)
End Function
Last edited by Nine on Apr 10, 2020 19:07, edited 1 time in total.
grindstone
Posts: 737
Joined: May 05, 2015 5:35
Location: Germany

Re: Compile error

Postby grindstone » Apr 10, 2020 18:06

I can't reproduce that error. Code compiles and runs here (WinXP32, FB 1.05)
Josep Roca
Posts: 492
Joined: Sep 27, 2016 18:20
Location: Valencia, Spain

Re: Compile error

Postby Josep Roca » Apr 10, 2020 18:42

If you're compiling using the 64-bit compiler, use GetWIndowLongPtr and SetWindowLongPtr.
Nine
Posts: 2
Joined: Apr 09, 2020 18:58

Re: Compile error

Postby Nine » Apr 10, 2020 19:06

Josep Roca wrote:If you're compiling using the 64-bit compiler, use GetWIndowLongPtr and SetWindowLongPtr.


That was it. Thanks a lot.
MrSwiss
Posts: 3542
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Compile error [Solved]

Postby MrSwiss » Apr 10, 2020 19:14

That was it. Thanks a lot.

Yes, and it also shows, that OLD examples are pretty useless, with new FBC compiler versions.
(unless they've been updated, of course)

Return to “Beginners”

Who is online

Users browsing this forum: No registered users and 3 guests