Hello:
I need help and was wondering if someone could help me understand how to reference a Win32 API UDT in my code.
The UDT found in "windows.inc" is:
TYPE MSG
DEF hwnd AS INT
DEF message AS INT
DEF wParam AS INT
DEF lParam AS INT
DEF time AS INT
DEF pt AS POINT
ENDTYPE
The Win32 API procedure I'm calling is:
DECLARE IMPORT, _DispatchMessage ALIAS DispatchMessageA(lpMsg AS MSG),INT
I know I have to use the underline form of the call in my code, but I don't understand how to set up and reference the MSG type in the "windows.inc" file.
I also know how to setup and reference UDT's in my main program. I don't understand how to use them in my code when they are referenced in an include file.
Thanks, Logman :-\
Logman,
Why are you trying to use DispatchMessage?
The only place it is valid to call that is within a message processing loop, where the MSG structure gets filled in by either PeekMessage or GetMessage. Emergence handles this for you with the WAITUNTIL and WAIT commands.
Paul.
Paul:
I'm not using DispatchMessage for anything. It was the first handy example of an API call with a quick and dirty example of a UDT-type parameter that I could find in "windows.inc"--just a simple example involving only one parameter.
I can do UDT's using dot notation in a main program, but I don't understand how to set them up for an API call. From my perspective, if I can understand how to do a simple API structured variable setup, then I can apply it to more complicated API calls that I really need to use.
If there's a better example, that's okay. I only want to learn how to set them up so I can pass data to structured variables in API calls.
Logman
TYPE MSG
DEF hwnd AS INT
DEF message AS INT
DEF wParam AS INT
DEF lParam AS INT
DEF time AS INT
DEF pt AS POINT
ENDTYPE
DECLARE IMPORT, _DispatchMessage ALIAS DispatchMessageA(lpMsg AS MSG),INT
def myvar as MSG
def ret as int
def mypoint as point
mypoint.x=100
mypoint.y=200
myvar.hwnd =win.hwnd
myvar.wParam=23
myvar.lParam=4
myvar.time= 123
myvar.pt =mypoint
ret = _DispatchMessage (myvar )
Larry
Thanks Larry.
Looks almost like doing UDT's in a main program. Interestingly, the MSG type also contains a POINT UDT. Your example clears it up for me.
Logman
I appreciate your help, but have one more question about API constants.
The code below creates a thread. The call to _CreateThread ALIAS CreateThread() incorporates a parameter called dwCreationFlags, which uses a CONST declared in the 'windows.inc' file. The CONST is CREATE_SUSPENDED.
The program won't compile unless I declare this particular constant in my main program--as shown on line 1.
Is this correct because once declared, the program runs perfectly? I assume that since I'm not using $INCLUDE "windows.inc", the main program has no visibility regarding constants declared in the API file. Therefore, they must be declared by me in my main program.
CONST CREATE_SUSPENDED = 0x4
TYPE SECURITY_ATTRIBUTES
DEF nLength AS INT
DEF lpSecurityDescriptor AS INT
DEF bInheritHandle AS INT
ENDTYPE
DECLARE IMPORT, _CreateThread ALIAS CreateThread(_
lpThreadAttributes AS SECURITY_ATTRIBUTES,_
dwStackSize AS INT,_
lpStartAddress AS POINTER,_
lpParameter AS POINTER,_
dwCreationFlags AS INT,_
lpThreadId AS POINTER),INT
DECLARE IMPORT, _GetLastError ALIAS GetLastError(),INT
DECLARE IMPORT, _ResumeThread ALIAS ResumeThread(hThread AS INT),INT
DECLARE IMPORT, _CloseHandle ALIAS CloseHandle(hObject AS INT),INT
DEF mySA as SECURITY_ATTRIBUTES
mySA.nLength = 8
mySA.lpSecurityDescriptor = 0
mySA.bInheritHandle = 0
INT nData
INT nTemp
INT hThread
OPENCONSOLE
hThread = _CreateThread(mySA,0,&Process_Listener,&nData,CREATE_SUSPENDED,&nTemp)
IF (hThread = NULL)
err = _GetLastError()
PRINT "Thread 1 could not be created!\n"
ELSE
_ResumeThread(hThread)
ENDIF
SUB Process_Listener(param AS POINTER),INT
PRINT "Start Process A >"
FOR i = 1 to 6
PRINT " Thread Loop-",i
NEXT i
PRINT "End Process A >"
RETURN 0
ENDSUB
PRINT "Start Main Loop >"
FOR i = 1 to 6
PRINT " Main Loop-",i
NEXT i
PRINT "End Main Loop >"
_CloseHandle(hThread)
DO
UNTIL INKEY$ <> ""
CLOSECONSOLE
END
Thanks to all who have helped me transition to EBasic.
Logman
that is correct
Larry
Larry:
Thanks for the help. I think I have a good hHandle :D on the Win32 API now.
I'm not used to a language having such a great built-in Win API capability. Somebody has obviously spent a lot of time porting it over for EBasic use.
Logman