Click here to Skip to main content
15,887,683 members
Everything / WinAPI

WinAPI

WinAPI

Great Reads

by SimbirSoft
C++: love and intrigue
by Axel Rietschin
Import photos & videos directly from smart phones and digital cameras using the Windows Photo Import API, for Windows Universal Apps and Classic Win32 applications on Windows 10 and beyond.
by David MacDermot
This article describes adding checkboxes to the standard combobox and listbox control.
by Alexander Eremeev
The Windows kernel-hacking library and development framework written on C++17

Latest Articles

by ColleagueRiley
A multi-platform single-header very simple-to-use framework library for creating GUI Libraries or simple GUI programs.
by AbdulRahman A. Badry
Alter your display gamma-ramp to correct & calibrate it
by David MacDermot
This article describes adding checkboxes to the standard combobox and listbox control.
by honey the codewitch
Diving into some of the core plumbing behind the Windows operating system

All Articles

Sort by Updated

WinAPI 

28 Mar 2024 by KarstenK
Verify that your new dll function has the same export macro signature as the other dll function. Mostly some DLL_EXPORT or similar macro stuff. Another common issue is that, your new dll isnt used by the calling program but a stale version in...
27 Mar 2024 by Rick York
Firstly, there are no limits to DLL sizes or capacities. Secondly, it is important to note what is emitting that error message. It could be the compiler or the linker. If it is from the compiler then you have not defined a prototype for the...
27 Mar 2024 by samtoad
Currently, I'm trying to add another "C" routine into a DLL file. I've made the routine inside a DLL source file. I've declared the routine, and also indicated the intentions as it will be exported. The function name is also included in a DEF...
11 Mar 2024 by Andre Oosthuizen
you can make use of the 'SystemTimeToTzSpecificLocalTime' function to achieve what you are trying - MS Learn | SystemTimeToTzSpecificLocalTime function (timezoneapi.h)[^] Your code will look like - #include #include void...
10 Mar 2024 by Pete O'Hanlon
I'm making an assumption here that you are talking about converting the two SYSTEMTIME structures in the DYNAMIC_TIME_ZONE_INFORMATION object. To accomplish this, I believe that you are going to start by converting the SYSTEMTIME structure to a...
10 Mar 2024 by samtoad
n using the GetDynamicTimeZoneInformation(&dtzi) function, and within the 'dtzi' structure, it tells you whether you're in the Daylight Savings time or not and when they will start, via these two dates. The return value of this function also...
25 Feb 2024 by ColleagueRiley
A multi-platform single-header very simple-to-use framework library for creating GUI Libraries or simple GUI programs.
5 Feb 2024 by OriginalGriff
I'd suggest that you move the data files to a "all users" data folder: Windows has a data folder which is available to all users: ProgramData. This is a hidden folder, normally in the root of the C: drive (but can be moved - open File Explorer...
5 Feb 2024 by KarstenK
To get the pathes windows has some special API named Known folder interfacesa or the more recente SHGetFolderPath. The parameters are useda as an identifier which path returns. But first you need some concept for your data. Best is when every...
5 Feb 2024 by samthelab
I've put together a simple multiuser program that runs great out of a PC-user A's directory. But the problems occur when user B' thru user D', on the same PC, runs the program and attempts access' to these date files. The results is usually quite...
24 Oct 2023 by samthelab
What does this mean and how do I fix it?? 1>C:\dllmain.cpp : warning C4747: Calling managed '_DllMain@12': Managed code may not be run under loader lock, including the DLL entrypoint and calls reached from the DLL entrypoint...
1 Oct 2023 by samthelab
Today, I recently received an answer to a question that I didn't ask - on my cell-phone, regarding a question that I was going to ask. It was about obtaining the Network Domain/SSID name in "C" programmatically from/on a cell phone. But I'm...
29 Sep 2023 by Richard MacCutchan
See Native Wifi API Sample - Win32 apps | Microsoft Learn[^]
19 Sep 2023 by TheNewbieProgrammer
I know this may sound silly, but to fix this you need to replace the color value with the starting color. And the other thing you need to do is to use elapsedTime instead of deltaTime to calculate the progress. Here's the code: float progress =...
12 Sep 2023 by NoviceCoder871987
I ran into a weird issue with custom drawing the listview control. I drew the grid lines in response to CDDS_POSTPAINT notification. All working okay so far. However, when scrolling vertically, the lines will be messed up and will not be drawn at...
9 Sep 2023 by Richard MacCutchan
See About Custom Draw - Win32 apps | Microsoft Learn[^] for custom drawing in Report mode.
17 Jul 2023 by Rick York
One thing to keep in mind is the Windows timer works on multiples of 60Hz or 16.7ms. That is as low as it will go about 60Hz is achievable as is 30Hz. At the risk of blowing my own horn, I like this class for determining elapsed time : High...
17 Jul 2023 by TheNewbieProgrammer
I will explain the problem very briefly: In order to get a color animation, the lerp algorithm must be used to change the colors smoothly, which requires the progress of the animation (std::min)((deltaTime / duration), 1.0f) But there is a...
16 Jul 2023 by KarstenK
You wil have to dig it out yourself. Start by making more TRACE output with a detailed timestamp. I would use some constant for the timer id. In this code your arent correctly use the timer id. Check it! tip: start with a low frame rate like 10...
9 Jul 2023 by Avtem
There is a WM_SETREDRAW message in WinAPI which you can send to a window in order to suspend/resume drawing updates. It works fine, but as soon as i add visual styles from comctl32 v.6.0.0 to my program calling WM_SETREDRAW on a ListView control...
9 Jul 2023 by Avtem
Unfortunately i couldn't figure out how to use WM_SETREDRAW with ListView controls, but since MDSN describes us how it's implemented i decided to do what they do - remove or add WS_VISIBLE style from the window without invalidating its rectangle....
9 Jul 2023 by Richard MacCutchan
See the Remarks section at WM_SETREDRAW message[^].
9 Jun 2023 by AbdulRahman A. Badry
Alter your display gamma-ramp to correct & calibrate it
19 May 2023 by tricityterminal
uintptr_t _beginthreadex( // NATIVE CODE void *security, unsigned stack_size, unsigned ( __stdcall *start_address )( void * ), void *arglist, unsigned initflag, unsigned *thrdaddr I want to start a thread from socket winsock ...
18 May 2023 by merano99
The use of _beginthreadex() is explained in detail here _beginthread, _beginthreadex | Microsoft Learn Here you can read that the function creates a thread which starts the execution of a routine at start_address. If you set almost all...
17 May 2023 by Derell Licht
I have a command-line utility that I wrote (C++, MinGW32, Windows 10), that displays information for images and videos... I recently found an excellent free library (ZPlay) that handles some of the more complex images such as OGG, MP3, FLAC... ...
17 May 2023 by cute_friend7077
crystalhd gstreamermm libmatroska libVLC mjpegtools OpenH264
17 May 2023 by MasterCodeon
hello everyone!i am trying to send a string to another application.the way i am trying to do this is by using the SendMessage function in the windows api, and i am setting the WParam parameter to a string value(when i imported the function i did use a string type for this parameter).now in...
16 May 2023 by virtualnik
Try MediaInfo: MediaInfo - Download MediaInfo for Microsoft Windows[^] It ships with a simple to use Dll interface that can be used to gather information about nearly all video and audio files. In the Zip-File you will find a directory called...
15 May 2023 by RickZeeland
Maybe you can use one of these GitHub projects: video-metadata · GitHub Topics · GitHub[^] And if you are not afraid of a bit C# coding: GitHub - drewnoakes/metadata-extractor-dotnet: Extracts Exif, IPTC, XMP, ICC and other metadata from image,...
14 May 2023 by KarstenK
So Derell wrote the ffmpeg is a solution. You have to learn to handle the code, but it has a lot of features and it is some "workhorse" library. Your tasks are challengig so it is also challenging to get some library to do the job. tip: the...
14 May 2023 by OriginalGriff
This isn't necessarily a C++ solution - I haven't played with C++ for over a decade - but there is a .NET way to get some video info direct from the OS provided a suitable codec is installed - I use it to get video duration and resolution, using...
14 May 2023 by Mitchell J.
ffmpeg should be able to do this. Not sure if it supports directly embedding itself within your C++ code, but you should at least be able to run an instance of the binary from your code (with the correct flags) and then parse the output it produces.
25 Apr 2023 by Richard MacCutchan
See ComboBox.AutoCompleteMode Property (System.Windows.Forms) | Microsoft Learn[^]. My apologies, try CB_FINDSTRING message (Winuser.h) - Win32 apps | Microsoft Learn[^]
25 Apr 2023 by Avtem
So, many WinAPI controls have a very useful feature - you can select an item in Listbox, ListView, Combobox by typing first several letters. You can try it out: just open your windows calculator, hit Ctrl+U to enable converting units view and in...
20 Apr 2023 by huguidesr
I've been trying to draw a bitmap int array using glTexImage2D, but it only outputs white nothingness. It outputs jumbled messy pixels from out of bounds memory if I initialize the int aray as a char array instead, but it only renders whiteness...
20 Apr 2023 by Rick York
I don't have an answer for you but here are a few sample projects you might get a hint from : 50 OpenGL Win32 Projects in One[^] 50 OpenGL MFC Projects in One[^] Your Own Quadrics in OpenGL MFC[^]
30 Mar 2023 by Richard MacCutchan
You seem to be confused about the correct use of pointers in your code. You define lpsh as: SHFILEOPSTRUCTA lpsh{}; But that is not an array, it is a structure, so you need to pass its address to the SHFileOperationA function. You should...
30 Mar 2023 by Member 15925018
Wherever and whenever I write to lpsh "type: LPSHFILEOPSTRUCTA" that raises the error: Exception thrown: write access violation. lpsh was nullptr. What I have tried: I've tried 1-Writing to the unwritten portions of LPSHFILEOPSTRUCTA (filled...
26 Mar 2023 by Saleh 2023
I am trying to get the pixel color of a specified coordinate point outside my application window. So, since hwnd specifies my window to be targeted, then all i should do is use getdc function and pass my hwnd as parameter. But what if I want a...
25 Mar 2023 by OriginalGriff
You can use GetDC on the NULL window to get a device context for the whole screen, and can follow that up with a call to GetPixel: HDC dc = GetDC(NULL); COLORREF cr = GetPixel(dc, x, y); ReleaseDC(NULL, dc);
26 Feb 2023 by uuu99933
Hi all! Are there people who write or wrote on Win9x? I have a question about the function ReadConsoleInput in console. For some reason, on Win9x systems, random stutters occur when this function returns. The difference can be up to 10 times...
26 Feb 2023 by merano99
According to Microsoft documentation, the system call is not suitable for Win9x. readconsoleinput Minimum supported client is Windows 2000 Prof Since Win9x does not support preemptive multitasking, you would need a non-blocking alterative to...
28 Dec 2022 by muhdaqil00
I was trying to run a code that I found on this site, "Getting the File System Image and Deleted Data Recovery." But when I run the project, a cpp file called "RemovebleDeviceInfo.cpp" has an error: "no matching function for call to...
28 Dec 2022 by CPallini
When you try to compile such (ill formed) code, there is a mismatch between TCHAR (resolved to char) and wstring. You may easily verify that trying to compile the following #include #include using namespace std; int main() { ...
28 Dec 2022 by Richard MacCutchan
It looks like you are building this code in the ASCII version, but the return statement expects that sResult contains Unicode data. Check the actual settings for the project and ensure they match what is used in the article.
28 Dec 2022 by OriginalGriff
Don't post this under Quick Answers - if you got the code from an article, then there is a "Add a Comment or Question" button at the bottom of that article, which causes an email to be sent to the author. They are then alerted that you wish to...
14 Nov 2022 by tardezyx
Perhaps, instead of checking all windows, you could check all processes with an existing MainWindowHandle. Therefore, prepare your "User32" class: [StructLayout(LayoutKind.Sequential)] public struct RECT { public int Left; // x...
14 Nov 2022 by Михаил Солодков
Hello! I see 4 windows on the monitor (for example), but EnumWindows gives me more than a dozen - some incomprehensible windows that are not on the screen at all. They names are something like "Microsoft Text Input Application, Microsoft Store,...
25 Oct 2022 by DoingWork
I am using Consuming Nouget Package VirtualDesktop in my desktop application. When I call VirtualDesktop.IsSupported then it returns True. But When I call VirtualDesktop.IsPinned(handle) it returns following exception. Exception:Empty...
22 Oct 2022 by Graeme_Grant
THis error message explains what is happening: Exception:Empty path name is not legal. (Parameter 'path') It is expecting a value, not an empty path
8 Oct 2022 by reverser69
hi all i want to do an inline asm and i want to see if a given location of memory is non-writable-executable code or its writable data; if its data, skip the overwrite. i want to do it in pure asm + win api. i partially achieved it by checking...
8 Oct 2022 by merano99
Access to main memory is usually realized with an MMU. Since the MMU is a critical resource, the operating system takes care of it. Access to the MMU requires operating system rights and good hardware knowledge. If you had access to the MMU, you...
12 Sep 2022 by sorauts
Turns out LoadImage and LoadBitmap don't work for 32-bit bitmaps, only 24-bit (without alpha). That is not explained anywhere and I figured it out through hours of trial and error. I need transparency, so I instead have to use LoadResource.
12 Sep 2022 by sorauts
I'm trying to obtain a HBITMAP using LoadImageW, retrieving an image from embedded resources. LoadImageW returns NULL, with GetLastError() invalidly claiming that access was denied with error 5. The image definitely exists, and has no special...
12 Sep 2022 by Rick York
I have done a bit of searching and I have seen this sequence of code several times : HRSRC resrc = FindResource( hInstance, MAKEINTRESOURCE( resource ), TEXT("PNG") ); HGLOBAL hPng = LoadResource( hInstance, resrc ); PVOID pByte =...
16 Feb 2022 by Haniel Arce Manriquez
Hello I am trying to create a Net 5.0 application for Hyper-v Backup and I would like to use Resilient Change Tracking for backup virtual disk's Blocks changing. I am using a Wrapper to library VirtDisk.h...
1 Feb 2022 by Avtem
So for my Win32 app I use one .chm file as a manual and another .chm for representing "Version History." I use a HtmlHelpW() function for opening them. The problem is, if I open both of them, the second .chm file hangs up, starts to consume all...
1 Feb 2022 by CHill60
If you want spaces in a path then you must surround the entire path with double quotation marks - see Long paths with spaces require quotation marks - Windows Server | Microsoft Docs[^] E.g. HtmlHelpW(mainWnd,...
23 Dec 2021 by David MacDermot
This article describes adding checkboxes to the standard combobox and listbox control.
2 Dec 2021 by Avtem
I wrote a DLL with hook of type WH_GETMESSAGE. What I want to do is store an std::vector inside that DLL and being able to manipulate it from my app. But the problem is that when my app calls DLL function createMyObjects() vector's size...
2 Dec 2021 by Rick York
Hook procedures are called in the context of the process that generates the message. Here is what the docs (Hooks Overview - Win32 apps | Microsoft Docs[^]) say on the topic : Quote: A global hook monitors messages for all threads in the same...
29 Nov 2021 by merano99
Based on my first suggestion, here is another solution if you have to close windows in between. case WM_CREATE: { SetWindowLong(hWnd, GWL_EXSTYLE, GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_LAYERED); SetLayeredWindowAttributes(hWnd,...
29 Nov 2021 by EnderMo233
int Num = 0; LRESULT CALLBACK TestWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { RECT rc; GetClientRect(hWnd, &rc); RECT Winrc; GetWindowRect(hWnd, &Winrc); SYSTEMTIME time; GetLocalTime(&time); ...
28 Nov 2021 by merano99
As Rick York suggested numbering the windows with SetWindowLongPtr () seems to be a good solution if you write a consecutive number after creating the window. Insted of using a MessageBox it is better to use the StatusBar: BOOL...
27 Nov 2021 by Rick York
The problem is you have one instance of the variables of interest. If you want each window to have a unique number then they each have to a unique variable. There are several ways this could be implemented. Among them are a map that associates...
21 Nov 2021 by EnderMo233
I try to use a method to save the DC, so that it only needs to call drawfun once when it is created, and directly recover from the memory DC at other times int dystate = 1; void CreatePanelDynamic(HWND h, HDC hdc, DRAWPANEL DrawFun, int Flag =...
21 Nov 2021 by Rick York
Richard is correct. Here's a memory DC class I use. It was adapted from one I found here written by Keith Rule a long time ago but this does not use MFC. class CMemoryDC { private: HBITMAP m_hbitmap; HBITMAP ...
21 Nov 2021 by Richard MacCutchan
When dystate == 1 (first time), you do the drawing into inhdc, and then blit it to the Window DC. But then before you leave, you do this: SelectObject(inhdc, hPreBmp); thus losing the BitMap that contains the drawing. Then when you come back...
20 Nov 2021 by KarstenK
You need to debug your code because the dystate flag isnt correctly set in the other loop. Try an else or switch for better control. For optimizing draw code double buffering is best. Read this article Flicker Free Text Scrolling with Double...
20 Nov 2021 by EnderMo233
There is a function to draw shadow,but each shadow takes 2ms to draw,if I create 10 shadow it takes nearly 20ms to draw and make the UI lag. CreateShadowBox(hWnd, hdc, rc.left + 20, gTopSize, 100,100,Box1, RGB(60,60,60), RGB(10,10,10)); ...
20 Nov 2021 by merano99
Of course, that doesn't make much sense. HANDLE thread = CreateThread(NULL, NULL, VUIShadowBoxThread, &p, 0, 0); if (thread) { WaitForSingleObject(thread, INFINITE); CloseHandle(thread); } It makes no sense to start a thread and then wait...
19 Nov 2021 by KarstenK
Threading is a good idea, but it also creates overhead, so you should avoid the so called thread explosion where a lot of threads are waiting for execution. It is up to you to test how many threads are useful. Better is to have some stabile...
30 Oct 2021 by Avtem
What i need Does LVS_EX_LABELTIP for Win32 ListView automatically implement showing tooltips for truncated items (i.g."Hello, W...")? Like style LVS_EX_CHECKBOXES which works "out of the box". Or is it developers responsibility? (From reading...
26 Oct 2021 by KarstenK
the label tip has some standard amount of characters, so a lengthly text gets truncated. Your flag is to override that default behaviour. "If a partially hidden label in any list view mode lacks tooltip text, the list-view control will unfold...
1 Sep 2021 by AysunTopcuAkkaya
Hello, in my company we are having a trouble about screen burn. We want to take the whole desktop view with all windowses and shrink it for some percentage and then move clockwise. I tried this with MoveWindow api for only one window and it's...
23 Aug 2021 by armagedescu
all the gui turns white I'd say that's rather a sign of leaking of display context handles See this code, each BeginPaint must be closed with EndPaint: switch (uMsg) { ... case WM_PAINT: { PAINTSTRUCT ps; ...
23 Aug 2021 by EnderMo233
My program use WINAPI(C++),and use GDI and childwindow to create GUI. the program can running normally,and seems nothing wrong,but when I tried to move the window outside the screen quickly to test the program,it crashed,all the gui turns...
7 Aug 2021 by Avtem
So i need to handle any change in a WinAPI combobox (its' type = Simple (you can modify the entry in edit box)). Everything is fine, except it always prints previous text, not the current. void onCommand(WPARAM wparam, LPARAM lparam) { ...
7 Aug 2021 by Richard MacCutchan
You should study Combo Box (Windows Controls) - Win32 apps | Microsoft Docs[^] which explains how to use the control.
13 Jul 2021 by Member 14770565
I had develop windows file watcher service to launch UI (as user give file print from menu) using createuserprocess winapi. It works fine for single user. For multi user this UI get launch in wrong user's session. So I need launch UI in...
13 Jul 2021 by Dave Kreskowiak
Save yourself the pain of this not working at all in future versions of Windows and create a small application that launches on user login. This app can "register" itself with the service application, receiving notification from it and launching...
23 May 2021 by Richard MacCutchan
Maybe using EnumDesktopWindows function (winuser.h) - Win32 apps | Microsoft Docs[^] would be a better call.
5 May 2021 by Member 15076657
Hello, I'm trying to print the list of windows services in a file. I have been trying this code. if ((EnumServicesStatusEx( scHandle, SC_ENUM_PROCESS_INFO, ...
4 May 2021 by Richard MacCutchan
I have simplified your code, and removed all the non essential parts, to the following, which lists the (basic) service information. You just need to add some prettier formatting as necessary. #include #include...
4 May 2021 by Member 15076657
I'm writing a code to list and print the windows services in a file. It runs fine and i have attached the code here. FILE *fp; fp=fopen("file.txt","w"); if ((EnumServicesStatusEx( scHandle, ...
4 May 2021 by Richard MacCutchan
This is essentially the same question you already posted at List windows services in a file using C[^]. And I already explained how you need to allocate the memory for the returned data. And again you are trying to extract data from a buffer that...
4 May 2021 by Richard MacCutchan
LPBYTE data =(unsigned char *) bytesNeeded; You cannot allocate dynamic memory like that; you are just casting a number to a pointer, which makes no sense. You need to call one of the memory allocation routines: LPBYTE data...
9 Apr 2021 by Member 14036402
Hello everyone, I am developing an application similar to windows inspect using the user 32 dlls.I can recursively access children in another Windows application.(EnumChildWindows) However, my main goal is to be able to get all the elements...
9 Apr 2021 by Dave Kreskowiak
No, there is no such service. You'd have to "sort" that data yourself. Get all the window handles and their coordinates and you can "order" them yourself however you want. Windows will not do it for you.
22 Mar 2021 by Member 15076657
I need to block an .exe file(application) using C++. Is there any code I have to refer? Kindly share some windows APIs to write the code.Thank you in advance. What I have tried: I noticed there is a code in C# here. I tried to convert it. Since...
22 Mar 2021 by Richard Deeming
Microsoft have examples in C++: Adding a Service Rule | Microsoft Docs[^]
8 Mar 2021 by Member 15076657
Hi, I want to create a windows service which is unstoppable and unmodifiable in all the accounts except base administrator. The service should be started or stopped only from the base administrator and not from any local administrators. In other...
8 Mar 2021 by KarstenK
Read Installing a Service documentation from Microsoft. Must must apply the correct credentials in CreateService. It is best practice to log all error in the error console or write some log. Test all features on some test target machine and NOT...
16 Jan 2021 by JoesephMU
I am working on a project where I have to create a windows token for a given SID. The intention is to generate an elevated token for a standard user. I am aware of an undocumented function "NtCreateToken()" which could do that but I dont get...
22 Oct 2020 by Avtem
(My IDE is Visual Studio 2019) So, the question is about the macro UNICODE. Which works fine if there is only one source file in the project. However, if there are multiply source files, and UNICODE macro is defined only in one of them, linker...
22 Oct 2020 by Richard MacCutchan
You can define it in the Project Properties in the Advanced -> Character Set box. This will ensure that all source files will be compiled with /D "UNICODE" as standard.
22 Oct 2020 by CPallini
Quote: Do i have to define UNICODE in every single source file? Yes, you have to. You might, however, define it as a compiler option, see /D (Preprocessor Definitions)- To set this compiler option in the Visual Studio development environment |...
6 Oct 2020 by KarstenK
You cant "elevate" tokens or processes because of security reasons Microsoft doenst allow that. For your case it is best to create a new process with CreateProcessWithLogonW.
6 Oct 2020 by curiousward
I have retrieved and duplicated a token (via OpenProcessToken() and DuplicateTokenEx() ) from a process running under the context of a Standard User. Is it possible to provide this token alone with administrative privileges so that such user...