c++

How to stop EnumWindows running infinitely win32

The code worked all along. Somehow I manage to get Visual C++ Express not hit the break point on the final return statement and it appeared to run for ever. In the example code bellow EnumWindows enumerates infinitely. How can one make it stop after all windows has been enumerated. #include <Windows.h> BOOL CALLBACK EnumWindowsProc(HW...

filling a boost vector or matrix

Is there a single-expression way to assign a scalar to all elements of of a boost matrix or vector? I'm trying to find a more compact way of representing: boost::numeric::ublas::c_vector<float, N> v; for (size_t i=0; i<N; i++) { v[i] = myScalar; } The following do not work: boost::numeric::ublas::c_vector<float, N> v(myScal...

Segmentation fault on string assignment in C++

Take a look at this example function: RuntimeConfiguration* conf_rt_conf() { RuntimeConfiguration *conf; conf = new RuntimeConfiguration(); conf->arch_path="./archive"; conf->err_log="./err_log"; conf->fail_log="./fail_log"; conf->msg_log="./msg_log"; conf->save="html, htm, php"; conf->ignore="jpg, gif";...

Digit limitation from decimal point in C++

Hello, I'm new in C++.I have double variable double a=0.1239857 I want to limit variable a from decimal point two digits.So a will be 0.12. I know C++ have functions that return largest or smallest integer that is greater or lower than a like ceil or floor.Is there a function that implement digit limitation of floating-point variab...

Multi-threading strategies? (Modifying a scene in a multi-threaded engine through an Editor)

Hi, I'm trying to write an editor overtop a multi-threaded game engine. In theory, through the editor, the contents of the scene can be totally changed but I haven't been able to come up with a good way for the engine to cope with the changes. (ie delete an entity while the renderer was drawing it). Additionally, I'm hesitant to write c...

How do I check for an unmangled C++ symbol when building a PHP extension?

I have a PHP module written in C++, which relies on a C++ library (Boost Date_Time) being installed. Currently, in my config.m4 file I'm checking for the library as follows: LIBNAME=boost_date_time LIBSYMBOL=_ZN5boost9gregorian9bad_monthD0Ev PHP_CHECK_LIBRARY($LIBNAME,$LIBSYMBOL,, [ AC_MSG_ERROR([lib $LIBNAME not found. T...

Syntax for dereferencing a pointer in C (or C++)

I had a colleague check in code like this in C (syntax #1): (*(*(*p_member).p_member).p_member).member When I asked him why he didn't use -> (syntax #2): p_member->p_member->p_member->member he got really defensive stating that syntax #2 is more complicated than #1...I ended up changing his code because I had to modify it and cou...

ifstream Open function not working

I've been all over the ifstream questions here on SO and I'm still having trouble reading a simple text file. I'm working with Visual Studio 2008. Here's my code: // CPPFileIO.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <fstream> #include <conio.h> #include <iostream> #include <string> ...

How do I get an error message when failing to load a JVM via JNI?

I would like to retrieve an error message that explains why the jvm failed to load. From the examples provided here: http://java.sun.com/docs/books/jni/html/invoke.html I extracted this example: /* Create the Java VM */ res = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args); if (res < 0) { // retrieve verbose error here? f...

What should i know about UDP programming?

I don't mean how to connect to a socket. What should I know about UDP programming? Do I need to worry about bad data in my socket? I should assume if I send 200bytes I may get 120 and 60 bytes separately? Should I worry about another connection sending me bad data on the same port? If data doesnt arrive typically how long may I (typ...

Returning a std::string from a C++ DLL to a c# program -> Invalid Address specified to RtlFreeHeap

Hi, In a function in my C++ DLL, I'm returning a std::string to my c# application. It pretty much looks like this: std::string g_DllName = "MyDLL"; extern "C" THUNDER_API const char* __stdcall GetDLLName() { return g_DllName.c_str(); } But when my C# code calls this function, I get this message in my output window: Invalid Add...

Tracing MFC message handling

Trying to upgrade an MFC app to use the new MFC feature pack, we are loosing the messages from a context menu. The menu appears and can be clicked, but the message seems not to be handled anywhere. We overrode OnCmdMsg() in lots of places but to no avail, the context menu's command message are not caught. Is there a way, tool, or approa...

Difference between erase and remove

I am bit confused about the difference between the usage of std::remove algorithm. Specifically I am not able to understand what is being removed when I use this algorithm. I wrote a small test code like this: std::vector<int> a; a.push_back(1); a.push_back(2); std::remove(a.begin(), a.end(), 1); int s = a.size(); std::vector<int>::...

Generating data structures by parsing plain text files

I wrote a file parser for a game I'm writing to make it easy for myself to change various aspects of the game (things like the character/stage/collision data). For example, I might have a character class like this: class Character { public: int x, y; // Character's location Character* teammate; } I set up my parser to read in ...

C++ custom stream manipulator that changes next item on stream

In C++, to print a number in hexadecimal you do this: int num = 10; std::cout << std::hex << num; // => 'a' I know I can create a manipulator that just adds stuff to the stream like so: std::ostream& windows_feed(std::ostream& out) { out << "\r\n"; return out; } std::cout << "Hello" << windows_feed; // => "Hello\r\n" Howev...

Signal-slot architecture best practice

I am using libsigc++ to wire up an application, and is uncertain as to the easier way of going about it. There is a preexisting object hierarchy that manages the data layer, and the top level object exposes all functions. All good so far. To this I am adding a GUI object hierarchy, and in the application object I am hooking them toge...

Fast Cross-Platform C/C++ Hashing Library

What's a high performance hashing library that's also cross platform for C/C++. For algorithms such as MD5, SHA1, CRC32 and Adler32. I initially had the impression that Boost had these, but apparently not (yet). The most promising one I have found so far is Crypto++, any other suggestions? http://www.cryptopp.com/ This seems to be qui...

html parsing with libxml

In another thread I got convinced into using HTML parsers instead of regexps for HTML parsing. I thought of using libxml (it has some HTML parser built in), but failed to find any useful tutorial. I also found this site and it says here it should do fine even with severely broken HTML. Could you give me some examples of HTML parsing wit...

Beginner for loop problem

[EDIT]Whoops there was a mistake in the code, and now all the responses to the question seem bizzare, but basically the for loop used to be, for(i=0; i<15; i++). I also edited to make the question more clear.[/EDIT] I am trying to make a for loop, that checks a 16 element array, so it loops from 0 to 15. I then use the i variable later,...

Qt versus WPF/.NET

My company is trying to make the decision between using Qt/C++ for our GUI framework or migrating to .NET and using WPF. We have up to this point been using MFC. It seems that .NET/WPF is technically the most advanced and feature-rich platform. I do, however, have several concerns. These include: Platform support Framework longevit...