c++

Invoke PostgreSQL Stored Procedure using C

I am referring to http://www.postgresql.org/docs/8.1/static/libpq.html I try to find an example of C/C++ to call PostgreSQL stored procedure. However, I cannot find one. Can anyone point me the right direction? ...

AES encryption problem in Debug and Release mode

Hello There, I am using AES encryption algorithm (Rijndael implementation). I am using MS Visual Studio 2008 IDE for my development work. I could see a strange problem in my Debug and Release mode. When I encrypt a string in Debug mode it generates different bytes than Release mode. But fortunately decrypting will result same string. I ...

Benefits of a swap function?

Browsing through some C++ questions I have often seen comments that a STL-friendly class should implement a swap function (usually as a friend.) Can someone explain what benefits this brings, how the STL fits into this and why this function should be implemented as a friend? ...

Which one to use - memset() or value initialization to zero out a struct?

In Win32 API programming it's typical to use C structs with multiple fields. Usually only a couple of them have meaningful values and all others have to be zeroed out. This can be achieved in either of the two ways: STRUCT theStruct; memset( &theStruct, 0, sizeof( STRUCT ) ); or STRUCT theStruct = {}; The second variant looks clean...

mfc autosuggest textbox (like in Windows Start->Run dialog)

In Windows XP if you click Start, Run (or Windows-key + R) you get a little dialog for running things directly. If you start typing, a resizable scroll-list pops up underneath the edit-box. I want something similar, so when a user is typing in a name to an edit-box, a list will suddenly appear if suggestions can be made. But I don't kn...

c++ identify current thread in function?

Hi! let's say i have a singleton object with a static function: static int MySingletonObject::getInt() now i would like to return a different int depending on which workingthread (MFC threading) is calling the function. I know that i can pass parameters to the threadingfunction when creating the thread. But Is there a way to identif...

Is it possible to have identically named source files in one visual studio c++ project?

I'm working on a static library project for a c++ course I'm taking. The teacher insists that we define only one function per source file, grouping files/functions belonging to the same class in subdirectories for each class. This results in a structure like: MyClass \MyClass.cc (constructor) \functionForMyClass.cc \anotherF...

Pointers or references for dynamically allocated members that always exist?

I have a class CContainer that has some members CMemberX, CMemberY, which are independent of each other and other CClientA, CClientB classes that use CContainer. #include "MemberX.h" #include "MemberY.h" class CContainer { public: CMemberX & GetX() const { return m_x; } CMemberY & GetY() const { return m_y; } private: CMem...

C++/POSIX how to get a millisecond time-stamp the most efficient way?

Hi, I'm using a open-source library for i2c bus actions. This library frequently uses a function to obtain an actual time-stamp with millisecond resolution. Example Call: nowtime = timer_nowtime(); while ((i2c_CheckBit(dev) == true) && ((timer_nowtime() - nowtime) < I2C_TIMEOUT)); The application using this i2c library uses a lot o...

Screen Pixel Resolution in mm

Is it possible to get the screen pixel resolution in mm using Win32 APIs ? I have an application which is showing 0.3472222222222222 as the value for this on my 1280x1024 monitor with 96 dpi . But I am not able to find out how it got this value. Any clues will be helpful. I can use MFC also if required. EDIT Sorry for the confusion, the...

Odd socket() error -- returns -1, but errno=ERROR_SUCCESS

I'm developing a dedicated game server on a linux machine, in C/C++ (mixed). I have the following snippet of code: int sockfd=socket(AI_INET, SOCK_DGRAM, 0); if(sockfd==-1) { int err=errno; fprintf(stderr,"%s",strerror(err)); exit(1); } My problem here, is that socket is returning -1 (implying a failure) and the error stri...

Why doesn't g++ link with the dynamic library I create?

I've been trying to make some applications which all rely on the same library, and dynamic libraries were my first thought: So I began writing the "Library": /* ThinFS.h */ class FileSystem { public: static void create_container(string file_name); //Creates a new container }; /* ThinFS.cpp */ #include "ThinFS.h" void FileSystem::...

Referencing an unmanaged C++ project within another unmanaged C++ project in Visual Studio 2008

First of all, let me say that I am not a C++ developer. However, I am working on a neural network project that requires me to work with C++. I am working with the Flood Neural Network library. I am trying to use a neural network library in an unmanaged C++ project that I am developing. My goal is to create an instance of a class object w...

STL algorithms on containers of boost::function objects

I have the following code that uses a for loop and I would like to use transform, or at least for_each instead, but I can't see how. typedef std::list<boost::function<void(void) > CallbackList; CallbackList callbacks_; //... for(OptionsMap::const_iterator itr = options.begin(); itr != options.end(); ++itr) { callbacks_.push_back(boo...

const char* 's in C++

How does string expressions in C++ work? Consider: #include <iostream> using namespace std; int main(int argc, char *argv[]){ const char *tmp="hey"; delete [] tmp; return 0; } Where and how is the "hey" expression stored and why is there segmentation fault when I attempt to delete it? ...

Class member function as callback using boost::bind and boost::function

Hey all - I'm working through setting up a member function as a callback for a C-library that I'm using. The C-library sets up callbacks like this: typedef int (*functionPointer_t)(myType1_t*, myType2_t*, myType3_t*); setCallback(param1, param2, functionPointer, param4) I would like to use boost::bind (if possible) to pass in the fu...

C++: Composition Interface

So I've spent some time thinking about this and been all over google looking for a 'solution' (the solution is most likely a matter of preference, but I'm unsure about this). Below is the problem I have, but the problem can be applied to a lot of situations regarding composition. I have a class, Colour, containing the members of red, gr...

MS Calculator on windows 7. I need to know how it does its operations.

MS calculator on windows 7 has a "programmers" mode. When I type in (in binary): 1111111111111111111111111111111111111111111111111111111111111111 and then click "Dec", the binary turns into -1. When I click Oct, the value turns into 1777777777777777777777 However, whenever I use an online converter, it doesn't work. I need to know ho...

C++0x memory model and speculative loads/stores

So I was reading about the memory model that is part of the upcoming C++0x standard. However, I'm a bit confused about some of the restrictions for what the compiler is allowed to do, specifically about speculative loads and stores. To start with, some of the relevant stuff: Hans Boehm's pages about threads and the memory model in C++0...

C++ std::queue::pop() calls destructor. what of pointer types?

Hi, I have a std::queue that is wrapped as a templated class to make a thread-safe queue. I have two versions of this class: one that stores value types, one that stores pointer types. For the pointer type, I'm having trouble deleting the elements of the queue on destruction. The reason is that I don't know a way to remove the items fr...