Problem Wrapping Functions - 'not declared in this scope'

Previous topic - Next topic

Moebius

Hi everyone,

When I try to compile the code at the bottom of the post, the compiler reports that both inline functions were 'not declared in this scope'.  I have no idea as to how I can avoid this, and I thought that I've followed the tutorial in the FAQ perfectly...

Anyway, of course I can avoid this by calling the declared functions in the main program, but according to the tutorial, one should be able to call declared functions inside GLB functions without scope errors.

I have two queries:
- Can the scope issues be avoided WITHOUT doing something like calling the declared functions in the main code or declaring them at the start of the function?
- Will redeclaring the functions every time 'MoveMouseMiddle()' (i.e. sticking the declarations at the start of the function) cause the program to reload those DLL functions every time?

Thanks in advance  :nw:

Code (glbasic) Select
TYPE DECL_POINT
x%
y%
ENDTYPE
INLINE
DECLARE(ClientToScreen,"user32.dll",(void*, DECL_POINT*),int);
DECLARE(SetCursorPos,"user32.dll",(long x, long y),int);
ENDINLINE
//You can change 'Width' and 'Height' to constants if you wont change the project size - should be faster to do so.
GLOBAL MyPOINT AS DECL_POINT
GETSCREENSIZE MyPOINT.x, MyPOINT.y
MyPOINT.x = MyPOINT.x / 2
MyPOINT.y = MyPOINT.y / 2


FUNCTION MoveCursorMiddle:
INLINE
ClientToScreen(GLBASIC_HWND(), &MyPOINT);
SetCursorPos(MyPOINT.x, MyPOINT.y);
ENDINLINE
ENDFUNCTION

Endless Loop: n., see Loop, Endless.
Loop, Endless: n., see Endless Loop.
- Random Shack Data Processing Dictionary

Kitty Hello

Code (glbasic) Select

SYSTEMPOINTER TRUE


// OK, we need a structure holding 2 32bit ints:
TYPE DECL_POINT
x%
y%
ENDTYPE

// now, get the windows API functions as if they were real GLBasic functions
// -> we still need inline when we deal with pointers!
// That only works for C-Runtime and Windows API function (stuff I link against)
IMPORT "C" int __stdcall SetCursorPos(int x, int y)
IMPORT "C" int __stdcall ClientToScreen(void*, void*)



WHILE TRUE
IF MOUSEAXIS(3) // Click
LOCAL scx%, scy%
GETSCREENSIZE scx%, scy%

// Convert local (screen) point to desktop point
LOCAL mypt AS DECL_POINT
mypt.x=scx%/2
mypt.y=scy%/2

INLINE
ClientToScreen(GLBASIC_HWND(), &mypt);
ENDINLINE
// put the cursor there
SetCursorPos(mypt.x, mypt.y)
ENDIF
SHOWSCREEN
WEND


Moebius

My code is returned working, with comments!   =D
Thanks a bunch!  GLBasic reigns supreme  =D
Endless Loop: n., see Loop, Endless.
Loop, Endless: n., see Endless Loop.
- Random Shack Data Processing Dictionary