All Questions
18,569
questions
191
votes
11
answers
226k
views
How to get the error message from the error code returned by GetLastError()?
After a Windows API call, how can I get the last error message in a textual form?
GetLastError() returns an integer value, not a text message.
160
votes
9
answers
149k
views
Cannot open include file 'afxres.h' in VC2010 Express
I'm trying to compile an old project using VS express 2010 but I get this error:
fatal error RC1015: cannot open include file 'afxres.h'. from this code
////////////////////////////////////////////...
159
votes
4
answers
221k
views
Why in C++ do we use DWORD rather than unsigned int? [duplicate]
I'm not afraid to admit that I'm somewhat of a C++ newbie, so this might seem like a silly question but....
I see DWORD used all over the place in code examples. When I look up what a DWORD truly ...
143
votes
6
answers
234k
views
How to convert std::string to LPCWSTR in C++ (Unicode)
I'm looking for a method, or a code snippet for converting std::string to LPCWSTR
142
votes
17
answers
106k
views
Windows threading: _beginthread vs _beginthreadex vs CreateThread C++
What's a better way to start a thread, _beginthread, _beginthreadx or CreateThread?
I'm trying to determine what are the advantages/disadvantages of _beginthread, _beginthreadex and CreateThread. ...
128
votes
8
answers
249k
views
Adding external library into Qt Creator project
How can I add external library into a project built by Qt Creator RC1 (version 0.9.2)? For example, the win32 function EnumProcesses() requires Psapi.lib to be added in the project to build.
121
votes
11
answers
111k
views
Can I download the Visual C++ Command Line Compiler without Visual Studio?
As per the title. I don't want to download the entire Visual C++ installer, only "cl.exe" and the other programs required for compiling and linking C++ programs on Windows.
118
votes
3
answers
201k
views
What does LPCWSTR stand for and how should it be handled?
First of all, what is it exactly? I guess it is a pointer (LPC means long pointer constant), but what does "W" mean? Is it a specific pointer to a string or a pointer to a specific string?
For ...
114
votes
3
answers
280k
views
Dynamically load a function from a DLL
I'm having a little look at .dll files, I understand their usage and I'm trying to understand how to use them.
I have created a .dll file that contains a function that returns an integer named funci()...
113
votes
10
answers
261k
views
How do I print to the debug output window in a Win32 app?
I've got a win32 project that I've loaded into Visual Studio 2005. I'd like to be able to print things to the Visual Studio output window, but I can't for the life of me work out how. I've tried '...
104
votes
8
answers
187k
views
How to read a value from the Windows registry
Given the key for some registry value (e.g. HKEY_LOCAL_MACHINE\blah\blah\blah\foo) how can I:
Safely determine that such a key exists.
Programmatically (i.e. with code) get its value.
I have ...
95
votes
4
answers
2k
views
Manipulate system/visible clipping region in Windows 1809
Apparently, Microsoft has changed the way clipping works with Windows update 1809, released in late 2018. Before that update, GetClipBox() returned the full client rectangle of a window, even when it ...
93
votes
13
answers
158k
views
What is the easiest way to parse an INI File in C++? [closed]
I'm trying to parse an INI file using C++. Any tips on what is the best way to achieve this? Should I use the Windows API tools for INI file processing (with which I am totally unfamiliar), an open-...
87
votes
2
answers
34k
views
What's "wrong" with C++ wchar_t and wstrings? What are some alternatives to wide characters?
I have seen a lot of people in the C++ community(particularly ##c++ on freenode) resent the use of wstrings and wchar_t, and their use in the windows api. What is exactly "wrong" with wchar_t and ...
84
votes
6
answers
261k
views
How do I use a third-party DLL file in Visual Studio C++?
I understand that I need to use LoadLibrary(). But what other steps do I need to take in order to use a third-party DLL file?
I simply jumped into C++ and this is the only part that I do not get (as ...
84
votes
5
answers
105k
views
How do I programmatically get the version of a DLL or EXE file?
I need to get the product version and file version for a DLL or EXE file using Win32 native APIs in C or C++. I'm not looking for the Windows version, but the version numbers that you see by right-...
82
votes
3
answers
60k
views
Illegal token on right side of ::
I have the following template declaration:
template <typename T>
void IterTable(int& rIdx,
std::vector<double>& rVarVector,
...
80
votes
4
answers
75k
views
Is there a way to get the string representation of HRESULT value using win API?
Is there a function in win API which can be used to extract the string representation of HRESULT value?
The problem is that not all return values are documented in MSDN, for example ...
78
votes
6
answers
50k
views
How do I decide whether to use ATL, MFC, Win32 or CLR for a new C++ project?
I'm just starting my first C++ project. I'm using Visual Studio 2008. It's a single-form Windows application that accesses a couple of databases and initiates a WebSphere MQ transaction. I basically ...
74
votes
7
answers
8k
views
Why do you need to recompile C/C++ for each OS? [duplicate]
This is more of a theoretical question than anything. I'm a Comp sci major with a huge interest in low level programming. I love finding out how things work under the hood. My specialization is ...
74
votes
3
answers
29k
views
What does it mean to set the declaration of a function equal to 0? How can you assign an integer to a function?
I was browsing through the sources of a (prefer not to name) GUI Toolkit which wrapped up the Windows API when I found the following function definition in the window class:
virtual LRESULT CALLBACK ...
73
votes
7
answers
200k
views
How can I get a process handle by its name in C++?
I'm trying to get the process handle of, say example.exe, so I can call TerminateProcess on it. How can I do this? Notice, it doesn't have a window so FindWindow won't work.
71
votes
13
answers
100k
views
Is there a way to find all the functions exposed by a dll
I've been searching for a way to get all the strings that map to function names in a dll.
I mean by this all the strings for which you can call GetProcAddress. If you do a hex dump of a dll the ...
71
votes
7
answers
154k
views
How to get main window handle from process id?
How to get main window handle from process id?
I want to bring this window to the front.
It works well in "Process Explorer".
69
votes
8
answers
55k
views
malloc() vs. HeapAlloc()
What is the difference between malloc() and HeapAlloc()? As far as I understand malloc allocates memory from the heap, just as HeapAlloc, right?
So what is the difference?
68
votes
4
answers
51k
views
What does "WINAPI" in main function mean?
Could you please explain to me the WINAPI word in the WinMain() function?
In the simplest way..
#include <windows.h>
int -->WINAPI<-- WinMain(HINSTANCE hInstance, HINSTANCE ...
67
votes
7
answers
124k
views
How to get installed Windows SDK version?
How can I determine what version of the Windows SDK is installed on my computer?
I'm asking so I can install the latest version if it isn't installed already.
66
votes
9
answers
249k
views
How to convert char* to wchar_t*?
I've tried implementing a function like this, but unfortunately it doesn't work:
const wchar_t *GetWC(const char *c)
{
const size_t cSize = strlen(c)+1;
wchar_t wc[cSize];
mbstowcs (wc, c,...
65
votes
19
answers
100k
views
How to make thread sleep less than a millisecond on Windows
On Windows I have a problem I never encountered on Unix. That is how to get a thread to sleep for less than one millisecond. On Unix you typically have a number of choices (sleep, usleep and nanosleep)...
65
votes
7
answers
89k
views
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?
64
votes
10
answers
213k
views
How do I call ::CreateProcess in c++ to launch a Windows executable?
Looking for an example that:
Launches an EXE
Waits for the EXE to finish.
Properly closes all the handles when the executable finishes.
64
votes
2
answers
186k
views
Get current cursor position
I want to get the current mouse position of the window, and assign it to 2 variables x and y (co-ordinates relative to the window, not to the screen as a whole).
I'm using Win32 and C++.
And a quick ...
62
votes
5
answers
108k
views
How can I take a screenshot in a windows application?
How can I take a screenshot of the current screen using Win32?
58
votes
4
answers
156k
views
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?
57
votes
2
answers
76k
views
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 ...
54
votes
8
answers
105k
views
How can I tell if a given path is a directory or a file? (C/C++)
I'm using C and sometimes I have to handle paths like
C:\Whatever
C:\Whatever\
C:\Whatever\Somefile
Is there a way to check if a given path is a directory or a given path is a file?
54
votes
7
answers
8k
views
Why does Sleep(500) cost more than 500ms?
I used Sleep(500) in my code and I used getTickCount() to test the timing. I found that it has a cost of about 515ms, more than 500. Does somebody know why that is?
54
votes
4
answers
57k
views
Difference between InvalidateRect and RedrawWindow
When I want to redraw a window, is there any preferred function to call between InvalidateRect and RedrawWindow?
For instance, are these two calls equal: (win would be a HWND)
RedrawWindow(win, NULL,...
53
votes
9
answers
93k
views
How can a Windows service execute a GUI application?
I have written a Windows service that allows me to remotely run and stop applications. These applications are run using CreateProcess, and this works for me because most of them only perform backend ...
53
votes
2
answers
34k
views
Embed Text File in a Resource in a native Windows Application
I have a C++ Windows program. I have a text file that has some data. Currently, the text file is a separate file, and it is loaded at runtime and parsed. How is it possible to embed this into the ...
52
votes
5
answers
79k
views
#define NOMINMAX using std::min/max
i recently added:
#define NOMINMAX
#include <Windows.h>
#include <algorithm>
to my main.cpp in order to use
std::max( x , x ); // x is just a placeholder and not actual anything
std::...
52
votes
10
answers
96k
views
C++ #include <atlbase.h> is not found
When I compile my C++ program in Visual Studio Express it says that it can't find atlbase.h. Am I missing some SDK or something?
52
votes
4
answers
129k
views
How to check if directory exist using C++ and winAPI [duplicate]
How do I check whether a directory exists using C++ and windows API?
51
votes
8
answers
113k
views
How to detect the current screen resolution?
How do I from Winapi (in C or C++) detect the current screen resolution?
Some background:
I want to start a new OpenGL fullscreen window, but want it open with the same horizontal and vertical size ...
46
votes
13
answers
30k
views
Are there any downsides to using UPX to compress a Windows executable?
I've used UPX before to reduce the size of my Windows executables, but I must admit that I am naive to any negative side effects this could have. What's the downside to all of this packing/unpacking?
...
44
votes
14
answers
62k
views
How do I recursively create a folder in Win32?
I'm trying to create a function that takes the name of a directory (C:\foo\bar, or ..\foo\bar\..\baz, or \\someserver\foo\bar), and creates directories as necessary so that the whole path is created.
...
44
votes
1
answer
28k
views
WinAPI: Create a window with a specified client area size
I was wondering how can I create a window using Win32 API with a specific client area size.
When trying to create a window using the following piece of code, the entire window is 640x480, with the ...
43
votes
2
answers
67k
views
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?
43
votes
6
answers
29k
views
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 ...
43
votes
1
answer
31k
views
Code analysis says Inconsistent annotation for 'wWinMain' : this instance has no annotations
I'm writing some simple win32 stuff and I'm using the following wWinMain
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
PWSTR pCmdLine, int nCmdShow)
VS2012 ...