c++

Is it practically safe to write static data from multiple threads

I have some status data that I want to cache from a database. Any of several threads may modify the status data. After the data is modified it will be written to the database. The database writes will always be done in series by the underlying database access layer which queues database operations in a different process so I cam not con...

Allocating large blocks of memory with new.

I have the need to allocate large blocks of memory with new. I am stuck with using new because I am writing a mock for the producer side of a two part application. The actual producer code is allocating these large blocks and my code has responsibility to delete them (after processing them). Is there a way I can ensure my application i...

dynamic_cast fails

I have a base class and a derived class. Each class has an .h file and a .cpp file. I am doing dynamic_cast of the base class object to the derived class in the following code: h files: class Base { public: Base(); virtual ~Base(); }; class Derived : public Base { public: Derived(){}; void foo(); }; class Another...

Powerful audio lib

Hi Can you recommend a powerful audio lib? I need it to timestrech & pitchshift independently, as well as give me full access to the raw audio data and let me stream bytes into its pipeline. Other effects like eq, filtering, distortion are a plus. Needs to be accessible from C++ / Linux. Maybe gstreamer, xine or mplayer would work? ...

Dealing with accuracy problems in floating-point numbers

I was wondering if there is a way of overcoming an accuracy problem that seems to be the result of my machine's internal representation of floating-point numbers: For the sake of clarity the problem is summarized as: // str is "4.600"; atof( str ) is 4.5999999999999996 double mw = atof( str ) // The variables used in the columns...

Can the list of C++ files in a Visual Studio project be dynamically filled ?

I have a tool that generates most (but not all) files that need to be compiled in Visual Studio. The tool reads a configuration file and generates c++ files afterwards. This list can differ from one call to another when the configuration is altered. I am wondering whether it would be possible to adapt the compiling process to my needs, ...

how to declare volatile iterator in c++

Is there a way to declare an iterator which is a member variable in a class and that can be incremented using a member function even though the object of that class is const. ...

how to handle exceptions in C# DLL loaded by C++

I have a DLL that is created in C# for the purpose of providing a COM interface to a third-party C# library. I have a C++ program that uses that COM interface so that it can communicate with the C# library. Sometimes, exceptions get thrown on the C# side and all I get back on the C++ side is an HRESULT from the COM invocation that says...

C++ dll Loop Problem

Hi there. Im having a problem with a loop inside a C++ dll being called from VB. I want this loop to update a global variable, but when I call the function the variable does not update the first time round, but does so every subsequent time. This is how I am trying to update the variable. else { ::nScore = nHighest; if (nScor...

Am I geting a structure copy here?

Here is a fake code sample vector<Fred> gFred; { // init gFred Fred &fred = gFred[0]; size_t z = 0; do { fred = gFred[z]; // do odd processing with fred z++; } while (fred.lastElementInSet == 0); } The thing that caught my attention was the fact that gFred[0] was being overwritte...

why doesn't winmain set the errorlevel?

int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { MessageBox(NULL, _T("This should return 90 no?"), _T("OK"), MB_OK); return 90; } Why does the above program correctly display the message box, but does not se...

static vs extern "C"

(expert C/C++ question) What is the difference between a static member function and an extern "C" linkage function ? For instance, when using "makecontext" in C++, I need to pass a pointer to function. Google recommends using extern "C" linkage for it, because "makecontext" is C. But I found out that using static works as well. Am I just...

C++ - How to set file permissions (cross platform)

Hi guys. I am using C++ ofstream to write out a file. I want to set the permissions to be only accessible by the user: 700. In unix; I suppose I can just issue a system("chmod 700 file.txt"); but I need this code to work on windows as well. I can use some windows api; but what is the best c++ cross platform way to do this? ...

Smart Pointers with "this" in C++

I have been working on replacing raw pointers with reference-counted pointers that expose only a const version of the underlying one. My objective is to reduce memory usage (and time spent unnecessarily constructing and destructing complex objects) without putting myself in a situation where any code has access to memory that it does no...

C++ "using" declaration in Visual Studio 2008

I am trying to use google protobuf and they have the following example: using google::protobuf; protobuf::RpcChannel* channel; protobuf::RpcController* controller; SearchService* service; SearchRequest request; SearchResponse response; void DoSearch() { // You provide classes MyRpcChannel and MyRpcController, which implement // th...

Numerical range iterators in boost?

I'm aware of the range iterators in boost, and as for this reference, it seems there should be an easy way of doing what I want, but it's not obvious to me. Say I want to represent a numerical range, 0 to 100 (inclusive or not), say range(0,100). I would like to do something like: for_each(range<int>(0,100).begin(), range<int>(0,100).e...

How do I iterate a collection of Excel columns in C++ using Automation?

I want to do the moral equivalent of the following VBA code: For Each col In Worksheets("Sheet1").Columns # do stuff Next col I have generated MFC wrappers for the Excel type library that get me this far (the generated types all derive from COleDispatchDriver: CApplication app; app.CreateDispatch( clsid, e ); CWorkbooks wbks( a...

Equal sign in Boost RegEx

Hello all, I've got a problem with the following Boost regular expression, boost::regex e("="); if(regex_search("=", e)) cout << "yeah"; Can anybody please tell me why I don't get a "yeah"? This is Boost 1.37 with Visual Studio 2008. Thank you very much in advance! ...

Breaking ReadFile() blocking - Named Pipe (Windows API)

To simplify, this is a situation where a NamedPipe SERVER is waiting for a NamedPipe CLIENT to write to the pipe (using WriteFile()) The Windows API that is blocking is ReadFile() The Server has created the synchronous pipe (no overlapped I/O) with blocking enabled The client has connected, and now the server is waiting for some data....

dumping c++ structures to a text file

Hi, how would one go about writing the contents of a structure in C++ to a text file? What I want to do is, say I have a structure called A, with data members A.one, A.two, and so on, and I want to write them out line by line into a text file, like so Structure A A.one = value A.two = value ... Structure B B.one = value B.two = value ...