c++

Qt and no moc_*.cpp file

I'm developing a simple qt4 app and making my own dialog. I subclassed QDialog, inserted Q_OBJECT macro in class declaration block and.. I get [Linker error] undefined reference to `vtable for MyDialog' and there is no moc_MyDialog.cpp generated by moc compiler. I Use Qt 4.1.3 on windows XP and mingw - i do the build proces from QT su...

Getting rid of the evil delay caused by ShellExecute

This is something that's been bothering me a while and there just has to be a solution to this. Every time I call ShellExecute to open an external file (be it a document, executable or a URL) this causes a very long lockup in my program before ShellExecute spawns the new process and returns. Does anyone know how to solve or work around t...

Lock / Prevent edit of source files on Linux using C++

How can I programmatically lock/unlock, or otherwise prevent/enable editing, a source file on Linux using C++. I want to be able to lock source file so that if I open it in an editor it will not allow me to save back to the same source file. I am thinking of maybe changing the permissions to read-only (and change it back to read-write ...

How to convert a number to a bytearray in bit endian order

I am trying to uncompress some data created in VB6 using the zlib API. I have read this is possible with the qUncompress function: http://doc.trolltech.com/4.4/qbytearray.html#qUncompress I have read the data in from QDataStream via readRawBytes into a char array, which I then converted to a QByteArray for decompression. I have the com...

bad_alloc error when using std::string

Hi all.. I'm currently working on a project that depends on me providing a path to a file (eg. "C:\Path.pth"). Now, I had everything working yesterday by calling my std::string with: std::string path("C:\\Path.pth"); -- But now it doesn't work!? It throws a bad_alloc. Seems like the '\' character is the problem. I even tried using \x5...

Looking for something similar to offsetof() for non-POD types

Hi, I'm looking for a way to obtain offsets of data members of a C++ class which is of non-POD nature. Here's why: I'd like to store data in HDF5 format, which seems most suited for my kind of material (numerical simulation output), but it is perhaps a rather C-oriented library. I want to use it through the C++ interface, which would ...

Reading the Exchange server time via MAPI

I'd like to calculate the age of the messages in an Exchange mailbox to make sure they sit there for at least a minute before our program (C++, MAPI) processes them. This way the spam filter we use should have enough time to do its job. Because the time on the PC where our program runs might be different from the time used by the Exchan...

What is the most hard to understand piece of C++ code you know?

Today at work we came across the following code (some of you might recognize it): #define GET_VAL( val, type ) \ { \ ASSERT( ( pIP + sizeof(type) ) <= pMethodEnd ); \ val = ( *((type *&)(pIP))++ ); \ } Basically we have a byte array and a pointe...

Sizing an MFC Window

Hi all, I have an MFC app which I have been working on for a few weeks now, I want to manually set the dimensions of the main frame when it is loaded, can someone give me a hand with this, specifically where to put the code as well? Thanks! ...

Getting selected members from multiselect list view ctrl

Hi all, I have a list view control which at the moment only allows one item to be selected. I then read this via the following code: void CApp::OnNMClickList1(NMHDR *pNMHDR, LRESULT *pResult) { int nSelected = (m_List.GetSelectionMark()); ... However, now I want to make this list able to multiselect, GetSelectionMark() always ret...

Dereferencing Variable Size Arrays in Structs

Structs seem like a useful way to parse a binary blob of data (ie a file or network packet). This is fine and dandy until you have variable size arrays in the blob. For instance: struct nodeheader{ int flags; int data_size; char data[]; }; This allows me to find the last data character: nodeheader b; cout <<...

Iterators.. why use them?

In the STL library some containers have iterators and it is commonly held that they are a superior way of iterating through these containers rather than simple for loops e.g. for ( int i=0; i < vecVector.size(); i++ ) { .. } Can anyone tell me why and in what cases I should use iterators and in what cases the code snippet above plea...

Why shouldn't you use references to smart pointers?

I recall reading somewhere that using references to smart pointers can cause memory corruption. Is this simply because of using the reference of the smart pointer after its been destroyed? Or does the reference counting get messed up? Thanks for clarifying ...

C++ #include semantics

This is a multiple question for the same pre-processing instruction. 1 - <> or "" ? Appart from the info found in the MSDN: http://msdn.microsoft.com/en-us/library/36k2cdd4(VS.80).aspx 1.a: What are the differences between the two notations? 1.b: Do all compilers implement them the same way? 1.c: When would you use the <>, and when w...

Isn't saying "C/C++" wrong?

I've seen a lot of questions around that use improperly the expression "C/C++". The reasons in my opinion are: Newbie C and C++ programmers probably don't understand the difference between the two languages. People don't really care about it since they want a generic, quick and "dirty" answer While C/C++ could sometimes be interpret...

Optimize Frustum Culling

i am writing a game in C++ and have a level consisting of many seperate meshes, each with their own vertex buffer. i am using vmmlib ( brilliant free gl compat. vector/matrix library ) to create my frustum culler and testing it against the bounding sphere of every mesh in the level. sadly my level can consist of up to 800 meshes and iter...

How do I get the integer value of a char in C++?

I want to take the value stored in a 32 bit unsigned int, put it into four chars and then store the integer value of each of these chars in a string. I think the first part goes like this: char a = orig << 8; char b = orig << 8; char c = orig << 8; char d = orig << 8; ...

Is C++ CLI a superset of C++?

Would a C++ CLI compiler be able to compile some large sets of C++ classes without modifications? Is C++ CLI a superset of C++? ...

What is the best way of implementing assertion checking in C++?

By that I mean, what do I need to do to have useful assertions in my code? MFC is quite easy, i just use ASSERT(something). What's the non-MFC way? Edit: Is it possible to stop assert breaking in assert.c rather than than my file which called assert()? Edit: What's the difference between <assert.h> & <cassert>? Accepted Answer: Load...

What are some good resources on 2D game engine design?

Hi all, I'm messing around with 2D game development using C++ and DirectX in my spare time. I'm finding that the enterprisey problem domain modeling approach doesn't help as much as I'd like ;) I'm more or less looking for a "best practices" equivalent to basic game engine design. How entities should interact with each other, how anima...