c++

Accessing a subset (not subtree) of an object hierarchy

I have a base class "Node" which contains a list of child nodes. Node defines a "forEachNode" function which takes a callback as a parameter and calls it on each node in the hierarchy. I have a class derived from Node - "SpecialNode" (not really a name I'd choose - just an example!). Node knows nothing about SpecialNode. I want to ite...

Why was constness removed from Java and C#?

I know this has been discussed many times, but I am not sure I really understand why Java and C# designers chose to omit this feature from these languages. I am not interested in how I can make workarounds (using interfaces, cloning, or any other alternative), but rather in the rationale behind the decision. From a language design persp...

Best way to get a query result

I'm developing an application that gets large images from an Internet server which is the best way to download this images, without freeze the entire application? I mean background download. I have thought about download it in another thread. ...

Split a varbinary in a SELECT

Hi, I have a large varbinary field in one of my tables, and I would like to download in parts for show a download progress indicator in my application. How can I split the data sent in a SELECT query? Thanks ...

Looking for benchmarking code snippet (c++)

Some loading routines in my program takes to long to complete. I want a quick small snippet for checking how long a function took to execute. By small I mean "preferably without 3rd party libraries". Maybe something as simple as taking the system time? start = current_system_time() load_something() delta = current_system_time()-start l...

Strange behavior with OpenCV

Hi every one, When I compile my Windows application (called CrosslinesDetection) in Visual C++ 2005 including OpenCV 1.1, a computer vision library, I do not get any compile or link errors, but when I am running it, it gets to a point and freezes, and Windows says the following: "Unhandled exception at 0x7c915223 in CrosslinesDetection...

What is the effect of overriding a (regular) virtual method by a pure virtual method?

Let's say we have class A { public: virtual int foo() { cout << "foo!"; } } class B : public A { public: virtual int foo() =0; } class C : public B { public: virtual int foo() { cout << "moo!"; } } Is this really overriding? I think this is actually overloading. What is the meaning of making something lik...

How to prevent crashing if com dll isnt registered

Hi From some old c++ code im trying to use a com dll, it works fine when the dll is registered, but it crahses if the dll isnt registered. // Initialize COM. HRESULT hr = CoInitialize(NULL); IGetTestPtr ptest(__uuidof(tester)); "Use method from the dll" // Uninitialize COM. CoUninitialize(); Is it anyway to check if the dll has bee...

C++: is string.empty() always equivalent to string == ""?

Can I make an assumption that given std::string str; ... // do something to str Is the following statement is always true? (str.empty() == (str == "")) ...

Reader / Writer Lock with timeout using conditional variable

How to write a Reader/Writer lock with timeout, using conditional variables in C/C++? ...

How can i convert hex numbers to binary in c++?

I am taking a beginning c++ class, and would like to convert letters between hex representations and binary. I can manage to print out the hex numbers using: for(char c = 'a'; c <= 'z'; c++){ cout << hex << (int)c; } But I can't do the same for binary. There is no std::bin that I can use to convert the decimal numbers to binary. H...

XA distributed transactions in C++

Hi everybody. Is there a good C++ framework to implement XA distributed transactions? With the term "good" I mean usable, simple (doesn't imply "easy"), well-structured. Due to study reasons, at the moment I'm proceeding with a personal implementation, following X/Open XA specification. Thank you in advance. ...

Dynamic Shared Library compilation with g++

I'm trying to compile the following simple DL library example code from Program-Library-HOWTO with g++. This is just an example so I can learn how to use and write shared libraries. The real code for the library I'm developing will be written in C++. #include <stdlib.h> #include <stdio.h> #include <dlfcn.h> int main(int argc, char **...

CTreeCtrl - getting an item position

Is there a way of getting the position (index) of an item in a CTreeCtrl? I am interested in the index of a node at its particular level. I was thinking to maintain the item positions within the item "data" field, but the problem is that my tree is sorted and I cannot predict the position an item will receive (well, only if I sort the...

Why is my ReadDirectoryChangesW not picking up changed files?

I'm sure I am just doing something really dumb and not seeing it but can anyone tell me why the following code would not be picking up changes in the passed in directory? When calling this code, creating and modifying files or directories in the passed in m_directory is ignored. But if I call PostQueuedCompletionStatus( m_hCompleti...

How can you make an MFC application with an HTML view consistently accept drag-dropped files?

I'm trying to decipher CHtmlView's behaviour when files are dragged into the client area, so I've created a new MFC app and commented out the CHtmlView line that navigates to MSDN on startup. In my main frame, I've overridden CWnd::OnDropFiles() with a function that shows a message box, to see when WM_DROPFILES is sent. OnDropFiles() g...

Do we need a Java++?

It seems to me that, in some ways, Java is where C was a while back. Both are fairly minimalist languages for their time, with relatively clean, simple cores to build on. (I'm referring to the core language here, not the libraries.) Both are/were extremely popular. Both are/were lingua francas, with tons of legacy code. Both are/wer...

replace line breaks in a STL string

how can i replace "\r\n" in an std::string ...

how define friend function and operator overloading in c++

i want to know about the friend function and operator overloading in c++ and how they work? with program? ...

Best way to create a timer on screen

Hey! I had this idea of creating a count down timer, like 01:02, on the screen (fullsize). One thing is that I really don't have a clue on how to start. I do know basic c/c++, win32 api and a bit of gdi. Anyone have any pointers on how to start this? My program would be like making the computer into a big stopwatch (but with added fe...