All Questions

Tagged with
Filter by
Sorted by
Tagged with
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.
user avatar
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 ////////////////////////////////////////////...
clamp's user avatar
  • 33.5k
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 ...
dreadwail's user avatar
  • 15.3k
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
Toran Billups's user avatar
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. ...
Kiril's user avatar
  • 40.1k
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.
Donotalo's user avatar
  • 12.9k
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.
magnus's user avatar
  • 4,201
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 ...
lhj7362's user avatar
  • 2,223
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()...
user avatar
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 '...
izb's user avatar
  • 50.9k
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 ...
nolandda's user avatar
  • 2,254
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 ...
Johannes Stricker's user avatar
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-...
conmulligan's user avatar
  • 7,098
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 ...
Ken Li's user avatar
  • 2,578
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 ...
Zombies's user avatar
  • 25.4k
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-...
JSBձոգչ's user avatar
  • 41.1k
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, ...
Adam Haile's user avatar
  • 31.1k
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 ...
khkarens's user avatar
  • 1,325
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 ...
John M Gant's user avatar
  • 19.2k
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 ...
Nassim Assaf's user avatar
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 ...
ApprenticeHacker's user avatar
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.
Malfist's user avatar
  • 31.5k
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 ...
minty's user avatar
  • 22.3k
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".
Alexey Malistov's user avatar
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?
TCS's user avatar
  • 5,822
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 ...
Pyjong's user avatar
  • 3,167
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.
Matt's user avatar
  • 781
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,...
AutoBotAM's user avatar
  • 1,515
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)...
Jorge Ferreira's user avatar
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?
Simon's user avatar
  • 25.7k
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.
jm.'s user avatar
  • 23.6k
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 ...
I Phantasm I's user avatar
  • 1,671
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?
user63898's user avatar
  • 30.4k
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?
Haim Bender's user avatar
  • 8,057
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 ...
adoss's user avatar
  • 1,131
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?
DylanJ's user avatar
  • 2,383
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?
kookoo121's user avatar
  • 1,126
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,...
default's user avatar
  • 11.5k
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 ...
sep's user avatar
  • 3,445
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 ...
Oliver Zheng's user avatar
  • 8,021
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::...
NaturalDemon's user avatar
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?
Ramilol's user avatar
  • 3,434
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?
MaSmi's user avatar
  • 587
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 ...
Prof. Falken's user avatar
  • 24.6k
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? ...
Mick's user avatar
  • 13.4k
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. ...
pauldoo's user avatar
  • 18.3k
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 ...
GeReV's user avatar
  • 3,225
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?
user avatar
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 ...
ggambetta's user avatar
  • 3,392
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 ...
EddieV223's user avatar
  • 5,183

1
2 3 4 5
372