c++

SendMessage (F4) fails when sending it to window

Working with Visual Studio 6 (VC++ 6.0) I'm using an ActiveX datepicker control which I fail to show expanded by default (3006216). Alternatively I'm trying to send a keyboard message (F4) to my window to open up the control, but nothing happens when I do so... // try 1: use the standard window handle LRESULT result = ::SendMessage(m_hW...

Corrupted mysql table, cause crash in mysql.h (c++)

i've created a very simple mysql class in c+, but when happen that mysql crash , indexes of tables become corrupted, and all my c++ programs crash too because seems that are unable to recognize corrupted table and allowing me to handle the issue .. Q_RES = mysql_real_query(MY_mysql, tmp_query.c_str(), (unsigned int) tmp_query.size()); ...

Releasing memory from map. C++

std::map<int, int> * mp = new std::map<int, int>; for(int i = 0; i < 999999; i++){ mp->insert(std::pair<int, int>(i, 999999-i )); } p("created"); //mp->clear(); - doesn't help either delete mp; p("freed"); The problem is: "delete mp" doesn't do anything. To compare: std::vector<int> * vc = new std::vector<int>; for(int i = ...

Equivalent of c# 'as' command in c++?

In c# you can use as to convert a type or get null: Object o = Whatever(); String s = o as String; Is there a similar easy way to achieve this in c++? I'm using Visual Studio 2010, if thats important. [update] Remember, there is a very important difference between casting and using as. Casting (at least in c#) will throw an exception...

How do I dynamically allocate memory for arrays in Qt C++ ?

I'm having some issues in allocating memory for an array dynamically in C++ within Qt SDK ... Here's for I'm doing: int dx = 5; QPoint * qPoint; qPoint = new QPoint[dx+1]; However when I try to debug the code, the programs just crashes when it tries to execute the third line .... any clues ? ...

static initialization confusion

I am getting very confused in some concepts in c++. For ex: I have following two files //file1.cpp class test { static int s; public: test(){s++;} }; static test t; int test::s=5; //file2.cpp #include<iostream> using namespace std; class test { static int s; public: test(){s++;} static int get() { ...

GCC: Compile to assembly with clarified correspondence to code?

When you break into the debugger in VS and open the disassembly window, each assembly fragment is displayed below it's corresponding code section (more or less). GCC with -S outputs only the stripped down assembly. Is there an option in GCC to show some correspondence to the original code? Source code is C++. ...

Blob ID matching over multiple frames in C++ (image analysis)

Dear reader, I'm working on a blob matching and tracking library in C++. Currently I'm using openCV to detect blobs and try to match blobs in a new frame by checking the position, velocity and size of the blob. This works quite okay and I'm receiving a high blob match rate (95% or higher). Sometimes blobs fall out of the image or new b...

How to not #include <windows.h>

Using MSVC2008, 32bit on 64bit system. I was once advised to never include windows.h as 'its a real monster and will slow down my compile times significantly'. I tried leaving it out and obviously get compile errors. I included windef.h to define all the DWORDs etc, but I quickly come unstuck knowing what else to define to get the code...

Editline with non-blocking input.

I use editline library in my program, for user commands input in shell. But becides shell, program have a gui interface, so I need to run editline's readline() function in separate thread, because it blocks until Enter pressed. Is there a way to use readline() function without blocking, so I could avoid separate thread usage? ...

Is it possible to connect slots of a model object to the GUI in QT4 -Designer?

So I try to build a Model-View window using QTDesigner and C++. For that reason I created a QOBject derived class as my model. It provides slots and signals to access it like: setFileName(QString) or fileNameChanged(QString). I got a little into using signal drag and drop in QTDesigner and found it quite VA-Smalltalk-Like nice. After a...

How to encapsulate a WinAPI application into a C++ class

There is a simple WinAPI application. All it does currently is this: register a window class register a tray icon with a menu create a value in the registry in order to autostart and finally, it checks if it's unique using a mutex As I'm used to writing code mainly in C++, and no MFC is allowed, I'm forced to encapsulate this into C+...

Prefer extension methods for encapsulation and reusability?

edit4: wikified, since this seems to have morphed more into a discussion than a specific question. In C++ programming, it's generally considered good practice to "prefer non-member non-friend functions" instead of instance methods. This has been recommended by Scott Meyers in this classic Dr. Dobbs article, and repeated by Herb Sutter a...

Reducing template bloat with inheritance

Does anyone have experience reducing template code bloat using inheritance? i hesitate rewriting our containers this way: class vectorBase { public: int size(); void clear(); int m_size; void *m_rawData; //.... }; template< typename T > class vector : public vectorBase { void push_back( const T& ); //......

VERY strange stack overflow in C++ program

Hello, I wrote a program some time ago (Mac OS X, C++, SDL, FMOD) and it perfomed rather good. But lately I wanted to extend its functionality and added some more code to it. And now, when I run it and try to test the new functionality, the program crashes with SIGABRT. Looking into debugger, on function stack I see: _kill kill$UNIX2...

C++ delete syntax

Hi, I came across this rather unusual usage of 'delete'. Just wanted to know if the following line deletes both pointers or only the first? delete ptr1, ptr2 ...

Mapping integers to types using C++ template fails in a specific case

I am attempting to compile the following template based code in VC++ 2005. #include <iostream> using namespace std; /* * T is a template which maps an integer to a specific type. * The mapping happens through partial template specialization. * In the following T<1> is mapped to char, T<2> is mapped to long * and T<3> is mapped...

sprintf an LPCWSTR variable

Hello everyone. I'm trying to debug print an LPCWSTR string, but I get a problem during the sprintf push in the buffer, because it retrieve only the first character from the string. Here is the code: HANDLE WINAPI hookedCreateFileW(LPCWSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, ...

how can i store xml in buffer using xmlite?

I'm trying to write xml data with XmlLite on buffer but couldn't got any api. writing a xml file works perfect but on a memory stream I can't figure i am working on follwong link api http://msdn.microsoft.com/en-us/library/ms752901(v=VS.85).aspx ...

Handling 16 bpp tiff file in C++

I need to open 16 bpp grayscale tiff image in C++ program. Trying to do this with GDI+ Image class, I get OutOfMemoryException (GDI+ doesn't support 16 bpp format). Standard Windows tools, like Paint and Picture Viewer, cannot open such image, possibly they use GDI or GDI+. ImageJ program opens such image successfully. Is there some SDK ...