Results 1 to 8 of 8

Thread: SetWindowSubclass is not working.

  1. #1
    Member
    Join Date
    Aug 2015
    Location
    Keralam, India
    Posts
    118
    Rep Power
    17

    SetWindowSubclass is not working.

    Hi all,
    I am trying to subclass a button, But SetWindowSubclass is not working. The window starts and suddenly thinBasic.exe is stop working.
    Here is my function declarartions.
    Declare Function SetWindowSubclass Lib "Comctl32.dll" Alias "SetWindowSubclass"(ByVal hWnd As DWord,
                                                                                    Byref pfnSubclass As Long,
                                                                                    ByRef uIdSubclass as Dword,
                                                                                    Byval dwRefData Long) As word
                                                                                    
    
    Declare Function DefSubclassProc Lib "Comctl32.dll" Alias "DefSubclassProc"(ByVal hWnd As DWord,
                                                                                    Byval uMsg As Dword,
                                                                                    ByVal wParam as Dword,
                                                                                    ByVal lParam Long) As Long
                                                                                    
                                                                                  
    
    Declare Function RemoveWindowSubclass Lib "Comctl32.dll" Alias "RemoveWindowSubclass"(ByVal hWnd As DWord,
                                                                                    Byref pfnSubclass As Long,
                                                                                    Byval uIdSubclass as Dword) As Boolean
    
    And here is my function calling code.
    If Me.mHandle <> 0 Then    
      Dim fnPtr As Long = CodePtr(ButtonWndProc)   
      dim myPtr As Long = Varptr(Me) '// My tButton type
      Dim rst = SetWindowSubclass(Me.mHandle, fnPtr, globalBtnSubClassID, myPtr)    
      PrintL("Sublcass result - ", rst) '// This is printing 1. That means, function success
    EndIf
    
    Here is my SubclassProc.
    function ButtonWndProc(Byval hwnd As Dword, Byval message As Dword, Byval wParam As Dword, Byval lParam As Long, 
                            Byval uIdSubclass As Long, Byref dwRefData As Long) As Long
      printl("Button message - ", message)
      return DefSubclassProc(hwnd, message, wParam, lParam)  
    End Function
    
    And i found one weird behaviour of thinbasic interpreter. See this code.
    SetWindowSubclass(ByVal hWnd As DWord, Byref pfnSubclass As Long, ByRef uIdSubclass as Dword, Byval dwRefData Long)
    
    The value for "pfnSubclass " is CodePtr(ButtonWndProc). But somehow thinbasic interpreter didn't liked it the way we write the code. It wants us to write like this
    Dim fnPtr As Long = CodePtr(ButtonWndProc)
    
    Now, we can use the variable fnPtr inside the function. But to do this, thinbasic will inform us like "Parameter "hWnd" is expected as Byref but it is not passed as Byref"
    I suddenly surprised with this error message. But when i remove CodePtr(ButtonWndProc) from the parameter position and placed the "fnPtr" variable then interpreter says "Parameter "uIdSubclass " is expected as Byref but it is not passed as Byref" So i got the trick and i changed the Varptr(Me) from parameter position and use a varibale for it like this
    dim myPtr As Long = Varptr(Me)
    
    After doing this the function worked succesfully and give result 1. But thinBasic exe stopped working.

  2. #2
    Member
    Join Date
    Aug 2015
    Location
    Keralam, India
    Posts
    118
    Rep Power
    17
    @Eros

    I suspect CodePtr is the problem.
    Documentation says this.
    There are some IMPORTANT limitations:

    1. script function can have from zero to 4 BYVAL LONG or DWORD parameters

    2. script function must return a LONG or DWORD value

    This is the SubclassProc syntax. It has 6 parameters. Thats the problem.
    function ButtonWndProc(Byval hwnd As Dword, Byval message As Dword, Byval wParam As Dword, Byval lParam As Long, 
                            Byval uIdSubclass As Long, Byref dwRefData As Long) As Long
    

  3. #3
    thinBasic MVPs ReneMiner's Avatar
    Join Date
    Oct 2012
    Location
    Germany
    Age
    51
    Posts
    1,418
    Blog Entries
    1
    Rep Power
    156

    i tried something...

    maybe... i had to try... anyway, i am nosy too

    FUNCTION Provide_FuncPtr ALIAS "Provide_FuncPtr" () AS LONG

    even if no parameter you can try
    call from tb Provide_funcPtr Function?getPtr(your function)
    it should return a codepointer to a function that matches in the parameters to capture what this api/function sends.
    my function cann only call yours by its pointer and will not pass any parameters but will fill the variables
    so you probably have to name it callback function
    i put the buttonproc/parameters in the order they were into the callback-variables, here you see their order
    your first parameter should be in cbhndl and so dwrefdata will be cbwparam / position 6...


    ButtonWndProc(Byval hwnd As Dword, Byval message As Dword, Byval wParam As Dword, Byval lParam As Long,
    Byval uIdSubclass As Long, Byref dwRefData As Long) As Long


    DECLARE FUNCTION  thinBasic_FunctionSimpleCall_ByPtr                _
                              LIB "thinCore.DLL"                          _
                              ALIAS "thinBasic_FunctionSimpleCall_ByPtr"  _
                              (                                           _
                                BYVAL FunctionPtr AS LONG               , _  '---PTR to function returned by thinBasic_FunctionGetPtr or other way
                                OPTIONAL                                  _
                                BYVAL ptrEXT      AS EXT PTR            , _  '---Used to get back from the called function a numeric value
                                BYVAL ptrSTR      AS STRING PTR         , _  '---Used to get back from the called function a string value
                                BYVAL IsCallBack  AS LONG               , _
                                BYVAL lCBHNDL     AS LONG               , _
                                BYVAL lCBMSG      AS LONG               , _
                                BYVAL lCBCTL      AS LONG               , _
                                BYVAL lCBCTLMSG   AS LONG               , _
                                BYVAL lCBLPARAM   AS LONG               , _
                                BYVAL lCBWPARAM   AS LONG               , _
                                BYVAL lCBNMCODE   AS LONG               , _
                                BYVAL lCBNMHDR    AS LONG               , _
                                BYVAL lCBNMHWND   AS LONG               , _
                                BYVAL lCBNMID     AS LONG                 _
                              ) AS LONG
    
    however i made 3 attempts, if you pass no parameter besides your function_getPtr (put that into a variable of type long or dword)
    then it tries the byref-thing
    give 1 as second parameter then it will grab the pointer of the byref received dwrefdata and dwrefdata should be a memory_location
    any other number as second parameter uses all 10 callback-variables / optional. i.e. you can use 10 or 0 and any number inbetween.
    tell me if it does at least something...
    it requires i guess only to declare FUNCTION Provide_FuncPtr ALIAS "Provide_FuncPtr" () AS LONG

    even it has no parameters visible it checks what follows the function call. i guess. i hope... its an experiment...
    Attached Files Attached Files
    Last edited by ReneMiner; 12-04-2021 at 01:31.
    running thinBasic in HP Pavillon Desktop 590 a0xxx 8GB Ram AMD A6-9225 Radeon R4 5Compute Cores 2C+3G @2.6GHz

    OS: downgraded again to Windows 10 Enterprise x64 10.0.18363 Build 18363 (1909)
    (alternate OS: modified WinRE - boot from a fake ramdisk - currently in "reconstruction mode")

  4. #4
    Member
    Join Date
    Aug 2015
    Location
    Keralam, India
    Posts
    118
    Rep Power
    17
    @ReneMiner,
    Thans a lot for the help. I will sure check your code sample. First of all, let me study your approach. I will come up with my questions. Thanks again.

  5. #5
    thinBasic MVPs ReneMiner's Avatar
    Join Date
    Oct 2012
    Location
    Germany
    Age
    51
    Posts
    1,418
    Blog Entries
    1
    Rep Power
    156
    yyou're welcom, my pleasure.
    I found lately a free - bit older verrsion of powerbasic. that was the first attempt to create somewhat like a module.
    Astonishing how many thing of thinbasic are similar to powerbasic. Guess i will bring many ideas to test and i repeatedly run into hindrances but as a wise man said
    '___________________________________________________________________________
    
    
    '  the higher your target the more you will grow when you reach for it
    '___________________________________________________________________________
    
    running thinBasic in HP Pavillon Desktop 590 a0xxx 8GB Ram AMD A6-9225 Radeon R4 5Compute Cores 2C+3G @2.6GHz

    OS: downgraded again to Windows 10 Enterprise x64 10.0.18363 Build 18363 (1909)
    (alternate OS: modified WinRE - boot from a fake ramdisk - currently in "reconstruction mode")

  6. #6
    Member
    Join Date
    Aug 2015
    Location
    Keralam, India
    Posts
    118
    Rep Power
    17
    Free version of power basic ? Is it ? Does Power Basic have Unicode support ?,
    These are the things I attracted in a programing language.
    1. Is it Free ? (At least a limited free version is enough)
    2. Does it support Basic family syntax ? (Not necessary, I like D also)
    3. Does it produce an EXE file ?
    4. C binding or Win32 API support.
    My assumption about PB and PureBasic was that they are proprietary languages.
    Well, Do you know the current status of FBSL ? Is it active. I think their forum is down. mike lobanovsky was the moderator of the forum and maintainer of FBSL.
    Last edited by kcvinu; 15-04-2021 at 11:32.

  7. #7
    thinBasic MVPs ReneMiner's Avatar
    Join Date
    Oct 2012
    Location
    Germany
    Age
    51
    Posts
    1,418
    Blog Entries
    1
    Rep Power
    156
    i think its able to handle unicode data but the ide works using ANSI by default. it was a german page where i found it you can try
    has the archive password-sealed but it's simply 123, has compiler that creates exe or dll if you like
    thinbasic is i think extra-ordinary-compatible.you should unpack the shipped sdk.zip from thinBasic-distribution and you can try yourself. the download i've found was here. its maybe not up to date but it does not matter as you can just compile what you need to be done - like creating your addresses to have compiled codepointers and i hope for thinBasic soon to allow the same as for the freebasic-compiler; to write the powerbasic-section between
    #Compiled language="Powerbasic" 
    
    'pb -code here 
    
    #EndCompiled
    
    even it might not be possible - but i am not sure - to ship this old pb-compiler - i think there might be copyright-issues...

    But as anyone can download it and create the settings that are required in
    "c:\thinBasic\compilers\thinBasic_compilers.ini"
    it might work already.

    Eros did not mention anything yet about configuration-possibilies nor -requirements.
    If you follow the freebasic-pattern it could very well be already possible to integrate any other compiler this way.

    if not yet possible you can create dlls for use in thinbasic for sure

    i think data exchange between thinBasic and powerbasic works much better than with freebasic since you will not need 3 helper-formats and 2 additional handlers just to transfer a string which disables to use them byref, not to mention arrays

    __________________________________________________________________________________________________
    ... anyway the inflexibility of freebasic to automatically detect what type were to use for something and the required pointer-artistic - no do not name it arithmetic! its a pain in the behind with the rule that all rules are exceptions -except the exceptions that are to except from the exceptional rules- disqualifies freebasic for me to use it.
    __________________________________________________________________________________________________

    @Eros

    have a look at cloakersmokers relax compiler. it derives from an ancient autohotkey-compiler and repeatedly compiled
    itself many times already. relax is a very fast, straighforward language has only a couple of commands / looks a bit as C but is not C.
    not required to have semicolons at the end of statements etc.
    Were it possible to use this compiler and to use relax-language between #compiled and #endcompiled?
    Anyway for all #compiled-#endcompiled: wouldnt it be more useful to allocate a buffer @ heap for data-exchange since all windows apps have the ability to use heap-memory?
    Last edited by ReneMiner; 16-04-2021 at 04:57.
    running thinBasic in HP Pavillon Desktop 590 a0xxx 8GB Ram AMD A6-9225 Radeon R4 5Compute Cores 2C+3G @2.6GHz

    OS: downgraded again to Windows 10 Enterprise x64 10.0.18363 Build 18363 (1909)
    (alternate OS: modified WinRE - boot from a fake ramdisk - currently in "reconstruction mode")

  8. #8
    thinBasic MVPs ReneMiner's Avatar
    Join Date
    Oct 2012
    Location
    Germany
    Age
    51
    Posts
    1,418
    Blog Entries
    1
    Rep Power
    156

    Post

    Update:

    i tried and completed the procedure of making all necessary additions and settings that are possible to let thinBasic use #compiled...#endcompiled and do the same as it would do to with freebasic now with powerbasic, but i expected too much.
    It wil not work, even if i overwrite the compiler-ini-settings of freebasic / it will not do it and only use freebasic as long i try

    #compiled language "Powerbasic" or
    #compiled "language=Powerbasic" or
    #compiled "language", "Powerbasic" ,

    it will not accept different modes and use freebasic ALWAYS while keyword #COMPILED is present.

    I tried using RawText / End RawText and discovered 2 Bugs concerning Rawtext but had no success yet concerning creating
    the dll during runtimes of the TB/script.

    I created an issue in support for that.
    Last edited by ReneMiner; 17-04-2021 at 00:53.
    running thinBasic in HP Pavillon Desktop 590 a0xxx 8GB Ram AMD A6-9225 Radeon R4 5Compute Cores 2C+3G @2.6GHz

    OS: downgraded again to Windows 10 Enterprise x64 10.0.18363 Build 18363 (1909)
    (alternate OS: modified WinRE - boot from a fake ramdisk - currently in "reconstruction mode")

Similar Threads

  1. TBASS_ChannelSeconds2Bytes not working?
    By martin in forum TBASS
    Replies: 6
    Last Post: 10-11-2014, 09:32
  2. tB + VS working together?
    By LCSims in forum thinBasic General
    Replies: 3
    Last Post: 10-07-2012, 21:28
  3. What are you working on?
    By Michael Clease in forum TBGL General
    Replies: 17
    Last Post: 02-02-2008, 07:11
  4. FreeBasic SDK: first working example
    By ErosOlmi in forum Module SDK (Freebasic version)
    Replies: 14
    Last Post: 23-09-2007, 08:26

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •