c++

What's the difference between calling CComModule.RegisterServer, _AtlComModule.RegisterServer, and LoadTypeLibEx for TypeLib registration?

In my DllRegisterServer method of my COM dll, I previously had code that called LoadTypeLibEx(module, REGKIND_REGISTER, &pTypeLib) to register my COM classes and their corresponding TypeLib's. My COM DLL is a 64-bit. I've noticed that on my 64-bit Vista system, under HKCR:\\TypeLib\{myguid}\1.0\0 I find a win32 subkey with the location t...

Search for nearest value in an array of doubles in C++?

I have a sorted array of double values in C++. Is there an STL function that will return the index of the nearest value in the array to a given double value? For example, given the following array double myarray[5] = { 1.0, 1.2, 1.4. 1.5, 1.9 }; the function call search(myarray, 1.6); should return 3, the index of the element nea...

How can I categorize the memory usage of a NON-.NET application/DLL ?

I have a 32-bit Visual Studio 8.0 C++ Windows DLL (non-.NET) that appears to be taking up more memory than I would expect. I want to determine exactly where the memory is going, not just a single figure of the total memory used (not interested in Task Manager or Resource Monitor's memory usage values). Back in 16-bit days HeapWalker was...

Setting boost dynamic_bitset from a string

Dynamic bitset I have a use case where i need to populate boost::dynamic_bitset<unsigned char> , from a std::string buffer. Can you suggest as to how to go about this. So I need to come up with a function void populateBitSet (std::string &buffer, boost::dynamic_bitset<unsigned char> & bitMap) { //populate bitMap ...

monitor cpu usage per thread on windows mobile device

Is is possible to measure CPU per thread on a windows mobile (or CE 5) device programmatically (c++)? If not, is their a utility that will monitor the CPU usage of a process? ...

InvalidateRect in WM_CREATE does not work

I want to invalidate the window when it's created. How can I do that? calling InvalidateRect during WM_CREATE doesn't work. The thing is I call SetWindowLongPtr in WM_CREATE and set GWLP_USERDATA. WM_PAINT looks for some pointer in USER_DATA but the first time I receive WM_PAINT the data isn't apparently still there so it doenst paint m...

Bison does not appear to recognize C string literals appropriately

Hi Folks, My problem is that I am trying to run a problem that I coded using a flex-bison scanner-parser. What my program is supposed to do is take user input (in my case, queries for a database system I'm designing), lex and parse, and then execute the corresponding actions. What actually happens is that my parser code is not correctly...

std::map design: why map accept comparator as template parameter

Map type from STL have next type: std::map< Key, Data, Compare, Alloc > As one of template parameters we could pass Compare predicate, why map accept this predicate as template parameter and not as object in constructor? It could has more flexible interface with something like boost::function< bool, const T&, const T& > in constr...

Is int x = 'fooo' a compiler extension?

I have seen and used C++ code like the following: int myFourcc = 'ABCD'; It works in recent versions of GCC, not sure how recent. Is this feature in the standard? What is it called? I have had trouble searching the web for it... EDIT: I found this info as well, for future observers: from gcc documentation The compiler values a...

change volume win32 c++

How would I go about changing the sound volume in c++ win32? Also how would I mute/unmute it? Thanks for the help! ...

C++ binary constant/literal

I'm using a well known template to allow binary constants template< unsigned long long N > struct binary { enum { value = (N % 10) + 2 * binary< N / 10 > :: value } ; }; template<> struct binary< 0 > { enum { value = 0 } ; }; So you can do something like binary<101011011>::value. Unfortunately this has a limit of 20 digits for a ...

What would be a good programming language (or a set of libraries for C++) to interface with electronic components (stepper motors etc.)?

I'm not an electronics guy, so I might not be able to explain precisely what I need. This is a question a friend keeps asking me. What my friend is looking for is a programming language that would allow him to: Interface with hardware (via serial and USB ports). Write multithreaded code. Throw together UIs very quickly. Port his code ...

Memory Allocation Profiling in C++

I am writing an application and am surprised to see its total memory usage is already too high. I want to profile the dynamic memory usage of my application: How many objects of each kind are there in the heap, and which functions created these objects? Also, how much memory is used by each of the object? Is there a simple way to do thi...

A Large Number of sp_counted_impl_p Objects

I just performed Allocation Profiling about how many objects of each type are in my application. I am using boost::shared_ptr extensively. I found a large number of sp_counted_impl_p objects allocated, each occupying 16 bytes. How many of sp_counted_impl_p objects can be expect per shared_ptr? Does someone have an idea? ...

High Resolution Timing Part of Your Code

Dear all, I want to measure the speed of a function within a loop. But why my way of doing it always print "0" instead of high-res timing with 9 digits decimal precision (i.e. in nano/micro seconds)? What's the correct way to do it? #include <iomanip> #include <iostream> #include <time.h> int main() { for (int i = 0; i <100; i++) {...

How to get the SPID in linux 2.6 from C++

Hi! I have a question: Is there some way to the SPID in linux 2.6 from a C++ application? When I do a "ps -amT" I can see the threads in the process: [email protected]:~# ps -amT PID SPID TTY TIME CMD 1120 - pts/1 00:00:20 sncmdd - 1120 - 00:00:00 - - 1125 - 00:00:00 - - 1126 - 00...

How can I write a program which can test throughput of disk?

How can I write a program which can test throughput of disk in Windows systems using c++? What's the mainly steps and APIs that I can use to programming? ...

Is it safe to store objects of a class which has an std::auto_ptr as its member variable in std::vector?

I can't use shared_ptr in my project, no boost :( So, I'm having a class roughly similar to the one below: class MyClass { private: std::auto_ptr<MyOtherClass> obj; }; Now, I want to store the instances of above class in std::vector. Is it safe? I've read here that it's wrong to use std::auto_ptr with STL containers. Does it apply ...

QT4.4 how to get the user settings path

linux: $HOME/.config windows: %APPDATA% mac os: $HOME/.config It can be set using http://doc.trolltech.com/4.4/qsettings.html#setPath, but it seems as I am not able to retrieve it. http://doc.trolltech.com/4.4/qlibraryinfo.html#location QLibraryInfo::LibrariesPath returns the system wide settings dir, which is not what I want. Any i...

Are there generic rules to design good class templates ?

I work in a department where people create (or select) algorithms that they implement in small-sized software to optimize some field-related objectives. Most of my colleagues know more about mathematical modelling and solvers than about programming. I personally have a few years of experience developping C++ class templates. I pretty mu...