Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting list of files #24

Merged
merged 5 commits into from Jan 8, 2023
Merged

Setting list of files #24

merged 5 commits into from Jan 8, 2023

Conversation

mchels
Copy link
Contributor

@mchels mchels commented Jan 4, 2023

I want to add setting files on the clipboard according to these links

https://stackoverflow.com/questions/25708895/how-to-copy-files-by-win32-api-functions-and-paste-by-ctrlv-in-my-desktop
https://forums.codeguru.com/showthread.php?565003-SetClipboardData()-to-Copy-File
https://forum.lazarus.freepascal.org/index.php?topic=51601.0
https://stackoverflow.com/questions/27278659/copy-a-file-to-clipboard-in-delphi
https://devblogs.microsoft.com/oldnewthing/20130520-00/?p=4313
https://learn.microsoft.com/en-us/windows/win32/shell/clipboard#cf_hdrop
https://github.com/luapower/winapi/blob/master/winapi/clipboard.lua#L187
https://learn.microsoft.com/en-us/windows/win32/api/shlobj_core/ns-shlobj_core-dropfiles
https://microsoft.github.io/windows-docs-rs/doc/windows/Win32/UI/Shell/struct.DROPFILES.html
https://microsoft.github.io/windows-docs-rs/doc/windows/Win32/Foundation/struct.BOOL.html
https://github.com/gabdube/native-windows-gui/blob/10f2ac484b25368abc286f4d90562c3a27f22595/native-windows-gui/src/events.rs
https://github.com/alex8088/clipboard-files/blob/master/src/clip_win.cc

I get an error in the test that I added, though:

C:\Users\UMRH\repos\clipboard-win>cargo test should_work_with_filelist -- --exact --nocapture
   Compiling clipboard-win v4.4.2 (C:\Users\UMRH\repos\clipboard-win)
    Finished test [unoptimized + debuginfo] target(s) in 2.60s
     Running unittests src\lib.rs (target\debug\deps\clipboard_win-accf31e6a3daf1f9.exe)

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running tests\formats.rs (target\debug\deps\formats-882388a362906242.exe)

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 2 filtered out; finished in 0.00s

     Running tests\test_clip.rs (target\debug\deps\test_clip-66edde24978329a6.exe)

running 1 test
0x9b75fef48
0x12cb0e047a0
0x12cb0dedcb0
20
0x12cb0dedcb0
48
error: test failed, to rerun pass '--test test_clip'

Caused by:
  process didn't exit successfully: `C:\Users\UMRH\repos\clipboard-win\target\debug\deps\test_clip-66edde24978329a6.exe should_work_with_filelist --exact --nocapture` (exit code: 0xc0000005, STATUS_ACCESS_VIOLATION)

Occasionally, I will get

(exit code: 0xc0000374, STATUS_HEAP_CORRUPTION)

instead of

(exit code: 0xc0000005, STATUS_ACCESS_VIOLATION)

so I suspect I am doing memory management wrong somehow. If anyone has any pointers (pun) on how to figure that part out, I would greatly appreciate it!

I had to disable no_std because I couldn't figure out how to get the code to run otherwise. Apologies for my rookie Rust skills.

Background: I am writing a file manager app in the tauri framework (https://tauri.app/) to learn rust. I come from a python background.

The funny thing is that the code above works for the first copy action in the sense that I am actually able to paste the file in Explorer. If I try to copy another file afterwards my Tauri app crashes with no stack trace

Copy link
Owner

@DoumanAsh DoumanAsh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left some comments which potentially might fix issue
I'll give it a better look tomorrow

Cargo.toml Outdated Show resolved Hide resolved
src/raw.rs Outdated Show resolved Hide resolved
src/raw.rs Outdated Show resolved Hide resolved
src/raw.rs Outdated Show resolved Hide resolved
src/raw.rs Show resolved Hide resolved
src/raw.rs Outdated Show resolved Hide resolved
@DoumanAsh
Copy link
Owner

@mchels I applied comments myself, please check

@DoumanAsh
Copy link
Owner

DoumanAsh commented Jan 5, 2023

Noticed there is some issue, let me try to see if I can write test for this code

@DoumanAsh
Copy link
Owner

@mchels I fixed memory corruption in my code, so now it should correctly set file from string.

Let me know how it looks to you.
I think for what you want it is better to have API that accepts list of strings, rather than single string

@mchels
Copy link
Contributor Author

mchels commented Jan 5, 2023

I think for what you want it is better to have API that accepts list of strings, rather than single string

Absolutely agree. The code I pushed was just what I was able to do myself.
I will take a look at the rest tomorrow. Thank you for looking into this!

@mchels
Copy link
Contributor Author

mchels commented Jan 8, 2023

@DoumanAsh I have pushed a commit that sets a list of strings rather than a single string. It seems to work for me.

@DoumanAsh DoumanAsh merged commit 4641eab into DoumanAsh:master Jan 8, 2023
@DoumanAsh
Copy link
Owner

I released version 4.5.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants