c++

SetThreadName not working with Visual Studio 2005

SetThreadName does not set thread name with Visual Studio 2005, when used as below: DWORD threadId; HANDLE handle = CreateThread(NULL, stackSize, ThreadFunction, ThreadParam, CREATE_SUSPENDED, &threadId); if (handle) { SetThreadName(threadId, "NiceName"); ResumeThread(handle); } After opening the Th...

Looking for design advise - Statistics reporter

I need to implement a statistics reporter - an object that prints to screen bunch of statistic. This info is updated by 20 threads. The reporter must be a thread itself that wakes up every 1 sec, read the info and prints it to screen. My design so far: InfoReporterElement - one element of info. has two function, PrintInfo and UpdateDat...

Struct with template variables in C++

I'm playing around with templates. I'm not trying to reinvent the std::vector, I'm trying to get a grasp of templateting in C++. Can I do the following? template <typename T> typedef struct{ size_t x; T *ary; }array; What I'm trying to do is a basic templated version of: typedef struct{ size_t x; int *ary; }iArray; It look...

how to do virtualization ?

Hi, I am newbie in vc++. I have configured my system with WDK,DDK and Visual Studio 2008. I want to implement dual functionality to my wireless hardware and i am using Vista so please help me out from here. so just tell me which function should i use Thanks in advance... :) ...

container won't sort, test case included, (easy question?)

I can't see what I'm doing wrong. I think it might be one of the Rule of Three methods. Codepad link #include <deque> //#include <string> //#include <utility> //#include <cstdlib> #include <cstring> #include <iostream> //#include <algorithm> // I use sort(), so why does this still compile when commented out? #include <b...

C++ expected constant expression

#include <iostream> #include <fstream> #include <cmath> #include <math.h> #include <iomanip> using std::ifstream; using namespace std; int main (void) { int count=0; float sum=0; float maximum=-1000000; float sumOfX; float sumOfY; int size; int negativeY=0; int positiveX=0; int negativeX=0; ifstream points; //the points to be imported ...

Suppress excel add-in confirmation message

I am accessing excel with C++ and add-ins are being loaded. Everything we load the add-in programatically, the user has to click ok when the add-in is unloaded and loaded. Some users have complained that this can be as much as 20 times for a "run." How can I programatically suppress the add-in confirmation messages? NOTE: excelApp...

Does the compiler optimize the function parameters passed by value?

Lets say I have a function where the parameter is passed by value instead of const-reference. Further, lets assume that only the value is used inside the function i.e. the function doesn't try to modify it. In that case will the compiler will be able to figure out that it can pass the value by const-reference (for performance reasons) an...

Optimizing sorting container of objects with heap-allocated buffers - how to avoid hard-copying buffers?

I was making sure I knew how to do the op= and copy constructor correctly in order to sort() properly, so I wrote up a test case. After getting it to work, I realized that the op= was hard-copying all the data_. I figure if I wanted to sort a container with this structure (its elements have heap allocated char buffer arrays), it'd be fa...

Verbosity in boost asio using ssl.

Is there a way to make ssl handshake more visible to me using boost asio? I am getting an error: "asio.ssl error". I just want more verbosity, because this message means almost nothing to me. Thanks. ...

How to force a window to maintain a certain width/height ratio when resized

I want my window to always maintain a certain ratio of let's say 1.33333333. So, if the window is width = 800, height = 600 and the user changes the width to 600, I want to change the height to 450 automatically. I'm already intercepting WM_SIZE but I don't know if it's enough; also I don't know how to change the width or height to main...

Chaining multiple ShellExecute calls

Consider the following code and its executable - runner.exe: #include <iostream> #include <string> #include <windows.h> using namespace std; int main(int argc, char *argv[]) { SHELLEXECUTEINFO shExecInfo; shExecInfo.cbSize = sizeof(SHELLEXECUTEINFO); shExecInfo.fMask = NULL; shExecInfo.hwnd = NULL; shExecInfo.lpV...

Program compiled with MSVC 9 won't start on a vanilla SP3 XP

I installed XP on a virtual machine, updated it to SP3 and then tested a small program compiled with Visual C++ 2008 on my real computer - however it didn't start but outputted only an error saying that a problem had been detected and that a reinstall of the application (mine is 10KB in size and doesn't even have an installation) could f...

DLL entry point

The standard DLL entry point is called DllMain. The second param is DWORD ul_reason_for_call. I have looked up on the MSDN to find all the values this can have, the following are obvious: DLL_PROCESS_ATTACH: DLL_THREAD_ATTACH: DLL_THREAD_DETACH: DLL_PROCESS_DETACH: But what about : DLL_PROCESS_VERIFIER When will the entry point be...

Dos create a batch file and run with multiple C++ programs.

Respected sirs, My name is @nimit. I want to create a batch file and run it in a DOS prompt. The batch file will execute a C++ program I've written. The output should be stored in a single text-file. How can I do this? The C++ program output should be stored in a particular text file. Thanks in advance, @nimit ...

Linux time sample based profiler.

short version: Is there a good time based sampling profiler for Linux? long version: I generally use OProfile to optimize my applications. I recently found a shortcoming that has me wondering. The problem was a tight loop spawning c++filt to demangle a c++ name. I only stumbled upon the code by accident while chasing down another b...

Isn't the C++ standard library backward-compatible?

Hi. I'm working on a 64-bit Linux system, trying to build some code that depends on third-party libraries for which I have binaries. During linking, I get a stream of undefined reference errors for one of the libraries, indicating that the linker couldn't resolve references to standard C++ functions/classes, e.g.: librxio.a(EphReader...

How to iterate on boost::mutable_queue

Hello, I need a priority queue where I can increase or decrease the priority key. So boost::mutable_queue seemed perfect despite the lack of documentation. The problem is that I need to iterate at some point over all the elements in the queue. How can I do that? Or is there an othe data structure that would work (preferably in boost)?...

What does deleting a pointer mean?

Is deleting a pointer same as freeing a pointer (that deallocates the memory)? ...

C++ shifting bits

I am new to shifting bits, but I am trying to debug the following snippet: if (!(strcmp(arr[i].GetValType(), "f64"))) { dem_content_buff[BytFldPos] = tmp_data; dem_content_buff[BytFldPos + 1] = tmp_data >> 8; dem_content_buff[BytFldPos + 2] = tmp_data >> 16; dem_content_buff[BytFldPos + 3] = tmp_data >> 24; ...