c++

Unfixable circular dependency

This code gives error C2504: 'IKeyEvent': base class undefined on line 3. class IKeyEvent; class EventDispatcher : private IKeyEvent { public: enum EEActions { A_FEW_ACTIONS }; private: void OnKey(EventDispatcher::EEActions action, char multiplier); } class IKeyEvent { public: virtual void OnKey(EventDispatcher...

C++ - Pointer to a class method

I have to set up a pointer to a library function (IHTMLDocument2::write) which is a method of the class IHTMLDocument2. (for the curious: i have to hook that function with Detours) I can't do this directly, because of type mismatch, neither can I use a cast (reinterpret_cast<> which is the "right one" afaik doesn't work) Here's what I ...

Move a bitmap around a window quickly in C++

I'm looking for some C++ code to let me quickly move a bitmap around a window, restoring the background as it moves. At present I capture the Window contents to a bitmap during the app initialization and in the OnPaint() I draw the this bitmap and then I draw my overlayed bitmap. I am double buffering the paint. The overlayed bitmap posi...

How to generate automatic properties (get, set) for Visual Studio 2008 C++

Having read this thread: http://stackoverflow.com/questions/3017/how-to-generate-getters-and-setters-in-visual-studio and tried (somewhat) the techniques described, I have failed miserably to graduate beyond the longhand way of writing Getters and Setters. While I recognize the conceptual advantage of encapsulation (private members o...

C++ -- Detours (Win32 API Hijacking) -- Hijack Class Methods

I had no problems hijacking function with Detours for a long time... When I tried to hijack class methods (in my case IHTMLDocument2::write from mshtml.dll) I encountered endless problems (mainly type mismatching). As I didn't find any relevant example on the net I began doubting this can be done. My question is: is it possible to hijac...

Compiler error when including C++ code in the iPhone project

Hi, I'm trying to include some C++ code into my iPhone project and I'm getting the following compiler error: "error:expected initializer before '<' token" at this code construct: template<typename T, P_UINT_32 BEG, bool OQ, bool OVR, bool DBG> P_UINT_32 EKType<T, BEG, OQ, OVR, DBG>::getSizeX() const { return n; } It looks...

Error when mixing C and C++

I would like to create Win32 application with GUI in cpp-files and main logic in c-files. Things are ok until c-function, called within c++ code with CreateThread, for example open COM port. I got IDE hanging in C++ Builder and error in CodeBlocks+GCC. ...

Constructor abort constructing

I would like to have the constructor abort object construction whenever it encounters certain error code (e.g. if the following is encountered): CudaObj::CudaObj(InsertionSim *theSim) { // Setup if(cublasInit() == CUBLAS_STATUS_NOT_INITIALIZED) { printf("CUBLAS init error.\n"); return -1; // abort here rather than ret...

Inline io wait using MASM

How to convert this to use VC++ and MASM static __inline__ void io_wait(void) { asm volatile("jmp 1f;1:jmp 1f;1:"); } I know asm changes to __asm and we remove the volatile but whats next? I am trying to create the function to place in the code below #define PIC1 0x20 #define PIC2 0xA0 #define PIC1_COMMAND PIC1 #define PIC1_DATA...

Windows Media Player Device Sync in VB.NET using WMPLIB

The MSDN documentation for WMPLIB states that syncing to device is not supported in .NET programming, only C++. Is there, however, a simple wrapper class or DLL that can be used to interface between a .NET program and the nescessary C++ code? Or is there a better way to sync files to a device using VB.NET? Are all devices suited/compat...

Atomic delete for large amounts of files

I am trying to delete 10000+ files at once, atomically e.g. either all need to be deleted at once, or all need to stay in place. Of course, the obvious answer is to move all the files into a temporary directory, and delete it recursively on success, but that doubles the amount of I/O required. Compression doesn't work, because 1) I don...

c++ compiler that creates object code for two different machines

Are there c++ compilers that I can run on a brand x system that will create machine code that will run on a brand y system? Would this be considered a cross compiler? ...

Is it possible to have a non-template class subclass a template class?

I have a template class defined like so: template <class T> class Command { public: virtual T HandleSuccess(std::string response) = 0; virtual std::string FullCommand() const = 0; // ... other methods here ... }; Will C++ allow me to create a non-template subclass of a template class? What I mean is can I do something like...

Examples of Object-Oriented Projects Help Procedural Programmers

Please help me identify some small to medium sized open source projects that embody object oriented design (preferably in C++ or Java). I would like to use these projects to demonstrate how real world problems (as opposed to contrived text book examples) can be solved with an object oriented design. I want to be able to present a plaus...

Using the mod operator C++

Hello, Without using any stls, boosts, and the like I have been trying to rotate the elements in my array. I've been trying to use the mod operator, to be efficient: void stack::rotate(int r) { r = ( r % maxSize + maxSize ) % maxSize; for ( int first_index = 0; first_index < r; ++first_index ) { int mem = items[first_index].n; i...

how to export visual studio project to qt?

Hi, I wonder how can I export a Visual Studio C++ project to qt? I am using openCV and openMP so I would like to know about setting this libraries in qt. Thank you very much. ...

Cleaner pointer arithmetic syntax for manipulation with byte offsets

In the following lines of code, I need to adjust the pointer pm by an offset in bytes in one of its fields. Is there an better/easier way to do this, than incessantly casting back and forth from char * and PartitionMap * such that the pointer arithmetic still works out? PartitionMap *pm(reinterpret_cast<PartitionMap *>(partitionMaps)); ...

Questions about C++ memory allocation and delete

I'm getting a bad error. When I call delete on an object at the top of an object hierarchy (hoping to the cause the deletion of its child objects), my progam quits and I get this: *** glibc detected *** /home/mossen/workspace/abbot/Debug/abbot: double free or corruption (out): 0xb7ec2158 *** followed by what looks like a memory dump of...

Receiving data in TCP

If i send 1000 bytes in TCP, does it guarantee that the receiver will get the entire 1000 bytes "togther"? or perhaps he will first only get 500 bytes, and later he'll receive the other bytes? EDIT: the question comes from the application's point of view. If the 1000 bytes are reassembles into a single buffer before they reach the appli...

std::regex -- is there some lib that needs to be linked?

I get a linker error with the following code: #include <regex> int main() { std::regex rgx("ello"); return 0; } test.o: In function `basic_regex': /usr/lib/gcc/i586-redhat-linux/4.4.1/../../../../include/c++/4.4.1/tr1_impl/regex:769: undefined reference to `std::basic_regex<char, std::regex_traits<char> >::_M_compile()' collec...