c++

Need help designing an inter-process comm layer

Hello everyone, I have several process in my system that need to communicate with each other. Some of the processes need to pass chunks of data 60 times per second continuously, and some are very sporadic. Most of the processes are in C#, one is C++. All running on the same windows 7 machine. Right now each process has it's own diff...

Having trouble understanding this error creating a thread...

HANDLE hThread; DWORD dwThreadId; hThread = CreateThread( NULL, // default security attributes 0, // use default stack size MyThreadFunction, // thread function name 0, // argument to thread function 0, ...

question with longjmp

I want to use longjmp to simulate goto instruction.I have an array DS containing elements of struct types (int , float, bool ,char). I want to jump to the place labled "lablex" where x is DS[TOP].int_val. how can I handle this? sample code : ... jmp_buf *bfj; ... stringstream s;s<<"label"<<DS[TOP].int_val; bfj = (jmp_buf *) s.str(); lo...

QT C++ Passing Widgets to function

Hi I am trying to write a simple function where I load a text file to a QComboBox, I am very new to QT and C++. Here is what i have right now: void frmVerification::openTextFile(QComboBox* qCombo, string filename) { using namespace std; string line; ifstream myfile(filename.c_str()); if (myfile.is_open()) { whi...

Iterating std::string elements

does it take constant time to move the iterator to elements of string in following: std::string str // string of size 100 MB std::string::iterator iter = str.begin(); std::advance(iter, str.size()-1); would it take constant time as in searching by index? char c = str[str.size()-1]; ...

Easiest way to pass modifyable System.String as modifyable LPTSTR ?

BOOL PathFindOnPath( LPTSTR pszFile, LPCTSTR *ppszOtherDirs ); I am calling this API from managed C++. My pszFile is in a System.String. What is the easiest way to pass this as LPTSTR? (Considering its an inout parameter) I have tried pin_ptr and interior_ptr but neither seems to be accepted by the compiler. ...

How do the variable length fields in the windows EVENTLOGRECORD structure work?

I've tried, with little success, to identify how the variable length portion of the EVENTLOGRECORD data works. Winnt.h defines the structure, and the following data, as follows: typedef struct _EVENTLOGRECORD { DWORD Length; // Length of full record DWORD Reserved; // Used by the service DWORD RecordNumber; // Absol...

preventing memory leak (case-specific)

Consider the following situation: SomeType *sptr = someFunction(); // do sth with sptr I am unaware of the internals of someFunction(). Its pretty obvious that the pointer to the object which someFunction() is returning must be either malloc'ed or be a static variable. Now, I do something with sptr, and quit. clearly the object be st...

How to know the bytes amount used by a pointer?

Hi, I have a pointer (uint8_t *myPointer), that I pass as paramether to a method, and then this method set the value to this pointer, but I want to know how much bytes are used (pointed ?) by the myPointer variable. Thanks in advance and excuse me by my english. ...

OpenCV findContours function problem

Hi, I am trying to use the findContours function in OpenCV, but VS 2008 gives an error saying: OpenCV Error: Bad flag (parameter or structure field) (Unrecognized or unsupport ed array type) in unknown function, file ........\ocv\opencv\src\cxcore\cxarr ay.cpp, line 2476 This application has requested the Runtime to terminate it in a...

Passing row of static 2-d array to function in C++

This is a really elementary question. Nonetheless, I haven't found a solution after studying dozens of semi-relevant examples online. I have a two-dimensional array of doubles whose size is known at compile time: double demPMFs[ NUM_DEM_PARAMS ][ NUM_AGE_CATEGORIES ]. Array entries are populated by input files early in the program. I'd ...

What's the point of using boost::mem_fn if we have boost::bind ?

I'm having a look at the Boost libraries that were included in C++'s Technical Report 1 and trying to understand what each does. I've just finished running an example for boost::mem_fn and now I'm wondering what's the point of using it instead of the better boost::bind. As far as I understand, both of them return a function object poin...

C++ auto_ptr and copy construction

If I have a class template <typename T> struct C { ... private: auto_ptr<T> ptr; }; How do I define the copy constructor for C: It cannot be template <typename T> C<T>::C(const C& other) because I want to if I copy the auto_ptr from other, I have changed other by removing ownership. Is it legal to define a copy constructor ...

How to handle state transitions and yet replace "if" statements with polymorphic types?

Recently I was listening to a tech talk on clean coding. The speaker was a test engineer, who emphasized on avoiding the "if" statements in the code and use polymorphism as much as possible. Also he advocated against global states. I quite agree with him, yet i need a clarification on replacing the global state and "if" statement using ...

How to achieve better efficiency re-inserting into sets in C++

I need to modify an object that has already been inserted into a set. This isn't trivial because the iterator in the pair returned from an insertion of a single object is a const iterator and does not allow modifications. So, my plan was that if an insert failed I could copy that object into a temporary variable, erase it from the set, m...

Duplicate symbol error associated with const char * [] declaration

I'd love help diagnosing the source of a duplicate symbol error that I'm receiving when I try to compile with g++ 4.2.1. The specific error is ld: duplicate symbol _SOCIODEM_FILENAMES in /var/folders/c+/c+eq1Qz1Feye7vxs5mQOUE+++TI/-Tmp-//ccP3yVgF.o and /var/folders/c+/c+eq1Qz1Feye7vxs5mQOUE+++TI/-Tmp-//cc1NqtRL.o collect2: ld return...

C++ gsoap mime/dime for binary files in windows

Hello, I'm pretty close to losing my head here ;) I'm developing a service that uses gsoap. I would like to return a mime response. I have everything working, but when reading binary files, all kind of files like jpeg, pdf, etc... contains the \0 char several times over the data (if opened with notepad can see a lot of NUL). So any c...

How do I set the windows system clock to the right local time using C++?

Right now I do something like this: SYSTEMTIME st; st.wHour = 6; st.wMinute = 23; BOOL result = SetSystemTime(&st); The goal is to get it to show that exact time on my local machine. When I run the program it changes it to 8:23 instead of 6:23. How can I get it to show the correct local time? ...

Can C++ assignment operators be free functions?

I'm trying something like this: Foo & operator=(Foo & to, const Bar &from); But I'm getting this error: E2239 'operator =(Foo &, const Bar &)' must be a member function Are there limitations on which operators can/cannot be defined as Free Functions, and if so, why? ...

How do I set the date to the next weekday of my choice using c++?

I would like to determine the next date that has a day of the week value equal to something I specify. For example, today is 6/21/2010 and the day of week value is 1 b/c today is a Monday. How do I find the next date with let's say a day of week value of 3. I would like to consider all cases that come close to the end of something incl...