c++

How to use doublebuffer in listview in windowsmobile

Hi.. does any one please tell me how to use double-buffer in windows-mobile listview Thanks Grabi8 ...

Debugging a 2D array in VS2008

I have a 2D array which contains height information. I want to see it in the debugger to a certain point if the values are correct. I know we can see a 1D array using "myArray,5", but it doesn't work when i write "myArray,5,5" or "myArray[0],5", without the quotation marks. Does anybody know how to do this? Or is this even possible? ...

Access Violation Exception/Crash from C++ callback to C# function.

So I have a native 3rd party C++ code base I am working with (.lib and .hpp files) that I used to build a wrapper in C++/CLI for eventual use in C#. I've run into a particular problem when switching from Debug to Release mode, in that I get an Access Violation Exception when a callback's code returns. The code from the original hpp...

Giving an instance of a class a pointer to a struct

I am trying to get SSE functionality in my vector class (I've rewritten it three times so far. :\) and I'm doing the following: #ifndef _POINT_FINAL_H_ #define _POINT_FINAL_H_ #include "math.h" namespace Vector3D { #define SSE_VERSION 3 #if SSE_VERSION >= 2 #include <emmintrin.h> // SSE2 #if SSE_VERSION >= 3 #inc...

thread-safe function pointers in C++

I'm writing a network library that a user can pass a function pointer to for execution on certain network events. In order to keep the listening loop from holding up the developer's application, I pass the event handler to a thread. Unfortunately, this creates a bit of a headache for handling things in a thread-safe manner. For instance,...

Using boost::shared_ptr within inheritance hierarchy

Imagine the following situation: class IAlarm : public boost::enable_shared_from_this<IAlarm> { boost::shared_ptr<IAlarm> getThisPointerForIAlarm() { return shared_from_this(); } void verifyThis(int); // called by Device }; class Alarm : public IAlarm { Alarm( boost::shared_ptr< Device > attachedDevice){ att...

Mystery pthread problem with fork()

I have a program which: has a main thread (1) which starts a server thread (2) and another (4). the server thread (2) does an accept(), then creates a new thread (3) to handle the connection. At some point, thread (4) does a fork/exec to run another program which should connect to the socket that thread (2) is listening to. Occasion...

How can I debug a program when debugger fails.

I am debugging an Iphone program with the simulator in xCode and I have one last issue to resolve but I need help resolving it for the following reason: when it happens the program goes into debugging mode but no errors appear (no BAD ACCESS appears) and it does not show where the code fails. Putting some variables as global helps me to...

Is MySQL C++ Connector access to remote database possible?

I am accessing a MySQL database within a C++ app using MySQL C++ Connector. It works fine if I have the C++ and the MySQL on the same machine. So, something like the following code works fine: sql::Connection *_con; sql::mysql::MySQL_Driver *_driver; _driver = sql::mysql::get_mysql_driver_instance(); _con = _driver->con...

c++ debugging in vis studio 2008, how to break when a variable becomes zero

I can detect when a variable changes, but it changes so often that its no use - what I want is to detect the moment that a variable becomes zero. Thanks, ...

Determining size of an overloaded C++ class

Using the sizeof operator, I can determine the size of any type – but how can I dynamically determine the size of a polymorphic class at runtime? For example, I have a pointer to an Animal, and I want to get the size of the actual object it points to, which will be different if it is a Cat or a Dog. Is there a simple way to do this, sh...

Safely moving a C++ object

I’ve heard some words of warning against shipping an object to another memory location via memcpy, but I don’t know the specific reasons. Unless its contained members do tricky things that depend on memory location, this should be perfectly safe … or not? EDIT: The contemplated use case is a data structure like a vector, which stores o...

What would be the purpose of using the reference and dereference operators immediately in sequence "&*B" ?

I have seen this in our code a couple times and it immediately makes me suspicious. But since I don't know the original intent I am hesitant to remove it. //requires double indirection which I won't go into FooClass::FooFunction(void ** param) { //do something } SomeClass * A = new SomeClass(); SomeClass **B = &A; FooFunction( reint...

Polymorphism & Pointers to arrays

Hi all, I have a class A: class A { public: virtual double getValue() = 0; } And a class B: class B : public A { public: virtual double getValue() { return 0.0; } } And then in main() I do: A * var; var = new B[100]; std::cout << var[0].getValue(); //This works fine std::cout << var[1].getValue(); //This, ...

Best way to create large hashmap at compile time (C++)?

In my application, I need a hash map mapping strings to a large number of static objects. The mappings remain fixed for the duration of the application. Is there an easy way to pre-generate the mappings at compile time rather than building it element-by-element when the application starts? ...

Distributing with Boost Library?

Hey guys, i'm quite new to using boost and I can't seem to find documentation anywhere on how to distribute your application when using boost? Many of the libraries are shared libraries, i'm not expecting my users to have boost installed, i'm only using a single library (regex) so is there an easy way to package the regex library with m...

Are do-while-false loops common?

A while back I switched the way I handled c style errors. I found a lot of my code looked like this: int errorCode = 0; errorCode = doSomething(); if (errorCode == 0) { errorCode = doSomethingElse(); } ... if (errorCode == 0) { errorCode = doSomethingElseNew(); } But recently I've been writing it like this: int errorCode = ...

Multithreaded Engine Windowed random slowdown

We have a task based multithreaded engine set up where a scheduler passes the task to the threads lock-free queue. The engine is in C++ with DirectX for the rendering and we are using boost::thread for creating the threads. When in windowed mode, it randomly slows down for a second or so and then speeds back up. It seems that it's someth...

Win32 C/C++ checking if two instances of the same program use the same arguments

Hello all, I have an application and I want to be able to check if (for instance) two instances of it used the same arguments on execution. To make it clearer: myapp 1 2 myapp 1 3 This isn't a Singleton design pattern problem as I can have more than one instance running. I though about checking the running processes, but it s...

Is it possible to return a derived class from a base class method in C++?

I would like to do this: class Derived; class Base { virtual Derived f() = 0; }; class Derived : public Base { }; Of course this doesn't work since I can't return an incomplete type. But neither can I define Derived before base, since I can't inherit from an incomplete type either. I figure that I could use templates as a workar...