Questions tagged [winapi]

The Windows API (formerly called the Win32 API) is the core set of application programming interfaces available for the Microsoft Windows operating systems. This tag is for questions about developing native Windows applications using the Windows API.

The Windows API, informally WinAPI, is Microsoft's core set of application programming interfaces (APIs) available in the Microsoft Windows operating systems. It was formerly called the Win32 API; however, the name Windows API more accurately reflects its roots in 16-bit Windows and its support on 64-bit Windows. Almost all Windows programs interact with the Windows API. You can find more help on the Windows API Documentation.

The Windows API (Win32) is primarily focused on the C programming language in that its exposed functions and data structures are described in that language in recent versions of its documentation. However, the API may be used by any programming language compiler or assembler capable of handling the (well defined) low level data structures along with the prescribed calling conventions for calls and callbacks.

42239 questions
43
votes
6 answers

CreateProcess from memory buffer

I can use CreateProcess to launch an EXE. I want to have the contents of an EXE in a memory buffer and do CreateProcess (or an equivalent) on it without having to write it to a file. Is there any way to do that? The backstory : we make games. We…
ggambetta
  • 3,312
  • 6
  • 32
  • 42
42
votes
4 answers

winapi: CreateProcess but hide the process' window?

I am using CreateProcess to create a cmd.exe process that is passed a parameter that it executes and quits, this makes command prompt flash up on the screen. I tried to avoid this by setting STARTUPINFO struct wShowWindow to SW_HIDE but this…
Myforwik
  • 3,438
  • 5
  • 35
  • 42
42
votes
8 answers

Prevent windows from going into sleep when my program is running?

I have to stop windows from going into sleep when my program is running. And I don't only want to prevent the sleep-timer, I also want to cancel the sleep-event if I press the sleep-button or in any other way actively tell the computer to sleep.…
ping
42
votes
4 answers

Working example of CreateJobObject/SetInformationJobObject pinvoke in .net?

I'm struggling to put together a working example of pinvoke'ing CreateJobObject and SetInformationJobObject. Through various google searches (including Russian and Chinese posts!) I've cobbled together the following code. I think the definition…
Suraj
  • 35,905
  • 47
  • 139
  • 250
42
votes
2 answers

redefinition errors in WinSock2.h

Including winsock2.h, in a file of a project. Getting many errors in - WinSock2.h(109) : error C2011: 'fd_set' : 'struct' type redefinition with a corresponding - WinSock.h(54) : see declaration of 'fd_set' I don't see winsock.h included in any…
T.T.T.
  • 33,367
  • 47
  • 130
  • 168
42
votes
9 answers

How to detect win32 process creation/termination in c++

I know that to receive notifications about Win32 process creation or termination we might implement a NT kernel-mode driver using the APIs PsSetCreateProcessNotifyRoutine() that offers the ability to register system-wide callback function which is…
Nuno
  • 1,910
  • 2
  • 21
  • 33
42
votes
5 answers

GetWindowRect returns a size including "invisible" borders

I'm working on an app that positions windows on the screen in a grid style. When Running this on Windows 10, there is a huge gap between the windows. Further investigation shows that GetWindowRect is returning unexpected values, including an…
Deanna
  • 23,876
  • 7
  • 71
  • 156
42
votes
5 answers

How to create a hidden window in C++

How to create a hidden window ? The purpose of this window is to receive some messages.
anand
  • 11,071
  • 28
  • 101
  • 159
42
votes
2 answers

How do you use CreateThread for functions which are class members?

How do you use CreateThread() to create threads of functions which are class members?
jeromekjeromepune
41
votes
9 answers

How to detect true Windows version?

I know I can call the GetVersionEx Win32 API function to retrieve Windows version. In most cases returned value reflects the version of my Windows, but sometimes that is not so. If a user runs my application under the compatibility layer, then…
gabr
  • 26,580
  • 9
  • 75
  • 141
41
votes
11 answers

Redirecting cout to a console in windows

I have an application which is a relatively old. Through some minor changes, it builds nearly perfectly with Visual C++ 2008. One thing that I've noticed is that my "debug console" isn't quite working right. Basically in the past, I've use…
Evan Teran
  • 87,561
  • 32
  • 179
  • 238
41
votes
5 answers

How can a Win32 process get the pid of its parent?

I'm currently passing the pid on the command line to the child, but is there a way to do this in the Win32 API? Alternatively, can someone alleviate my fear that the pid I'm passing might belong to another process after some time if the parent has…
twk
  • 16,760
  • 23
  • 73
  • 97
41
votes
8 answers

Win32 API to enumerate dll export functions?

I found similar questions but no answer to what I am looking for. So here goes: For a native Win32 dll, is there a Win32 API to enumerate its export function names?
user15071
  • 3,391
  • 8
  • 31
  • 31
40
votes
2 answers

What is the smallest possible Windows (PE) executable?

As a precursor to writing a compiler I'm trying to understand the Windows (32-bit) Portable Executable format. In particular I'd like to see an example of a bare-bones executable which does nothing except load correctly, run and exit. I've tried…
Matthew Murdoch
  • 30,874
  • 30
  • 96
  • 127
40
votes
4 answers

Global hotkey in console application

Does anyone know how to use the RegisterHotKey/UnregisterHotKey API calls in a console application? I assume that setting up/removing the hotkey is the same, but how do I get the call back when the key was pressed? Every example I see is for…
user60456