c++

Better way for pass by reference from C# to C++?

Hello all, I have a 3rd party collection of .h files along with the .lib files that go with them. I am wrapping those native C++ files with a C++/CLI wrapper and making final calls from C#. I have an issue when I call methods that expect a reference to be passed in where the value is not getting changed in my wrapper unless I explicitl...

Library plans for C++0x?

Lately I've been getting very excited about the support for lambdas in VC2010. I'm slowly starting to grasp the full potential this feature has in transforming C++ into something alot better. But then I realized that this potential greatly depends on main stream support of lambdas in day to day libraries like boost and QT. Does anyone k...

How to implement a queued map?

The problem: I want to be able to FIFO queue outgoing messages. For update/deletion reasons, I also want to be able to access every message in the queue based upon an object ID. I've currently implemented a solution where data is pushed into a deque, and an iterator to that data is kept. The iterator, keyed by an object ID, is then plac...

PInvoke error when marshalling struct with a string in it

I have a C++ struct struct UnmanagedStruct { char* s; // Other members }; and a C# struct struct ManagedStruct { [MarshalAs(UnmanagedType.LPStr)] string s; // Other members } the C++ library exposes extern "C" UnmanagedStruct __declspec(dllexport) foo( char* input ); And it is imported like [DllImport("SomeDLL.dl...

Container with two indexes (or a compound index)

I have a class like this class MyClass { int Identifier; int Context; int Data; } and I plan to store it in a STL container like vector<MyClass> myVector; but I will need to access it either by the extenal Index (using myVector[index]); and the combination of Identifier and Context which in this case I would perform a...

C++ Map cant insert with pair

Why I cant insert like here? #include <map> struct something { } some_object; typedef std::map<std::string, something*> list; typedef std::pair<std::string, something*> pair; int main() { list l; pair p("abc", &some_object); // working fine!!! l.insert(p); // 17 errors return 0; } visual studio give me many errors...

Template Metaprogramming - i still don't get it :(

Hi folks ... i have a problem .. i don't understand Template Metaprogramming. The Problem is : i read a lot . But it does not make much sense to me :/ Fact nr.1 : Template Metaprogramming is faster template <int N> struct Factorial { enum { value = N * Factorial<N - 1>::value }; }; template <> struct Factorial<0> { enum...

Determine static initialization order after compilation?

In C++, I know that the compiler can choose to initialize static objects in any order that it chooses (subject to a few constraints), and that in general you cannot choose or determine the static initialization order. However, once a program has been compiled, the compiler has to have made a decision about what order to initialize these...

C/C++ Packing and Compression

Hey guys, I'm working on a commercial project that requires a couple of files to be bundled (packed) into an archive and then compressed. Right now we have zlib in our utility library, but it doesn't look like zlib has the functionality to compress multiple files into one archive. Anyone know of free libraries I'd be able to use for thi...

MFC Fail to Load Dlg from DLL

I have installed in my PC VS2008 and Windows Mobile 6 SDK. I have made a SmartDevice MFC application and a Regular DLL MFC, both uses shared MFC DLL. But when I called DoModal() of the DLL the application hangs, show a "Debug Assertion Failed" message and freeze my device. Can you help me? Codes: The EXE code: typedef BOOL (CALLBA...

Initializing member variables

I've started to pick up this pattern: template<typename T> struct DefaultInitialize { DefaultInitialize():m_value(T()){} // ... conversions, assignments, etc .... }; So that when I have classes with primitive members, I can set them to be initialized to 0 on construction: struct Class { ... DefaultInitialize<double> m_doubl...

can not draw on GDI+ bitmap object.

I am writing program in c++ gdi gdi+. Drawing large image on gdi+ bitmap is slow is using gdi+ api. So I used the following way to draw: Bitmap img(xxx); Graphics gr(&img); HDC dc = gr.GetHDC(); ::StretchDIBits( dc, rec.left, rec.top, (rec.right - rec.left), (rec.bottom - rec.top), m_recRegin.left , m_recRegin.top, ...

Boost's Linear Algebra Solution for y=Ax

Does boost have one? Where A, y and x is a matrix (sparse and can be very large) and vectors respectively. Either y or x can be unknown. I can't seem to find it here: http://www.boost.org/doc/libs/1_39_0/libs/numeric/ublas/doc/index.htm ...

Most Compact Way to Count Number of Lines in a File in C++

What's the most compact way to compute the number of lines of a file? I need this information to create/initialize a matrix data structure. Later I have to go through the file again and store the information inside a matrix. Update: Based on Dave Gamble's. But why this doesn't compile? Note that the file could be very large. So I try t...

C++ STL map typedef errors

I'm having a really nasty problem with some code that I've written. I found someone else that had the same problem on stackoverflow and I tried the solutions but none worked for me. I typedef several common STL types that I'm using and none of the others have any problem except when I try to typedef a map. I get a "some_file.h:83: erro...

Performance impact of -fno-strict-aliasing

Is there any study or set of benchmarks showing the performance degradation due to specifying -fno-strict-aliasing in GCC (or equivalent in other compilers)? ...

Is setting parent for a window from different process correct?

I have two applications having two different top level windows: App1 -- Window1 App2 -- Window2 Now, I am creating a Dialog Dlg1 in App1 and I want to set window2(App2) as a parent window. ( That is because I want my Dlg1 to come on top of Window2 ). I created the dialog by setting Window2 as parent. It worked. But is it the correct ...

FireFox Com Function

For IE microsoft provides COM to access it programatically. Is there any function to access Firefox from our Program ...

What is the correct way to handle timezones in datetimes input from a string in Qt

I'm using Qt to parse an XML file which contains timestamps in UTC. Within the program, of course, I'd like them to change to local time. In the XML file, the timestamps look like this: "2009-07-30T00:32:00Z". Unfortunately, when using the QDateTime::fromString() method, these timestamps are interpreted as being in the local timezone. T...

svn rename problem

Hi, Our code is C++ and is managed in svn. The development is with Visual Studio. As you know Visual Studio C++ is case insensitive to file names and our code unfortunately "exploited" this heavily. No we are porting our application to Linux + gcc, which is case sensitive. This will involve a lot of file names and file changes. We plan...