flat assembler
Message board for the users of flat assembler.

Index > Tutorials and Examples > da2a threaded drag and drop win32

Author
Thread Post new topic Reply to topic
Ali.Z



Joined: 08 Jan 2018
Posts: 820
Ali.Z 24 Jan 2025, 06:08
a simple win32 utility that converts windows CR,LF to unix LF.
using threads to process drag and drop event, which doesnt block the gui from processing events.
it spawns n-threads, where n is count of total files dropped.
the dropped files must be null terminated ansi strings.
use at your own risk, aliz. Twisted Evil

update1: copy paste errors.
update2: fix textout transparency.


Description:
Download
Filename: da2a.zip
Filesize: 3.21 KB
Downloaded: 84 Time(s)


_________________
Asm For Wise Humans
Post 24 Jan 2025, 06:08
View user's profile Send private message Reply with quote
Mat Quasar



Joined: 15 Dec 2024
Posts: 87
Mat Quasar 24 Jan 2025, 11:07
Nice!

Code:
proc DialogProc
 .wmdropfiles:
    invoke    CreateRemoteThread,,,dragdrop
.wminitdialog:
    invoke    DragAcceptFiles
endp

proc dragdrop
    invoke    DragQueryFile
    invoke    VirtualAllocEx
 .spawn:
    invoke    CreateRemoteThread,,,da2a
 .notalone:
    invoke    WaitForMultipleObjectsEx
    invoke    VirtualFreeEx
 .bye:
    invoke    DragFinish
endp

proc da2a
    invoke    DragQueryFile
    stdcall   fs_read

.done:
    stdcall   fs_write
    invoke    VirtualFreeEx
endp

proc fs_read
    invoke    CreateFile
    invoke    GetFileSize
    invoke    VirtualAllocEx
    invoke    ReadFile
    invoke    CloseHandle
endp

proc fs_write
    invoke    CreateFile
    invoke    WriteFile
    invoke    CloseHandle
endp
    
Post 24 Jan 2025, 11:07
View user's profile Send private message Reply with quote
Ali.Z



Joined: 08 Jan 2018
Posts: 820
Ali.Z 24 Jan 2025, 21:58
the thing can be generlized to:
a - for every drop message spawn a thread that:
- 1 - query number of dropped files
- 2 - allocate memory that holds drop context structure to be passed to the thread
- 3 - spawn child thread and pass it its own drop context
b - complete last job, wait for all child threads and only then free memory

even tho the source is included, i wouldnt generally recommend this design, i can refactor this multiple times to produce even better versions. (e.g.1 divide number of files and give each thread multiple files, e.g.2 let main thread query all dropped file names and free memory and only then spawn childs to process them, e.g.3 use async file i/o, etc.)
regardless, it is a good example for others to learn about threading.

_________________
Asm For Wise Humans
Post 24 Jan 2025, 21:58
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.