c++,windows,winapiRelated issues-Collection of common programming errors


  • LachlanB
    c# c++ dependencies
    Currently we are using Source Safe and have started migration to Subversion. All of our external SDK’s(> 500 MB) are held in Source Safe right now, and I am looking for ways to move them from VSS to a repository.We have C++ (mostly), C# (many), Java (few) projects. Hundreds of projects, all running on Windows.I looked at a couple of dependency managers but I’m not satisfied:NuGet – good for .Net but painful for C++ Ivy – not look in depth, but doesn’t seem acceptable for C++First question: what

  • Jamal
    c++ game parsing
    I am currently writing my first actual C++ project. I like Chess and I would like to see how good I’m doing on a monthly basis, so the idea is to read the log files (.pgn files) from the games and tell me how many games I won and such.My question specially relates to Games.cpp where I’m not sure I have done the right thing in having both a getMonths() returning a list of all the months I have played a game and a getGamesByMonth(std::string month) returning all the games played on a given month.

  • MadScienceDreams
    c++ templates c++11 variadic-templates
    So someone asked a question then deleted it, but I found it an interesting challenge.They had this weird type, and had run into the problem that Concat and Range were castable to Sequences but were not Sequences (for obvious reasons)template<unsigned… Is> struct Sequence{}; template<typename… Is> struct Concat{}; template<unsigned… Is> struct Concat<Sequence<Is…>> : public Sequence<Is…> {}; template<unsigned… Is, unsigned… Js, typename… R

  • Michael Stum
    c++ c random
    I’m adapting a Mersenne Twister in my Application, specifically mt19937ar.c from http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/MT2002/emt19937ar.html – Code is mirrored on https://gist.github.com/mstum/8367363This is used as a deterministic RNG in a game, and to make save games work as expected I need to get the current seed out of the MT (rather than the initial seed) so that I can resume.Example, let’s say I initialize it with a seed of 12345 and call genrand_int31 5 times. This yields the s

  • Eric
    c++ c
    I’ve seen posts talk about what might cause differences between Debug and Release builds, but I don’t think anybody has addressed from a development standpoint what is the most efficient way to solve the problem.The first thing I do when a bug appears in the Release build but not in Debug is I run my program through valgrind in hopes of a better analysis. If that reveals nothing, — and this has happened to me before — then I try various inputs in hopes of getting the bug to surface also in the

  • Tronic
    c++ xml linux xerces
    I’m searching for a tutorial to load a XML file, read it, change it and finally save it with C++. I’m using Linux Ubuntu and tried to use Xerces. With Google and much time, I could only load an XML File:#include <xercesc/parsers/XercesDOMParser.hpp> #include <xercesc/dom/DOM.hpp> #include <xercesc/sax/HandlerBase.hpp> #include <xercesc/util/XMLString.hpp> #include <xercesc/util/PlatformUtils.hpp>#include <iostream>using namespace std; using namespace xercesc;i

  • leemes
    c++ json qt parsing qt5
    I have a string which contains (not is) JSON-encoded data, like in this example:foo([1, 2, 3], “some more stuff”)| |start end (of JSON-encoded data)The complete language we use in our application nests JSON-encoded data, while the rest of the language is trivial (just recursive stuff). When parsing strings like this from left to right in a recursive parser, I know when I encounter a JSON-encoded value, like here the [1, 2, 3] starting at index 4. After parsing this substring, I need

  • ciamej
    java c++ performance caching optimization
    if (var != X)var = X;Is it sensible or not? Will the compiler always optimize-out the if statement? Are there any use cases that would benefit from the if statement?What if var is a volatile variable?I’m interested in both C++ and Java answers as the volatile variables have different semantics in both of the languages. Also the Java’s JIT-compiling can make a difference.The if statement introduces branching and additional read that wouldn’t happen if we always overwrote var with X, so it’s bad.

  • Gzorg
    c++
    I’m working with a class for which the new operator has been made private, so that the only way to get an instance is to writeFoo foo = Foo()WritingFoo* foo = new Foo()does not work.But because I really want a pointer to it, I simulate that with the following :Foo* foo = (Foo*)malloc(sizeof(Foo)); *foo = Foo();so that can test whether the pointer is null to know whether is has already been initialized.It looks like it works, from empirical tests, but is it possible that not enough space had been

  • djwbrown
    c++ arrays pointers structure
    I’m having trouble understanding arrays of pointers to structures. I created this simple example to try and understand them better. Although it compiles, I keep getting “BAD ACCESS” crashes (nonsense pointers) at the point shown below. Can anyone explain why this is wrong?#include <iostream> using namespace std;struct complex_num {double real_part;double imag_part; };void init_complex(complex_num *element) {element->real_part = -1.0; // <— EXECUTION STOPS HERE.element-&

  • 8088
    windows windows-vista video display resolution
    I’ve got a 22-inch, 1680 x 1050 monitor. Brand X2gen, model MW22U. Connected by DVI cable to my NVIDIA GeForce 9600 GT graphics card.Several days ago my monitor stopped working. It displayed nothing after the boot process.I loaded Safe Mode which forced it to 1024 x 768, which did display. I installed updated drivers for my graphics card (NVIDIA GeForce ION Driver 185.85) which forced it to 1024 x 768 when I then returned to Normal Mode.But I cannot set it to a resolution higher than 1024 x

  • slhck
    windows display
    I own a netbook whose default (recommended) resolution is 1024 x 600. However, when I fire up the display (graphics) properties page, I am shown that the display is a Digital Flat Panel (1280 x 1024 60 Hz). Does this imply that the display actually supports 1280 x 1024 resolution as default? I am confused, since I don’t see any option to set the above resolution, and I’ve failed to try saving the resolution under “Custom” resolutions inside the graphics properties page.

  • AviD
    appsec cryptography source-code windows key-management
    I have an application that is creating several keys and storing them in various stores (in this case the Machine store).How can I enumerate all the keys on a given Windows system?CspParameters cspParams = new CspParameters();cspParams.KeyContainerName = containerName + ” ” + g.ToString() ;cspParams.Flags = CspProviderFlags.UseMachineKeyStore;// Create a new RSA key and save it in the container. This key will encrypt// a symmetric key, which will then be encryped in the XML document.RSACryptoSer

  • Jonas
    appsec windows
    Often when I install applications on my computer, I realize that I need to trust the application because it can do what ever it want with my computer, e.g. accessing files, listen to my keyboard, monitor my network and so on.This feels unsecure. E.g. on Windows 7, how can I control or restrict what an application that I install can do on my computer? Is there any software tools for this or should I create a new user account every time I install an application or how to handle software installs?O

  • Costa
    windows gui language-choice
    Expertise: 11 years PHP programmingI’d like to get into simple Windows programming for a kiosk project. What language should I choose?My criteria:easy to learn, “higher”-level language (e.g. not C++, I don’t have a year to learn this) quick to get up-and-running (that’s what I loved about PHP) well-documented & lots of community resources easy GUI creation client wants windows machines so Linux is not an optionWhat I’ve gathered from other Stackexchange answers and Google, but have no exper

  • izx
    installation windows wubi
    I’m trying to install Wubi from Windows, and it fails half-way with this error:”None Type” object has no attribute ‘get_info’ c:\user\hp\Appdata\local\temp\wubi-12.04rev266How can I complete Wubi installation?

  • Toni Toni Chopper
    windows batch-file cmd
    I have a which.bat on Windows 7,@echo off REM This bat searches a file in PATH list to see whether a file can be found. REM If found, it shows the file’s full path. REM which.bat gcc.exe REM shows REM gcc.exe is found: D:\GMU\MinGW2\bin\gcc.exe REM REM Note: Filename extension is significant in the search. E.g. If you run REM which.bat gcc REM gcc.exe will not be matched.IF “%1” == “” goto ENDIF “%~$PATH:1” == “” (echo %1 is not found in any directories from PATH env-var.) ELSE (ech

  • admdrew
    windows visual-studio-2010 networking installer directory-structure
    I have a C++ Windows application built in Visual Studio 2010 with a Setup project to create an .msi that installs fine when users have a local My Documents folder, but fails when their My Documents folder is located on a network drive.When installed locally, the installer creates Project and Data folders in their My Documents folder, but when I try to install to system with My Documents in a network location, the .msi fails with the cannot access network location error message. Looking at the in

  • EpicTonic
    windows batch-file cmd
    -BASIC INFORMATION I have this sourceforge project called E-Series which makes certain coding tasks more easier, in this question I’ll specifically be talking about “Easy Command Line” from E-Series.-NOTES-Once again, In the title as well, calling the batch file from original cmd (Access it by going to Run>cmd) does work, however calling it from a .bat file designed to call it does not.-the batch file i’m calling has parameters.-WHAT I’VE GOTHERE are all the files required to run the whol

  • Martin Brown
    windows datetime formatting batch-file
    In a windows (XP) batch script I need to format the current date and time for later use in files names etc.,Similar to How to append a date in batch files but with time in as wellI have this so far:echo %DATE% echo %TIME% set datetimef=%date:~-4%_%date:~3,2%_%date:~0,2%__%time:~0,2%_%time:~3,2%_%time:~6,2% echo %datetimef%which gives:28/07/20098:35:31.01 2009_07_28__ 8_36_01Is there anyway I can allow for single digit hour in %TIME% so I can get:2009_07_28__08_36_01

  • thudbang
    winapi
    Is it possible to wait for all processes launched by a child process in Windows? I can’t modify the child or grandchild processes.Specifically, here’s what I want to do. My process launches uninstallA.exe. The process uninistallA.exe launches uninstallB.exe and immediately exits, and uninstallB.exe runs for a while. I’d like to wait for uninstallB.exe to exit so that I can know when the uninstall is finished.

  • jesse
    windows winapi visual-c++ timer
    I faced a strange behavior with waitable timers. If I create it with one-second period then after the first firing, its following firings seem to be “aligned” to some millisecond value which differs significantly from first firing.Here is example of fire times (hours:minutes:seconds.milliseconds):18:06:25.753 <– here 753 18:06:26.238 <– here and later 238 18:06:27.238 18:06:28.238 18:06:29.238If I re-run the program, the millisecond value of first firing is different, but the subsequen

  • Jehjoa
    c++ windows winapi exception-handling
    I’m using a self written exception class called windows_error that inherits from std::runtime_error, which I use to, well, properly handle unexpected errors from Windows API functions.All the way on the bottom of the callstack, at the end of my WinMain function, I catch all windows_error exceptions that haven’t been dealt with yet. I intend to handle them by display an error message right before the program terminates, like so:int WINAPI wWinMain(HINSTANCE inst, HINSTANCE prev, wchar_t *cmdline,

  • Aczire
    c++ windows winapi error-handling
    Any idea why this happens? The method works flawlessly for the currentprocess and fails for remote process running on the same local machine with a garbage error code 2147483661 (0x80000000D) for me, since there is no hint at all anywhere about this particular error code, or am i missing something?. Also, I feel; since SymInitialize itself failed, and so is SymFromAddr. Am I correct?The process in question is running as admin and does have the SeDebug and SeSecurity Privileges.bool DbgHelpWrapp

  • James
    c++ c windows multithreading winapi
    I’d like to access a spawned process’s TIB (I created the process with CreateProcessW successfully).I have obtained a pointer to the spawned process’s TIB through:GetThreadContext (with permissions set of course) Accessing pContext.SegFs Formatting this value like so: (ldtSel.HighWord.Bits.BaseHi << 24 ) | ( ldtSel.HighWord.Bits.BaseMid << 16 ) | ( ldtSel.BaseLow ); (I don’t think this is necessary).The value I am left with after the format is a 10 digit pointer.How am I to use this

  • Gareth McCaughan
    windows winapi virtual-desktop
    [I have found the answer to this, but I’m asking it anyway so that if anyone else has the same problem they can find it. Answer to follow a minute or so after the question.]I’m hacking together something that lists every window on my Windows box, and it seems that for (only) one of my windows GetWindowRect is returning a rectangle with very negative y-coordinates.Possible complications: (1) I have multiple monitors but (1a) the y-coordinate is very negative, on the order of -24000, and (1b) othe

  • Sss
    c++ winapi stream dynamic-memory-allocation
    I have created preview handler for a file and when i click on that file i get the preview of that file in preview pane and what the scene behind is i read the file by creating a stream and and that stream i store in a buffer and then i play with the buffer contents in order to create the preview on preview pane.Now my question is that i want to allocate the size of that file(of which i have create dpreview handler) dynamically (using visual c++) so that i would not need to allocate the memory

  • user2808671
    c++ winapi
    If I write a simple code like this:int main(int argc, char* argv[]) {HANDLE hEvent = CreateEventW( NULL, FALSE, FALSE, L”EVENTTEST” );if (hEvent==NULL){cout<<“Error “<<GetLastError();}else{cout<<“Success”;}getch();return 0; }the code runs with success message but if I add some declaration in general scope above main (here I only add a line of code by declaring a bool variable) the function CreateEvenetW Fails with error code 998. If I use CreateEvent instead of CreateEventW no

  • P. Avery
    c++ visual-studio-2008 winapi graphics gdi+
    I’m using win32 for 2D animation. My program so far loads an array of HBITMAP objects created from resource. The problem arises during animation when calling CreateCompatibleDC() from “OnUpdate()” in code below. AFTER MANY CALLS to the OnUpdate function, the HDC object is not created(possibly not allocated in memory). This causes unexpected results when DeleteDC() is called to delete the HDC object. Here is the update function code from main.cpp:void OnUpdate(HWND hwnd) {PAINTSTRUCT ps;HDC hdc =

  • Yippie-Ki-Yay
    c++ winapi assert
    I am developing a simple WinAPI application and started from writing my own assertion system.I have a macro defined like ASSERT(X) which would make pretty the same thing as assert(X) does, but with more information, more options and etc.At some moment (when that assertion system was already running and working) I realized there is a problem. Suppose I wrote a code that does some action using a timer and (just a simple example) this action is done while handling WM_TIMER message. And now, the sit

Web site is in building