handle

What exactly is “handle”?

雨燕双飞 提交于 2019-12-01 01:54:14
问题 I've often heard about "handles", what exactly are those? Edit: For instance I have heard about: windows handles event handles file handles and so on. Are those things the same? Or they are some abstract terms? 回答1: A handle is an indirect way to reference an object owned by the OS or a library. When the operating system or a library owns an object but wants to let a client refer to it, it can provide a reference to that object called a handle. Handles can be implemented in different ways.

Delphi - Drag & Drop with ListView

社会主义新天地 提交于 2019-11-30 23:46:33
Good evening :-)! I have this code to use Drag & Drop method for files : TForm1 = class(TForm) ... public procedure DropFiles(var msg: TMessage ); message WM_DROPFILES; end; procedure TForm1.FormCreate(Sender: TObject) begin DragAcceptFiles(ListView1.Handle, True); end; procedure TForm1.DropFiles(var msg: TMessage ); var i, count : integer; dropFileName : array [0..511] of Char; MAXFILENAME: integer; begin MAXFILENAME := 511; count := DragQueryFile(msg.WParam, $FFFFFFFF, dropFileName, MAXFILENAME); for i := 0 to count - 1 do begin DragQueryFile(msg.WParam, i, dropFileName, MAXFILENAME); Memo1

How to find that Mutex in C# is acquired?

家住魔仙堡 提交于 2019-11-30 21:41:05
问题 How can I find from mutex handle in C# that a mutex is acquired? When mutex.WaitOne(timeout) timeouts, it returns false . However, how can I find that from the mutex handle? (Maybe using p/invoke.) UPDATE : public class InterProcessLock : IDisposable { readonly Mutex mutex; public bool IsAcquired { get; private set; } public InterProcessLock(string name, TimeSpan timeout) { bool created; var security = new MutexSecurity(); security.AddAccessRule(new MutexAccessRule(new SecurityIdentifier

Must I CloseHandle() on a thread handle?

核能气质少年 提交于 2019-11-30 21:38:44
_beginthreadex returns a handle to a thread: m_hStreamStatsThread = (HANDLE) _beginthreadex( NULL, 0, StreamStatsThread, this, 0, NULL ); This handle may be used if you need to refer to the thread in calls like TerminateThread(..) for example. According to the MSDN page on _beginthreadex , _beginthreadex won't always return a valid handle - e.g. it may also return -1L on error etc. When a thread has completed normally, do I have to call CloseHandle on the thread handle, or can I just set its value to NULL / INVALID_HANDLE_VALUE? Agree with Nemanja Trifunovic. Even after the thread exited - its

Proper way close WinAPI HANDLEs (avoiding of repeated closing)

拥有回忆 提交于 2019-11-30 21:35:55
I have some handle and I need to close it. There is some places in code, where handle may be closed. So, is this a right way to close handle? HANDLE h; .... if ( h != INVALID_HANDLE_VALUE ) { ::CloseHandle(h); h = INVALID_HANDLE_VALUE; } There is a same question about bitmap handles: HBITMAP hb; .... if ( hb != INVALID_HANDLE_VALUE ) { ::DeleteObject(hb); hb = INVALID_HANDLE_VALUE; } EDIT: I think, there is some misunderstanding. I know CloseHandle is for closing handles. I'd like to know proper way for closing handles. A similar situations occurs with deleting of pointers. Foo *foo = new Foo(

C# SSL server mode must use a certificate with the corresponding private key

感情迁移 提交于 2019-11-30 19:06:47
I'm going to learn how to handle HTTPS traffic in C# as server-side and as for the first steps I've got some troubles. Here is some code ( http://pastebin.com/C4ZYrS8Q ): class Program { static bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { if (sslPolicyErrors == SslPolicyErrors.None) return true; Console.WriteLine("Certificate error: {0}", sslPolicyErrors); return false; } static void Main() { var tcpListener = new TcpListener(IPAddress.Parse("127.0.0.1"), 8080); tcpListener.Start(); var clientAccept = tcpListener

Delphi - Drag & Drop with ListView

馋奶兔 提交于 2019-11-30 18:39:26
问题 Good evening :-)! I have this code to use Drag & Drop method for files : TForm1 = class(TForm) ... public procedure DropFiles(var msg: TMessage ); message WM_DROPFILES; end; procedure TForm1.FormCreate(Sender: TObject) begin DragAcceptFiles(ListView1.Handle, True); end; procedure TForm1.DropFiles(var msg: TMessage ); var i, count : integer; dropFileName : array [0..511] of Char; MAXFILENAME: integer; begin MAXFILENAME := 511; count := DragQueryFile(msg.WParam, $FFFFFFFF, dropFileName,

STDERR? What is it? What are its common uses?

拟墨画扇 提交于 2019-11-30 14:50:36
Curious about how the handle STDERR works? Lets keep it down to say Batch Files to keep it simple and focused? I know that many programming languages accept STDERR, so I don't know if maybe uses are different across the board or maybe there is a common function for all programming languages? If anyone can provide some examples on common usage that you have seen or an explanation of why someone may utilize it for ??? situation that would be awesome. Thanks in advance! Usually you would use stderr for error messages. If you run a program on the command line, you can capture its stdout and/or

Convert an IntPtr window handle to IWin32Window^

依然范特西╮ 提交于 2019-11-30 11:17:10
How do I convert a handle acquired from a form/control's Handle property, to a IWin32Window^ ? Control.FromHandle (That gets you the Control object, which implements the IWin32Window interface.) Eg. IntPtr myWindowHandle = IntPtr(someVal); IWin32Window^ w = Control::FromHandle(myWindowHandle); Note that this relies on the handle being "acquired from a form/control's Handle property." You cannot use this technique with an arbitrary Win32 window handle. There's a simpler method that is supported directly by the .NET framework without having to create your own custom class. You can use this with

Why call Dispose() before main() exits?

久未见 提交于 2019-11-30 08:27:07
问题 My .net service cleans up all its unmanaged resources by calling resourceName.Dispose() in a finally block before the Main() loop exits. Do I really have to do this? Am I correct in thinking that I can’t leak any resources because the process is ending? Windows will close any handles that are no longer being used, right? 回答1: There is no limit to the types of resources that may be encapsulated by an object implementing IDisposable . The vast majority of resources encapsulated by IDisposable