c++

What is the best way to make a simple cross platform GUI in C++?

I want to produce a desktop application with a very simple GUI (a background graphic, a cancel button and a progress bar). My main targets are Mac and Windows. Is this possible using Visual C++ 2008? Can anyone point to any examples using Visual C++? Or is there a better way to create the GUI separately? ...

checking float inside a string and return result???

Hi there! I have a text file which i geline to a string. the file is like this: 0.2abc 0.2 .2abc .2 abc.2abc abc.2 abc0.20 .2 . 20 i wanna check the result then parse it in to separate float. The result is: 0.2 0.2abc 2 20 2abc abc0.20 abc this is expalined: check if there is 2 digit (before and after '.' (full stop)) whether with char...

How to set amcap's default color space to YUY2?

Hi, AMcap is a app for capturing video or to preview from webcam. Its source code comes with Microsoft Windows SDK as sample. I want to (bypass the following process of user interaction in amcap code or say want to) set it as default: Ampcap menu Options Video Capture Pin ... Color Space/Compression: YUY2 Out...

[C++] How can I kill all processes of a program?

Hey everybody, I wrote a program that forks some processes with fork(). I want to kill all child- and the mother process if there is an error. If I use exit(EXIT_FAILURE) only the child process is killed. I am thinking about a system("killall [program_name]") but there must be a better way... Thank you all! Lennart ...

How do i know if a thread is suspended under Windows CE

Can I get a threads suspend count under Windows CE, using C or Visual C++, without calling resume or suspend functions? The only way I can see of doing it is something like int Count = SuspendThread(ThreadHandle); ResumeThread(ThreadHandle); This has a couple of problems, firstly, I'd rather not suspend the thread, and secondly the...

I can't build a library that needs WOW64 Api

Hi, I'm fixing a bug with Windows Vista 64 bits of a 32bit application, when I try to use the function Wow64DisableWow64FsRedirection(...) the compiler says 'undeclared identifier...'. I'm including the Windows.h header file and set _WIN32_WINNT to 0x0501. Any ideas? Thanks. EDIT: We're using MS Visual Studio 2003 ...

Solve Quadratic Equation in C++

Hello all, I am trying to write a function in C++ that solves for X using the quadratic equation. This is what I have written initially, which seems to work as long as there are no complex numbers for an answer: float solution1 = (float)(-1.0 * b) + (sqrt((b * b) - (4 * a * c))); solution1 = solution1 / (2*a); cout << "Solution 1: " <...

Convert C++Builder AnsiString to std::string via boost::lexical_cast

For a school assignment I have to implement a project in C++ using Borland C++ Builder. As the VCL uses AnsiString for all GUI Components I have to convert all of my std::strings to AnsiString for the sake of displaying. std::string inp = "Hello world!"; AnsiString outp(inp.c_str()); works of course but is a bit tedious to write and ...

Memory leak (sort of) with a static std::vector

I have a static std::vector in a class. When I use Microsoft's memory leak detection tools: _CrtMemState state; _CrtMemCheckpoint( & state); _CrtMemDumpAllObjectsSince( & state ); it reports a leak after I insert stuff into the vector. This makes sense to me because new space is allocated when something is inserted into the vector. ...

Problem accessing static const variables through class member functions

I am having a problem accessing a static const variable defined in my class private member variable section. Specifically, the code written below can output the variable within the constructor, but when I try to access it through an accessor function, I get an error discussed below. If anyone knows why I would appreciate your help. #i...

How is static variable initialization implemented by the compiler?

I'm curious about the underlying implementation of static variables within a function. If I declare a static variable of a fundamental type (char, int, double, etc.), and give it an initial value, I imagine that the compiler simply sets the value of that variable at the very beginning of the program before main() is called: void SomeFu...

in c++ gdb core dump, can I see if a pointer is still allocated?

I have a core dump sitting on disk, created by an app that failed an assert and aborted. The app was compiled in debug mode on Linux/g++. I suspect that in the stack frame at the top of the stack, my this object has been delete'd (I think this is no longer a valid ptr). However it could take days or longer to reproduce this abort. Is th...

How can I find prime numbers through bit operations in C++?

How can I find prime numbers through bit operations in C++? ...

C++ Recursive File/Directory scanning using Cygwin

I'm looking to write a portable filesystem scanner, capable of listing all files on a given directory path recursively. To do this, I'm attempting to use cygwin for my compiler, making use of dirent.h and using the template: #include <dirent.h> #include <stdio.h> int main(void) { DIR *d; struct dirent *dir; d = opend...

is there any specific case where pass-by-value is preferred over pass-by-const-reference in C++?

I read that they are conceptually equal. In practice, is there any occasion that foo(T t) is preferred over foo(const T& t) ? and why? Thanks for the answers so far, please note I am not asking the difference between by-ref and by-val. Actually I was interested in the difference between by-const-ref and by-val. I used to ho...

C++ - threads and multiple queues

I need to build a system of workers (represented as threads) and (multiple) queues. Individual jobs are waiting in one of the queues and waits for a worker thread to process them. Each worker can process jobs only from some of the queues. No spin-waiting. C/C++, pthreads, standard POSIX. The problem for me is the "multiple queues" thing...

Reference to pointers and C++ polymorphism

Hi, does anyone know why this gives a compiler error ? I tried VS 2005 and Codewarrior: class Parent { protected: int m_Var; public: Parent() : m_Var(0) {} virtual ~Parent() {} void PubFunc(); }; class Child : public Parent { protected: bool m_Bool; public: Child() : m_Bool(false) {} ...

Non-blocking connect() with WinSocks

According to MSDN you have to create a non-blocking socket like this: unsigned nonblocking = 1; ioctlsocket(s, FIONBIO, and use it in the write-fdset for select() after that. To check if the connection was successful, you have to see if the socket is writeable. However, the MSDN-article does not describe how to check for errors. How ...

Combine two images with one being transparent

I have two bitmap images. One contains a picture taken with a usb camera. The other will contain a shape, like a rectagle, but it can also be a trapezoid, or lets say, a random shape with only one color in it. The rest of the image is white right now. The two images aren't of the same size but scaling algorithms aren't the most difficul...

Is there an easy way to iterator over a static list of strings in C++

It often happens that I need to iterate over a list of strings in my C++ code. In languages like Perl, this is easy: foreach my $x ("abc", "xyz", "123") {.... } In the past, this is what I've done in C++ const char* strs[] = { "abc", "xyz", "123" }; for (int i=0; i<sizeof(strs)/sizeof(const char*); i++) { const char *str = strs[i...