c++

Overriding in C++

class base { public: int foo(); int foo(int a); int foo(char* b); int doSomething(int); } class derived : public base { public: int doSomething(int b); } int derived::doSomething( int b) { base::doSomething(b); //Make Something else } int main()...

c++ define types/call functions based on configuration

In C++, is there a nice technique or design pattern to perform the following tasks based on configuration? Scenario #1: Call functions If a configuration says: A:foo() Then the code should call A::foo() assuming that the object of A is already accessible. Scenario #2: Declare type If a configuration says: bar:vector<std::string> ...

How to determine whether an LSA session is active in Windows XP

I'm trying to get the list of users currently logged into a machine. On Windows 7, I can call LsaEnumerateLogonSessions, then WTSQuerySessionInformation with WTSConnectState. But on XP, each LSA session has 0 for the TS Session field (unless it's a Remote Desktop session), which always has WTSConnectState of WTSActive, and I end up lis...

C++ Template Portability

I am updating a code base that is 10 years old and used Metrowerks Code Warrior on Mac and Windows. I am updating to OS X, XCode 3.2, Universal Binary. I seem to be getting a lot of template related errors and not being a genius on templates (and forgetting to eat a healthy dose of frosted templates for breakfast), I find myself wonde...

How to hardcode a value in a texbox in c++

I am using the below code to popup the authentication dialog. I want to hard-code the password in my code and make it a read-only text box. What should I do? IDD_LOGIN_AUTH_DIALOG DIALOG DISCARDABLE 0, 0, 148, 82 STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU CAPTION "Authentication" FONT 8, "MS Shell Dlg" BEGIN LTEXT ...

NameSpaces When, Where, Why!

Hi All, I have code that uses namespaces, a few of them and I am having some confusion in my brain. If I have something like: #include <vector> protected: vector<registeredObject> mRegistryList; The compiler complains that vector has 'no type' Can't I just do this: #include <vector> protected: std::vector<registeredObject...

automatically skipping/ignoring external code in gdb

anybody know how to tell gdb to only enter code that is in your project? I know it's hard for a debugger to know what is "in the project" and what is a library....but I thought some naive checks could help, eg don't look in any files that aren't in the users home directory. I frequently have code like this: MyFunction(complexVarable, co...

QGraphicsView missing text on some draws

I've tried drawing a rectangle with text inside in a QGraphicsView. I get the text from the currently selected item in a QTreeWidget. The scene seems to sporadically show the text, sometimes it will, sometimes it won't. void MainWindow::on_treewidget_itemSelectionChanged() { drawSectionFromProperties(ui->treewidget->currentItem()); } v...

Rounding with static_cast<int> ?

Hi, I feel really silly asking this because I know how to do it 101 ways, but not the way it is defined in the book. (note, I know C++) So far, we have only gone over the very basics of C++. So basically, we know variables, assignment, and basic casting. In the book I am having trouble with this portion of the problem: prompt the us...

Any useful suggestions to figure out where memory is being free'd in a Win32 process?

An application I am working with is exhibiting the following behaviour: During a particular high-memory operation, the memory usage of the process under Task Manager (Mem Usage stat) reaches a peak of approximately 2.5GB (Note: A registry key has been set to allow this, as usually there is a maximum of 2GB for a process under 32-bit Wi...

Why doesn't this reinterpret_cast compile?

I understand that reinterpret_cast is dangerous, I'm just doing this to test it. I have the following code: int x = 0; double y = reinterpret_cast<double>(x); When I try to compile the program, it gives me an error saying invalid cast from type 'float' to type 'double What's going on? I thought reinterpret_cast was the rogue cast t...

How to flush file buffers when using boost::serialization?

I'm saving a file on an USB drive and need to make sure that it's completely written to avoid corruption in case the USB drive is not removed properly. Well I've done some research and it seems this is possible via calling the FlushFileBuffers Win32 function. But the problem is, I'm saving using boost::serialization and thus don't have a...

Iterate through struct variables.

I want to get an iterator to struct variable to set a particular one on runtime according to enum ID. for example - struct { char _char; int _int; char* pchar; }; enum { _CHAR, //0 _INT, //1 PCHAR //2 }; int main() { int i = 1; //_INT //if i = 1 then set variable _int of struct to some value. } can you do that without if/e...

How to call unmanaged c++ function that allocates output buffer to return data in c#?

I have problems with marshalling output parameter of c++ function returning array of data to c#. Here is C++ declaration: #define DLL_API __declspec(dllexport) typedef TPARAMETER_DATA { char *parameter; int size; } PARAMETER_DATA; int DLL_API GetParameters(PARAMETER_DATA *outputData); The function allocates memo...

Conditional dependency with make/gmake

Is there a way to direct make/gmake to act upon conditional dependencies? I have this rule in place: $(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp $(CPPC) -c $(FLAGS_DEV) $< -o $@ In the general case, every .cpp file has a corresponding .h file; however there are a few exceptions. Is there a way to achieve "depend on this if it exists" with gm...

How to convert a string to Unsigned char in visual c++

How to convert a string to Unsigned char in c++... I have, unsigned char m_Test[8]; i want to assign a string "Hello world" to the m_Test. how to do it ? ...

Language codes in platform SDK 6.1

Hi, Language codes are in the form "en-US","de-DE" or "sl-SI" for English US, German and slovakian respectively. Whether there is any #define s present in PLATFORM SDK 6.1 for language codes. Its better if i got these values instead of using Hard coded strings in my program. Can anyone help me regarding this. Its better if i get the hea...

Com Server: .tlbimp.exe does not recognize methods with pointer parameters

I am writing a comserver that have a pointer as parameter: STDMETHODIMP TServerDidleComTestImpl::GetMyObject(IDummyComObj** outObj) { //Do stuff } When I am writing a client in c++ I have no problem with this method, but when trying to write a .Net client the tlbimp.exe says: Type library importer has encountered a method with...

Plugin DLLs that depend on other DLLs

I am writing a DLL to plug into another (3rd party) application. The DLL will need to depend on another set of DLLs (for license reasons I cannot link statically). I would like my DLL to be "xcopy-deployable" to any directory. I would also like not to require adding this directory to the path. If I just build the DLL the usual way, Win...

Conditional operator in member-initialization list

Hi, Suppose I have this class: class foo { public: foo() { } foo(const std::string& s) : _s(s) { } private: std::string _s; }; Which is a member of another class: class bar { public: bar(bool condition) : _f(condition ? "go to string constructor" : **go to empty ctor**) { } private: foo _f; };...