c++

Dynamic loaded libraries and shared global symbols

Since I observed some strange behavior of global variables in my dynamically loaded libraries, I wrote the following test. At first we need a statically linked library: The header test.hpp #ifndef __BASE_HPP #define __BASE_HPP #include <iostream> class test { private: int value; public: test(int value) : value(value) { std::...

C++: Copying to dereferenced pointer...

Hi. I currently have a weird problem with a program segfaulting but im not able to spot the error. I think the problem boils down to this. struct S {int a; vector<sometype> b;} S s1; // fill stuff into a and b S* s2 = new S(); *s2 = s1; Could it be that the final copying is illegal in some way? Im really confused right now... Thanks ...

Question about a possible design pattern...

I have such a design in my mind.... My aim is to reuse the program with some features included and without some features. What is it called in the literature? More information: there are events.. Events cause calls to function1() or function2()... Features have functions which are called when events takes place. A feature may influence ...

why do I need virtual table?

I was looking for some information about virtual table, but can't find something easy to understand, can somebody give me good example(not from Wiki, please), with explanations, or link, thanks in advance ...

c++ repaint window

i got a window with an image in it. but when its a little picture i first need to resize the window before i can see it, the screen doesnt refresh/repaint. how can i fix this? ...

Writing booleans to file

Hello, I have a piece of code that gives a runtime error. Can anyone help find out why? vector<int> intData; vector<bool> boolData; for(int i=0;i<19000;i++) boolData.push_back(false); string ofile = "tree.dat"; ofstream fout(ofile.c_str(),ios::out | ios::binary); if (!boolData.empty()) fout.write((char *)&boolData[0], size...

C++ Using a class template argument as a template argument for another type

Hey Everyone, I'm having this problem while writing my own HashTable. It all works, but when I try to templatize the thing, it gave me errors. I recreated the problem as follows: THIS CODE WORKS: typedef double Item; class A { public: A() { v.push_back(pair<string, Item>("hey", 5.0)); } void iterate() { ...

Portable way of counting milliseconds in C++ ?

Hi, Is there any portable (Windows & Linux) way of counting how many milliseconds elapsed between two calls ? Basically, I want to achieve the same functionnality than the StopWatch class of .NET. (for those who already used it) In a perfect world, I would have used boost::date_time but that's not an option here due to some silly rule...

Can a custom MFC window/dialog be a class template instantiation?

There's a bunch of special macros that MFC uses when creating dialogs, and in my quick tests I'm getting weird errors trying to compile a template dialog class. Is this likely to be a big pain to achieve? Here's what I tried: MyDlg.h template <class W> class CMyDlg : public CDialog { typedef CDialog super; DECLARE_DYNAMIC(CMyD...

GetVolumeNameForVolumeMountPoint returns false

Hi.. To get the volume GUID i tried the code like below int len = wcslen( pDetData->DevicePath); pDetData->DevicePath[len] = '\\'; pDetData->DevicePath[len+1] = 0; #define BUFFER_SIZE MAX_PATH WCHAR volume[BUFFER_SIZE]; BOOL bFlag; bFlag = GetVolumeNameForVolumeMountPoint( pDetData->DevicePath, volume, BUFFER_SIZE ); int loginErrCode...

How can I login linux using C or C++

I need to programmely switch the current user to another,then the followed code should be executed in the environment(such as path,authority..) of another user. I've find the 'chroot()','setuid()' may be associated with my case, but these functions need the root authority, I don't have root authority, but I have the password of the seco...

Getting hardware floating point with android NDK

Hi All, I've begun playing with the android NDK. One of the things I've just learnt is about creating an application.mk file to specify the armv7 abi. I'm building the san-angeles example with the following parameters. APP_MODULES := sanangeles APP_PROJECT_PATH := $(call my-dir)/../ APP_OPTIM := release APP_ABI ...

Counting of objects created in stack and heap for many classes

What is the best way to count the total number of objects created in both stack and heap for different classes. I know that in C++ new and delete operators can be overloaded and hence in the default constructor and destructor the object count can be incremented or decremented as and when the objects get created or destroyed. Further if ...

C or C++: how do loaders/wrappers work?

Here's an example of what I mean... User runs LOADER.EXE program LOADER.EXE downloads another EXE but keeps it all in memory without saving it to disk Runs the downloaded EXE just as it would if it were executed from disk, but does it straight from memory I've seen a few applications like this, and I've never seen an example or an ex...

in C++, what is the best method to feed the O/P of one function to another function?

Under these conditions, The o/p of the first program is an large array of either integers, doubles or strings. Best method means the fastest on x86 architecture. o/p means output. Sorry for being unclear. ...

Throwing Exception in CTOR and Smart Pointers

Is it OK to have the following code in my constructor to load an XML document into a member variable - throwing to caller if there are any problems: MSXML2::IXMLDOMDocumentPtr m_docPtr; //member Configuration() { try { HRESULT hr = m_docPtr.CreateInstance(__uuidof(MSXML2::DOMDocument40)); ...

Receive many datagrams from several hosts using winsock

Dear stackers. I am developing an application that distributes rendering across several devices (a university project). Each frame consists of several blocks (16x16 pixels), and each device is "assigned" a number of blocks to be rendered. These blocks, when rendered, are compressed and serialized into a buffer until the max size of thi...

Windows DDK development with MinGW?

Is it possible to develop a Windows driver (specifically a PDF-like printer driver that displays the data on-screen instead of actually printing) without using Visual Studio? I'm thinking of using free C++ tools such as MinGW/gcc. ...

How to store array in one column in Sqlite3?

Hi, Is there any way to store an array of integers in one column of table? I want o/p like this: ident | value | count ----------------+------------------------------------------------------------------------------------------------------------------------+------- 563 | [0:10]...

How to concat two c++ map

Hello, Anybody knows how to concat these two map: map<string, map<string,string>> map1; map<string, map<string,string>> map2; I just want to add map2 to map1 and keep all elements already in map1 i.e. add map2 at the end of map1. I'v tried map1.insert(map2.begin(), map2.end()) but it does not work since it overwrites old elements in ...