What is the range of a Windows HANDLE on a 64 bits application?

MSDN states: Interprocess Communication Between 32-bit and 64-bit Applications 64-bit versions of Windows use 32-bit handles for interoperability. When sharing a handle between 32-bit and 64-bit applications, only the lower 32 bits are significant, so it is safe to truncate the handle (when passing it from 64-bit to 32-bit) or sign-extend the handle (when passing … Read more

How to get hWnd of window opened by ShellExecuteEx.. hProcess?

First use WaitForInputIdle to pause your program until the application has started and is waiting for user input (the main window should have been created by then), then use EnumWindows and GetWindowThreadProcessId to determine which windows in the system belong to the created process. For example: struct ProcessWindowsInfo { DWORD ProcessID; std::vector<HWND> Windows; ProcessWindowsInfo( DWORD … Read more

What is a handle in C++?

A handle can be anything from an integer index to a pointer to a resource in kernel space. The idea is that they provide an abstraction of a resource, so you don’t need to know much about the resource itself to use it. For instance, the HWND in the Win32 API is a handle for … Read more

Determine path to registry key from HKEY handle in C++

Use LoadLibrary and NtQueryKey exported function as in the following code snippet. #include <windows.h> #include <string> typedef LONG NTSTATUS; #ifndef STATUS_SUCCESS #define STATUS_SUCCESS ((NTSTATUS)0x00000000L) #endif #ifndef STATUS_BUFFER_TOO_SMALL #define STATUS_BUFFER_TOO_SMALL ((NTSTATUS)0xC0000023L) #endif std::wstring GetKeyPathFromKKEY(HKEY key) { std::wstring keyPath; if (key != NULL) { HMODULE dll = LoadLibrary(L”ntdll.dll”); if (dll != NULL) { typedef DWORD (__stdcall *NtQueryKeyType)( … Read more

Register to be default app for custom file type

You can add the following to the AndroidManifest.xml file inside the activity that has to open the file (pdf in our case) <intent-filter > <action android:name=”android.intent.action.VIEW” /> <category android:name=”android.intent.category.DEFAULT” /> <data android:mimeType=”application/pdf” /> </intent-filter> Make sure you specify the proper mime format. The user will be prompted to choose your app if she wants to … Read more

Get Application’s Window Handles

You could do what Process.MainWindowHandle appears to do: use P/Invoke to call the EnumWindows function, which invokes a callback method for every top-level window in the system. In your callback, call GetWindowThreadProcessId, and compare the window’s process id with Process.Id; if the process ids match, add the window handle to a list.

What is a Windows Handle?

It’s an abstract reference value to a resource, often memory or an open file, or a pipe. Properly, in Windows, (and generally in computing) a handle is an abstraction which hides a real memory address from the API user, allowing the system to reorganize physical memory transparently to the program. Resolving a handle into a … Read more