Author Topic: user32 error  (Read 13224 times)

0 Members and 3 Guests are viewing this topic.

Charles Pegge

  • Guest
Re: user32 error
« Reply #30 on: March 26, 2018, 02:07:14 AM »
You would have to use byval any in your declaration. In O2, this would be ok for strings, but you would have to pass the strptr explicitly for char and asciiz.

Similarly, you would need to pass '@' pointers for RECT etc.

But Unprotyped is smarter, and less work  :)

Aurel

  • Guest
Re: user32 error
« Reply #31 on: March 28, 2018, 06:53:19 AM »
Yes Charles i agree that is less work of course
but i want to clear some things...
I found in PowerBasic  for Windows include folder WinAPI
4 type of declaration:

DECLARE FUNCTION SendMessageA LIB "User32.dll" ALIAS "SendMessageA" _
    (BYVAL hWnd AS DWORD, BYVAL dwMsg AS DWORD, BYVAL wParam AS DWORD, _
    BYVAL lParam AS LONG) AS LONG

DECLARE FUNCTION SendMessageW LIB "User32.dll" ALIAS "SendMessageW" _
    (BYVAL hWnd AS DWORD, BYVAL dwMsg AS DWORD, BYVAL wParam AS DWORD, _
    BYVAL lParam AS LONG) AS LONG

#IF %DEF(%UNICODE)
DECLARE FUNCTION SendMessage LIB "User32.dll" ALIAS "SendMessageW" _
    (BYVAL hWnd AS DWORD, BYVAL dwMsg AS DWORD, BYVAL wParam AS DWORD, _
    BYVAL lParam AS LONG) AS LONG
#ELSE
DECLARE FUNCTION SendMessage LIB "User32.dll" ALIAS "SendMessageA" _
    (BYVAL hWnd AS DWORD, BYVAL dwMsg AS DWORD, BYVAL wParam AS DWORD, _
    BYVAL lParam AS LONG) AS LONG
#ENDIF ' NOT %UNICODE                                             


Charles
I am now confused...  ::)
Which one is right or which one you use inside Bind()
I have problem when i use lParam as sys
then
sendmessage hsci, sci_settext ,0, strptr(tx)
simply not work , or in another word my char buffer is not recognized and scintilla not show text
if i use lParam as Any
then i must do this
sendmessage edit,wm_text,0 ,byval strptr(tx) -> tx is string type

do you maybe use sendmessageW in your bind() ?
This is absolutely crazy 

Arnold

  • Guest
Re: user32 error
« Reply #32 on: March 28, 2018, 07:10:37 AM »
Hi Aurel,

if you use corewin.inc why do you not simply use the unprototyped SendMessage function and apply the arguments given in the Win32 Help File:

LRESULT SendMessage(

    HWND hWnd,   // handle of destination window
    UINT Msg,   // message to send
    WPARAM wParam,   // first message parameter
    LPARAM lParam    // second message parameter
   );

HWND, WPARAM, LPARAM is sys, MSG is a value.

Roland

Charles Pegge

  • Guest
Re: user32 error
« Reply #33 on: March 28, 2018, 08:59:23 AM »
Hi Aurel,

I would simply reject all of those declarations. They cannot be used for a 64bit binary. Using CoreWin, MinWin, or the old bind blocks, resolves the problem, but you must also provide accurately defined types.

Unfortunately, just because something appears to work, it does not prove it is correct, and if it is incorrect, the program will fail under different conditions.

Mike Lobanovsky

  • Guest
Re: user32 error
« Reply #34 on: March 28, 2018, 11:07:27 AM »
Yessssss Roland! You nailed down both the problem and solution exactly! Bingo!

There are too many WinAPIs and user defined functions where the exact interpretation of function arguments would depend not so much on the function prototype but on other circumstances, and in this particular case, on what SendMessage()'s Msg value (i.e. the particular WM_... message) is!

This is where strongly typed function prototypes are nothing but pure evil: they won't let you pass WPARAM and LPARAM values flexibly but will require that you breed a bunch of SendMessage() aliases for all possible occasions.

Just use unprototyped SendMessage(), look up in MSDN what WPARAM and LPARAM args a particular WM_... message requires, and pass numeric literals or vars for direct (byval) args, or @numvars for (byref) arg addresses, or simple udtvar or strvar names (or strptr strvar) for byref UDTs and strings. Every MSDN page has the Parameters section that explains in plain English whether each argument the WinAPI expects is a literal (byval) value or a (byref) address.


What other declaration or prototype an intelligent human being would ever need?!