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
62
votes
1 answer

How do I properly map a `MagImageScalingCallback` using JNA?

I am using jna.jar, jna-3.2.5.jar and jna-3.3.0-platform.jar in my Java Project. This is the Winapi function I want to replicate. BOOL WINAPI MagImageScalingCallback( _In_ HWND hwnd, _In_ void *srcdata, _In_ …
Vishnu
  • 11,614
  • 6
  • 51
  • 90
62
votes
7 answers

What's the C++ version of Guid.NewGuid()?

I need to create a GUID in an unmanaged windows C++ project. I'm used to C#, where I'd use Guid.NewGuid(). What's the (unmanaged windows) C++ version?
Simon
  • 25,468
  • 44
  • 152
  • 266
61
votes
3 answers

WinApi - GetLastError vs. Marshal.GetLastWin32Error

I tested a lot. But I found no disadvantages of those 2! But see the accepted answer. I read here that calling GetLastError in managed code is unsafe because the Framework might internally "overwrite" the last error. I have never had any noticeable…
Bitterblue
  • 13,162
  • 17
  • 86
  • 124
61
votes
5 answers

Using global keyboard hook (WH_KEYBOARD_LL) in WPF / C#

I stitched together from code I found in internet myself WH_KEYBOARD_LL helper class: Put the following code to some of your utils libs, let it be YourUtils.cs: using System; using System.Diagnostics; using System.Runtime.InteropServices; using…
Ciantic
  • 6,064
  • 4
  • 54
  • 49
60
votes
9 answers

Turn on/off monitor

Is it programmatically possible to turn a monitor on/off through code (C#)?
RV.
  • 2,782
  • 8
  • 39
  • 51
58
votes
5 answers

error C2275 : illegal use of this type as an expression

Since yesterday, I've been facing a compiling error for my C project. The project itself consists on creating a service that will make some tasks. I don't what has changed since yesterday, but this morning, my code can't compile anymore. Here are…
BMN
  • 8,253
  • 14
  • 48
  • 80
57
votes
4 answers

How large is a DWORD with 32- and 64-bit code?

In Visual C++ a DWORD is just an unsigned long that is machine, platform, and SDK dependent. However, since DWORD is a double word (that is 2 * 16), is a DWORD still 32-bit on 64-bit architectures?
Haim Bender
  • 7,937
  • 10
  • 53
  • 55
57
votes
2 answers

Foreground Vs Active window

In Windows, what is the difference between foreground and active window? To be specific, under what circumstances can a foreground window not be an active window? If the 2 terms are referring to the same concept why there're 2 terms. The msdn…
JavaMan
  • 4,954
  • 4
  • 41
  • 69
57
votes
8 answers

How do I measure time in C?

I want to find out for how long (approximately) some block of code executes. Something like this: startStopwatch(); // do some calculations stopStopwatch(); printf("%lf", timeMesuredInSeconds); How?
snakile
  • 52,936
  • 62
  • 169
  • 241
57
votes
10 answers

How to use a FolderBrowserDialog from a WPF application

I'm trying to use the FolderBrowserDialog from my WPF application - nothing fancy. I don't much care that it has the Windows Forms look to it. However, when I call ShowDialog, I want to pass the owner window which is an IWin32Window. How do I get…
Craig Shearer
  • 14,222
  • 19
  • 64
  • 95
57
votes
2 answers

C# - How To Convert Object To IntPtr And Back?

I want to pass an object from managed code to a WinApi function as IntPtr. It will pass this object back to my callback function in managed code as IntPtr. It's not a structure, it's an instance of a class. How do I convert object to IntPtr and back…
Bitterblue
  • 13,162
  • 17
  • 86
  • 124
56
votes
4 answers

Get a screenshot of a specific application

I know I can get the screenshot of the entire screen using Graphics.CopyFromScreen(). However, what if I just want the screenshot of a specific application?
Hao Wooi Lim
  • 3,928
  • 4
  • 29
  • 35
56
votes
4 answers

Win32 window Owner vs window Parent?

In Win32 programming, what is the difference between a window's parent and a window's owner? I thought I had it figured out, then I came across this code: SetWindowLong(handle, GWL_HWNDPARENT, foo); This actually sets the window's owner, not the…
Jon Tackabury
  • 47,710
  • 52
  • 130
  • 168
56
votes
2 answers

Creating a transparent window in C++ Win32

I'm creating what should be a very simple Win32 C++ app whose sole purpose it to ONLY display a semi-transparent PNG. The window shouldn't have any chrome, and all the opacity should be controlled in the PNG itself. My problem is that the window…
adoss
  • 1,121
  • 1
  • 9
  • 9
56
votes
5 answers

ShellExecute equivalent in .NET

I'm looking for the .NET-preferred way of performing the same type of thing that ShellExecute does in Win32 (opening, printing, etc. for arbitrary file types). I've been programming Windows for over 20 years, but I'm a complete newbie at .NET, so…
Martin Kenny
  • 2,468
  • 1
  • 19
  • 16