[Solved] How to trick the compiler?

Just starting out? Need help? Post your questions and find answers here.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: How to trick the compiler?

Post by RASHAD »

Did not test it but it worth to try
https://stackoverflow.com/questions/22 ... indows-xp

Someone suggested to use "user32.dll" of Windows > vista
Egypt my love
ZX80
Enthusiast
Enthusiast
Posts: 330
Joined: Mon Dec 12, 2016 1:37 pm

Re: How to trick the compiler?

Post by ZX80 »

@RASHAD
Thanks for trying to help. It is interesting, but may be suspicious. Unfortunately, I have to go now. Thanks again.

P.S. Anyway, I'm glad we covered this issue here. Perhaps Fred will read this thread too and find it useful.
User avatar
chi
Addict
Addict
Posts: 1028
Joined: Sat May 05, 2007 5:31 pm
Location: Linz, Austria

Re: How to trick the compiler?

Post by chi »

I have no problems running your XP code (EventDropFiles()) on Win8.1 x64 (VM). Are you sure the crash is related to PB's DragAndDrop functions?
Et cetera is my worst enemy
ZX80
Enthusiast
Enthusiast
Posts: 330
Joined: Mon Dec 12, 2016 1:37 pm

Re: How to trick the compiler?

Post by ZX80 »

chi wrote: Sun Sep 19, 2021 2:41 pm ...Are you sure the crash is related to PB's DragAndDrop functions?
I'm not sure if the reason is PB, but... on a real system, I saw a crossed out circle when dragging objects (with admin rights). I read this topic. A similar problem. So I'm not deceiving you. Now there is no way to test "on a live" 8.1 system. I was interested in combining these two methods in one file(cheat the mechanism). Apparently this will not be possible. Okay. Let's leave two files.
AZJIO
Addict
Addict
Posts: 1318
Joined: Sun May 14, 2017 1:48 am

Re: How to trick the compiler?

Post by AZJIO »

Code: Select all

OSVersion()
?
If you need administrator rights, then "Drag-and-drop" will not work. Try using the transfer source with the same rights, i.e. you need to install QDir run it with administrator rights and then the files will be dragged.
User avatar
jacdelad
Addict
Addict
Posts: 1432
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: How to trick the compiler?

Post by jacdelad »

@ZX80: Regarding your post of yesterday I don't think both implementations are hard to combine:

Code: Select all

Macro MyStuffWithTheDroppedFiles()
  ClearGadgetItems(0)
  ForEach DroppedFiles()
    AddGadgetItem(0, -1, DroppedFiles() + #LF$ + "")
  Next
EndMacro

Define NewList DroppedFiles.s(),is_win_xp=Bool(OSVersion()=#PB_OS_Windows_XP)
SecondColumnWidth = 250
wflags = #PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_SizeGadget|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget

If OpenWindow(0, #PB_Ignore, #PB_Ignore, 600, 300, "test", wflags)
  LIG_ID = ListIconGadget(0, 5, 5, 590, 290, "parameter", 600 - 15 - SecondColumnWidth, #PB_ListIcon_MultiSelect|#PB_ListIcon_FullRowSelect|#PB_ListIcon_GridLines)
  AddGadgetColumn(0, 1, "value", SecondColumnWidth)
  
  If is_win_xp
    EnableGadgetDrop(0, #PB_Drop_Files, #PB_Drag_Copy | #PB_Drag_Move)
  Else
    ChangeWindowMessageFilter_(#WM_DROPFILES, #MSGFLT_ADD)
    ChangeWindowMessageFilter_(#WM_COPYDATA, #MSGFLT_ADD)
    ChangeWindowMessageFilter_(73, #MSGFLT_ADD)          
    SetWindowLongPtr_(WindowID(0), #GWL_EXSTYLE, GetWindowLongPtr_(WindowID(0), #GWL_EXSTYLE) | #WS_EX_ACCEPTFILES)
  EndIf
  
  Repeat
    Select WaitWindowEvent()
      Case #WM_DROPFILES;Drop on Vista+
        Dropped = EventwParam()
        Num = DragQueryFile_(Dropped, -1, "", 0)
        If Num
          ClearList(DroppedFiles())
          For i=0 To Num-1
            Size = DragQueryFile_(Dropped, i, 0, 0)
            Object$ = Space(Size)
            DragQueryFile_(Dropped, i, Object$, Size+1)
            AddElement(DroppedFiles())
            DroppedFiles() = Object$
          Next
          DragFinish_(Dropped)
          MyStuffWithTheDroppedFiles()
        EndIf
      Case #PB_Event_GadgetDrop;Dropped on XP
        Object$ = EventDropFiles()
        If Object$
          Num = CountString(Object$, Chr(10)) + 1
          ClearList(DroppedFiles())
          For i=1 To Num
            AddElement(DroppedFiles())
            DroppedFiles() = StringField(Object$, i, Chr(10))
          Next
          MyStuffWithTheDroppedFiles()
        EndIf
      Case #PB_Event_CloseWindow
        Break
    EndSelect
  ForEver
EndIf
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
User avatar
chi
Addict
Addict
Posts: 1028
Joined: Sat May 05, 2007 5:31 pm
Location: Linz, Austria

Re: How to trick the compiler?

Post by chi »

Following code works on all my VM's (x86/x64, with/without admin privileges) and doesn't crash on XP

Code: Select all

Procedure _ChangeWindowMessageFilter(msg, flag) : EndProcedure
Prototype _ChangeWindowMessageFilter(msg, flag) 

user32 = OpenLibrary(#PB_Any, "user32")
ChangeWindowMessageFilter__._ChangeWindowMessageFilter = GetFunction(user32, "ChangeWindowMessageFilter")
If ChangeWindowMessageFilter__ = 0 : ChangeWindowMessageFilter__ = @_ChangeWindowMessageFilter() : EndIf

NewList DroppedFiles.s()

SecondColumnWidth = 250
wflags = #PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_SizeGadget|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget

If OpenWindow(0, #PB_Ignore, #PB_Ignore, 600, 300, "test", wflags)
  LIG_ID = ListIconGadget(0, 5, 5, 590, 290, "parameter", 600 - 15 - SecondColumnWidth, #PB_ListIcon_MultiSelect|#PB_ListIcon_FullRowSelect|#PB_ListIcon_GridLines)
  AddGadgetColumn(0, 1, "value", SecondColumnWidth)
  
  ChangeWindowMessageFilter__(#WM_DROPFILES, #MSGFLT_ADD)
  ChangeWindowMessageFilter__(#WM_COPYDATA, #MSGFLT_ADD)
  ChangeWindowMessageFilter__($49, #MSGFLT_ADD)  
  
  SetWindowLongPtr_(WindowID(0), #GWL_EXSTYLE, GetWindowLongPtr_(WindowID(0), #GWL_EXSTYLE) | #WS_EX_ACCEPTFILES)
  
  Repeat
    Event  = WaitWindowEvent()
    Window = EventWindow()
    
    If Event = #WM_DROPFILES
      Dropped = EventwParam()
      Num = DragQueryFile_(Dropped, -1, "", 0)
      If Num
        ClearList(DroppedFiles())
        For i=0 To Num-1
          Size = DragQueryFile_(Dropped, i, 0, 0)
          Object$ = Space(Size)
          DragQueryFile_(Dropped, i, Object$, Size+1)
          AddElement(DroppedFiles())
          DroppedFiles() = Object$
        Next
        DragFinish_(Dropped)
        
        ClearGadgetItems(0)
        ForEach DroppedFiles()
          AddGadgetItem(0, -1, DroppedFiles() + #LF$ + "")
        Next
      EndIf
  
    ElseIf Event = #PB_Event_CloseWindow
      Exit = #True
    EndIf
  Until Exit
EndIf

If IsLibrary(user32)
  CloseLibrary(user32)
EndIf
Et cetera is my worst enemy
ZX80
Enthusiast
Enthusiast
Posts: 330
Joined: Mon Dec 12, 2016 1:37 pm

Re: How to trick the compiler?

Post by ZX80 »

@AZJIO and jacdelad

What you say is all theory. In practice, things are different. Of course I know about OSVersion(). I have also tried my own code similar to jacdelad's code. But it didn't work. Everything is more cunning and subtle here. This is not easy to do, as it might seem at first glance. You can't just put such a condition. The fact that there is a ChangeWindowMessageFilter_ in the source code stops the program (on real XP system). Regardless of the availability of such a condition. This is what I tried to explain.

I didn't answer before because I didn't want to make it unfounded/unconfirmed. I waited until I had access to a real XP system for test the codes suggested here. Well... As expected, jacdelad's code failed. BUT! The code provided by chi worked on a real XP system. I'm surprised that this is possible.

@chi
You won! Thanks a lot!
Just one slight inconvenience. The previously opened library will not close automatically? In the code, I have several places with hard End. Writing the same thing every time is bad style. Can a macro be used to close the library? Thanks again. The topic can be considered closed/resolved.
User avatar
jacdelad
Addict
Addict
Posts: 1432
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: How to trick the compiler?

Post by jacdelad »

Well, I just combined your code and it should execute the right one on the right system. If you say it doesn't work, I won't call you a lier.
But can you explain to me why a function that is not called affects the program at all? From what I understand about your last post, even if the part with ChangeWindowMessageFilter_ is not called its pure presence breaks the program? I've never encountered such a behaviour with any function I use.
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
ZX80
Enthusiast
Enthusiast
Posts: 330
Joined: Mon Dec 12, 2016 1:37 pm

Re: How to trick the compiler?

Post by ZX80 »

jacdelad wrote: Tue Sep 21, 2021 3:43 pm From what I understand about your last post, even if the part with ChangeWindowMessageFilter_ is not called its pure presence breaks the program?
Exactly.
jacdelad wrote: Tue Sep 21, 2021 3:43 pm But can you explain to me why a function that is not called affects the program at all?
Sorry, I cannot explain this. Maybe someone else.

P.S. Tomorrow I will be able to access XP. I can write only this line to the source and try to compile (F5). My bad. I had to do it today. Sorry.
P.S.2. Anyway, thanks to everyone who answered my question.
AZJIO
Addict
Addict
Posts: 1318
Joined: Sun May 14, 2017 1:48 am

Re: [Solved] How to trick the compiler?

Post by AZJIO »

jacdelad

Code: Select all

Case #WM_DROPFILES;Drop on Vista+
...
Case #PB_Event_GadgetDrop;Dropped on XP
Isn't there WM_DROPFILES in Windows XP?
Isn't #PB_Event_GadgetDrop present in Vista+?
Should the OS flag be used here?

ZX80
If the function is not called, it cannot affect.
User avatar
jacdelad
Addict
Addict
Posts: 1432
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: [Solved] How to trick the compiler?

Post by jacdelad »

Well yes, after the "Case #Whatever" should be a "If my_os_version=xp...". Also I don't know if #WM_DROPFILES and #PB_Event_GadgetDrop conflict each other. My fault.
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
User avatar
chi
Addict
Addict
Posts: 1028
Joined: Sat May 05, 2007 5:31 pm
Location: Linz, Austria

Re: [Solved] How to trick the compiler?

Post by chi »

ZX80 wrote: Tue Sep 21, 2021 3:39 pm Just one slight inconvenience. The previously opened library will not close automatically? In the code, I have several places with hard End. Writing the same thing every time is bad style. Can a macro be used to close the library?
In theory, the OS is freeing the dll when the process terminates... But you have to decide for yourself ;)
jacdelad wrote: Tue Sep 21, 2021 3:43 pm But can you explain to me why a function that is not called affects the program at all? From what I understand about your last post, even if the part with ChangeWindowMessageFilter_ is not called its pure presence breaks the program? I've never encountered such a behaviour with any function I use.
Check out the differences between load-time-dynamic-linking and run-time-dynamic-linking
Et cetera is my worst enemy
Post Reply