c++

date and time picker problem, can't reset date or time

I'm using a usoft date time picker control in a dialog box. I started by setting the format to "HH':'mm' 'ddddMMMdd','yyyy" and the current local date & time using DTM-SETSYSTEMTIME. If the user changes any field in the control, the program can not reset the date and time in the control using DTM-SETSYSTEMTIME although SendMessage retur...

C++ simple operations (+,-,/,*) evaluation class

I am looking for a C++ class I can incorporate into a project I am working on. the functionality I need is evaluation of string operations to numerical form: for example "2 + 3*7" should evaluate to 23. I do realize what I am asking is a kind of an interpreter, and that there are tools to build them, by my background in CS is very poo...

Using type of function pointer as template argument

I'm trying to write a template which gets the type of a functionpointer as templateargument and the corresponding functionpointer as a function argument, so as a simplyfied example I'm doing this right now: int myfunc(int a) { return a; } template<typename T, typename Func> struct Test { typedef typeof(myfunc) Fun; static T MyF...

sprintf(buf, "%.20g", x) // how large should buf be?

I am converting double values to string like this: std::string conv(double x) { char buf[30]; sprintf(buf, "%.20g", x); return buf; } I have hardcoded the buffer size to 30, but am not sure if this is large enough for all cases. How can I find out the maximum buffer size I need? Does the precision get higher (and theref...

Problem with luabind::object dereferencing (simplified)

Using C++, lua5.1, luabind 0.7 Lua code: -- allocates near 8Mb of memory function fff() local t = {} for i = 1, 300000 do table.insert(t, i) end return t end C++ code: { luaL_dostring(lua_state, "return fff()"); luabind::object obj(luabind::from_stack(ls, -1)); } lua_gc(l_, LUA_GCCOLLECT, 0); // colle...

C++ namespaces trobles

//portl.cpp namespace FAWN { namespace Sys{ class PortListner { .... Connecter::ConPtr _cur_con; - the main problem is here ... //con.cpp namespace FAWN { namespace Sys { class Connecter { ..... public: typedef boost::shared_ptr<Connecter> ConPtr; ... Moreover, portl.cpp file is included into some other "main" sourse file. An...

one question about initialization list in C++

Hi I was told there are multiple situations in which initialization list must be used to for initialization. There are three cases 1) const member 2) reference 3) members without default constructors Is that right? Anyone would like elaborate this? Is there any other case I missed? Thanks! ...

Indirectly calling non-const function on a const object

Given the following code: class foo; foo* instance = NULL; class foo { public: explicit foo(int j) : i(j) { instance = this; } void inc() { ++i; } private: int i; }; Is the following using defined behavior? const foo f(0); int main() { instance->inc(); } I'm asking because I'm using a cl...

One more time: LNK2005 (now ok) and LNK2019 (ok)

I know that all forums are full of such question, but I've tried few hooks, and they doesn't work (or I do them bad). So, I've got: main.cpp <- fawn.h <- connector.cpp (defenition) <- conncetor.h (declaration) <- portl.cpp (def) <- portl.h (dcl) <- connector.h with include guard (thanks to Igor Zevaka a...

Odd behavior when passing copy via '*this'

Recently I implemented a 'Paused' screen in my game. Since I wanted it to be a separate game state, I needed to somehow save the data from when the player paused the game to when they re-enter. However, when states are switched the pointer to the previous state is deleted. Thus, I decided for the Paused constructor to take a copy of the...

Cannot recreate named pipe under vista

Hey, In my application i have the app and a service that does stuff for the app. They communicate via a named pipe. Now i can start the app and it starts the service and connects and this works well. When the application downloads an update, it restarts it self (to unload in use modules) killing the service and then starts the service...

Python, Threads, the GIL, and C++

Is there some way to make boost::python control the Python GIL for every interaction with python? I am writing a project with boost::python. I am trying to write a C++ wrapper for an external library, and control the C++ library with python scripts. I cannot change the external library, only my wrapper program. (I am writing a functi...

Displaying graphics on top of another full screen application; hardware overlay?

On Windows (Vista32), I want to display some simple graphics on top of a fullscreen flash window (an overlay of useful information while using the flash application). What's the fastest way to accomplish it? I think I may be able to achieve it using DirectX with the DDSCAPS_OVERLAY flag but with the only example I've found I get an exce...

Why does copy constructor call other class' default constructor?

I was wondering why an error like this would occur. no matching function for call to 'Foo::Foo()' in code for a copy constructor? Assume Foo is just an object with normal fields ( no dynamically allocated memory, etc. ), and the only constructor it has defined is a constructor that takes one argument. I didn't even know the construct...

Using pattern Adapter for Image Viewer

Hi! I do the Image Viewer. I want to use GDI+ for showing a picture in a window. And the library boost::gil for rotating, converting, resizng an image. But GDI+ contains Image class and boost::gil contains other class Image. How can I use the pattern Adapter for my task? Or what pattern should I use? Thanks! ...

How to add web-services as a layer on the top of sockets written in C/C++?

Is it possible to exchange web-services over socket programs written in C/C++? The data to exchange are in the from of xml/soap message. ...

What is the difference between POSIX sockets and BSD sockets?

Could someone please explain the differences between POSIX sockets and BSD sockets? ...

Using std::map<K,V> where V has no usable default constructor

I have a symbol table implemented as a std::map. For the value, there is no way to legitimately construct an instance of the value type via a default constructor. However if I don't provide a default constructor, I get a compiler error and if I make the constructor assert, my program compile just fine but crashes inside of map<K,V>::oper...

Boost Libraries Support for MS VC++ 10.0

Friends I have been using Microsoft Visual C++ 2010 Express edition and also downloaded the Boost Libraries for Windows and I would want to have Boost linked with VC++ so that I can run programs that involves Boost libraries in VC++. Please provide some inputs on Boost with VC++ Thank you ...

count number of files with a given extension in a directory - C++?

Hi there, Is it possible in c++ to count the number of files with a given extension in a directory? I'm writing a program where it would be nice to do something like this (pseudo-code): if (file_extension == ".foo") num_files++; for (int i = 0; i < num_files; i++) // do something Obviously, this program is much more complex,...