handle

Proper way close WinAPI HANDLEs (avoiding of repeated closing)

◇◆丶佛笑我妖孽 提交于 2019-11-30 05:38:18
问题 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

Must I CloseHandle() on a thread handle?

丶灬走出姿态 提交于 2019-11-30 05:32:43
问题 _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

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

社会主义新天地 提交于 2019-11-30 03:34:57
问题 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 =

Delphi: Check whether file is in use

▼魔方 西西 提交于 2019-11-29 19:08:30
问题 I want to write to/delete a file but sometimes I get a crash if the file is in use by another program. How do I check to see whether the file is opened by another process or I can open it for writing? 回答1: The problem is, that between the time you check to see if you could get exclusive access and opening the file, something else gets exclusive access to the file, and you get the exception anyway. The only fool proof way to see if you can get an exclusive lock on a file is to try and get an

Convert an IntPtr window handle to IWin32Window^

∥☆過路亽.° 提交于 2019-11-29 16:53:57
问题 How do I convert a handle acquired from a form/control's Handle property, to a IWin32Window^ ? 回答1: 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. 回答2: There's a simpler method that

Delete a directory where someone has opened a file

非 Y 不嫁゛ 提交于 2019-11-29 11:54:58
I am trying to programmatically delete and replace the contents of an application, "App A", using an "installer" program, which is just a custom WPF .exe app, we'll call "App B". (My question concerns code in "App B".) GUI Setup (not particularly important) App B has a GUI where a user can pick computer names to copy App A onto. A file picker is there the admin uses to fill in the source directory path on the local machine by clicking "App A.exe". There are also textboxes for a user name and password, so the admin can enter their credentials for the target file server where App A will be

What can cause section handle leaks?

流过昼夜 提交于 2019-11-29 10:05:05
This is a follow-up question to my previous question. As suggested in this answer to my previous question , I used ProcessExplorer to analyze a list of handles that my application is using to find a handle leak. The handles that are leaking are of type Section . What exactly is a section handle, where is it used and what can cause section handles to leak? I'm not using memory mapped files in my code. Quoting Mark Russinovich's Inside Windows 2000 (what is now called Windows Internals), The section object , which the Win32 subsystem calls a file mapping object , represents a block of memory

How to get a HWND handle out of a System.Windows.Forms.Form

丶灬走出姿态 提交于 2019-11-29 06:21:17
问题 Given the form System.Windows.Forms::Form Form1; and the window handle HWND hWnd; How can I set hWnd to the Handle property of Form1 that does truly exist as a public property that "Gets the window handle that the control is bound to. (Inherited from Control.)" according to the Microsoft documentation of System.Windows.Forms::Form? In the constructor of my Form Form1, I've tried hWnd = this.Handle; but the compiler complains: error C2228: left of '.Handle' must have class/struct/union type is

Why call Dispose() before main() exits?

眉间皱痕 提交于 2019-11-29 06:14:38
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? 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 objects will be cleaned up by the operating system when a process shuts down, but some programs may use

Getting Matlab handles events or properties

余生颓废 提交于 2019-11-29 04:49:14
The question How may I get the list of events and properties for a handle of double type, as a figure , axes ? The issue Matlab documentation says to you to use the WindowButtonDownFcn , WindowButtonMotionFcn , and so on in order to listen to whatever happens at your interface. The issue is that this properties are very limited as the following fact : Keeping Variables in Scope When MATLAB evaluates function handles, the same variables are in scope as when the function handle was created. (In contrast, callbacks specified as strings are evaluated in the base workspace.) This simplifies the