![]() |
|
[C#] NativeClipboard.cs | Read/Write clipboard text | 64 and 32-bit | Console or GUI - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [C#] NativeClipboard.cs | Read/Write clipboard text | 64 and 32-bit | Console or GUI (/showthread.php?tid=5855054) |
NativeClipboard.cs | Read/Write clipboard text | 64 and 32-bit | Console or GUI - gigajew - Jun 27, 2018 This is my sweet clipboard class. Enjoy it! Supports both 32- and 64-bit. And it also supports GUI or no GUI. ![]() RE: NativeClipboard.cs | Read/Write clipboard text | 64 and 32-bit | Console or GUI - 0xDEAD10CC - Jun 30, 2018 Code internal sealed class NativeClipboardLol. Also, I think I've seen some implementations of this on HF before. You really should be taking more care with unmanaged resources and functions to free those resources though. try/finally for example. No idea why you need a redundant message loop too, and no reason this couldn't have been a static class, and GlobalAlloc should probably specify the GHND flag rather than relying on memory to be zero'd. RE: NativeClipboard.cs | Read/Write clipboard text | 64 and 32-bit | Console or GUI - kevy42 - Jun 30, 2018 iv been trying to do this myself for ages, finally got a crude version going than saw this. looks 100x better than mine XD, nice share RE: NativeClipboard.cs | Read/Write clipboard text | 64 and 32-bit | Console or GUI - Washi - Jun 30, 2018 Just a question: What advantages brings your class that the Clipboard class built into the .NET framework does not provide? RE: NativeClipboard.cs | Read/Write clipboard text | 64 and 32-bit | Console or GUI - 0xDEAD10CC - Jun 30, 2018 (Jun 30, 2018 01:16 PM)Washi Wrote: Just a question: What advantages brings your class that the Clipboard class built into the .NET framework does not provide? One of them: Quote:The Clipboard class can only be used in threads set to single thread apartment (STA) mode. To use this class, ensure that your Main method is marked with the STAThreadAttribute attribute. I wouldn't know whether to call it an "advantage" but it's not a limitation at least. Runs fine in [MTAThread] context. Here's some of my modifications to the code though: Code internal static class NativeClipboardI don't see how the message loop was necessary, but even if it was you could have just thrown the call in the static constructor... RE: NativeClipboard.cs | Read/Write clipboard text | 64 and 32-bit | Console or GUI - int - Jul 2, 2018 (Jun 30, 2018 01:16 PM)Washi Wrote: Just a question: What advantages brings your class that the Clipboard class built into the .NET framework does not provide? was just thinking this. RE: NativeClipboard.cs | Read/Write clipboard text | 64 and 32-bit | Console or GUI - FryPan - Jul 2, 2018 (Jun 30, 2018 01:24 PM)0xDEAD10CC Wrote: One of them: Who wants to access clipboard using threads? This is a rare occasion RE: NativeClipboard.cs | Read/Write clipboard text | 64 and 32-bit | Console or GUI - 0xDEAD10CC - Jul 2, 2018 (Jul 2, 2018 04:07 PM)FryPan Wrote: Who wants to access clipboard using threads? This is a rare occasion I was just pointing it out, native calls like in the class above are probably going to be faster than the Clipboard class anyways because the .NET framework internally does a lot more checking and stuff behind the scenes than doing what you see above. Still a lot that could be fixed in that class though. I just finished running a small benchmark against 1000 calls and it's a difference of a factor of 10x... ~30ms vs ~3ms (first run was 100x difference). Not saying you need performance here either, but using the Clipboard class also requires that you reference System.Windows.Forms.dll. RE: NativeClipboard.cs | Read/Write clipboard text | 64 and 32-bit | Console or GUI - Washi - Jul 3, 2018 (Jun 30, 2018 01:24 PM)0xDEAD10CC Wrote: I wouldn't know whether to call it an "advantage" but it's not a limitation at least. Runs fine in [MTAThread] context. Ah okay, the code being independent of the apartment state might actually be a factor I guess. But yea as you said, I wonder whether this, the speed or the dependency on System.Windows.Forms.dll are that much of an issue to be honest, especially since WinForms is part of the standard .NET framework libraries. RE: NativeClipboard.cs | Read/Write clipboard text | 64 and 32-bit | Console or GUI - 0xDEAD10CC - Jul 4, 2018 (Jul 3, 2018 07:27 AM)Washi Wrote: Ah okay, the code being independent of the apartment state might actually be a factor I guess. I have no side on this, perhaps if I was doing lower level clipboard work I'd use P/Invokes, but for the basic operations there probably isn't much difference. RE: NativeClipboard.cs | Read/Write clipboard text | 64 and 32-bit | Console or GUI - Interallahu - Jul 4, 2018 (Jul 2, 2018 04:07 PM)FryPan Wrote: Who wants to access clipboard using threads? This is a rare occasion You can use delegates with threads.. or Invoke Plus, The P/Invoking hes doing requires the message loop, which is usually done in a seperate thread RE: NativeClipboard.cs | Read/Write clipboard text | 64 and 32-bit | Console or GUI - gigajew - Jul 4, 2018 Revamped code, removed an error dealing with memory and removed some unused imports, added unsafe context RE: NativeClipboard.cs | Read/Write clipboard text | 64 and 32-bit | Console or GUI - interestingcode - Jul 5, 2018 is this coded in c# or c++? nvm lol saw just now that it was posted in c# topic |