c++

Redirecting C++ fstream

So I have a C++ program, that normally when it executes writes out things to a log file. This is done using an fstream. However, now I want to include functionality to turn the logging off. Essentially, my code looks like this: bool isLogging; fstream* logFilePtr; throughout my code, there are a bunch of statements like: (*logFile...

Need help with STL sort algorithm

I'm having some troubles with using the std::sort algorithm here. I was reading that you can just overload the less than operator to sort classes, but I have been getting all sorts of errors. I have also tried using a functor as you can see in the example I made below. I was hoping somebody could see what I'm doing wrong here. #include...

Finding MAC address from IP

Possible Duplicate: Getting the MAC address of the remote host I'm working on a module which has a client server architecture. And i have to authenticate the connecting peer machine on the basis of Mac address. At the time of installation i store a encrypted list of valid Mac addresses. Please note that i have no control...

Using templated "super"

Related question: Using "super" in C++ I examined the source code for OpenSteer and found the following code for defining properties of vehicles. The requirement is Super have too be inherited from an interface class AbstractVehicle. template <class Super> class SteerLibraryMixin : public Super { ... } template <class Super> class Ann...

Necessary to pin_ptr on C++ CLR Value types, why?

Since .NET Value types (managed C++ structs) are stored on the Stack why is it (or, alternatively is it actually) necessary to pin_ptr them in order to pass a pointer to an unmanaged function? Eg. BYTE b[100]; If I pass &b to an unmanaged function without first pinning it, may the stack become corrupted? Is the CLR stack subject to c...

Can I create an object from a derived class by constructing the base object with a parameter?

In other words, given a base class shape and a derived class rectangle: class shape { public: enum shapeType {LINE, RECTANGLE}; shape(shapeType type); shape(const shape &shp); } class rectangle : public shape { public: rectangle(); rectangle(const rectangle &rec); } I'd like to know if I could create an instance of rectangl...

C++ OpenGL Window and Context creation framework / library

I'm searching for an multi platform OpenGL framework that abstracts the creation of windows and gl contexts in C++. I'd like to have an OO representation of Window, Context & co where i can instantiate a Window, create a Context and maybe later set the window to fullscreen. I'm thinking about implementing this myself for xgl, wgl and ag...

Multiple Rendertargets in DX9

I've set m_lpD3DDevice->SetRenderTarget(0,Buffer1); m_lpD3DDevice->SetRenderTarget(1,Buffer2); m_lpD3DDevice->SetRenderTarget(2,Buffer2); and if I render the pixelshader only affects the first render target. It's output structure is struct PS_OUTPUT { float4 Color0 : COLOR0; float4 Color1 : COLOR1; float4 Color2...

Adding SSL support to existing TCP & UDP code?

Here's my question. Right now I have a Linux server application (written using C++ - gcc) that communicates with a Windows C++ client application (Visual Studio 9, Qt 4.5.) What is the very easiest way to add SSL support to both sides in order to secure the communication, without completely gutting the existing protocol? It's a VOIP...

Multiplatform C++ Project: Inclusion of platform specific sources

I have for some of my classes different implementations per OS. My source structure is like this: include/AExample.h include/windows/WindowsExample.h include/linux/LinuxExample.h src/AExample.cpp src/windows/WindowsExample.cpp src/linux/LinuxExample.cpp the A* classes are the interfaces for the specific implementations My current bu...

Efficency of Comparisons in C++? ( abs(X)>1 vs abs(x) != 0)

I know- Premature optimization. But I've got code that's supposed to find out if a position is changed vs a cached position. Current code is: if(abs(newpos-oldpos) > 1){ ..... } Is it more efficient to use the following? if(abs(newpos-oldpos) != 0){ .... } Why or why not? I'm currently debating it my head which is more re...

MFC: GetWindowRect usage

I'm trying to determine the window position of an application. I know SetWindowPos() would set the window position at a certain position with a specific sizing. I would like to retrieve this information, but I have noticed some negative values in there. When I save these values into the registry and then load them on the next instance, I...

XPath support in Xerces-C

I am supporting a legacy C++ application which uses Xerces-C for XML parsing. I've been spoiled by .Net and am used to using XPath to select nodes from a DOM tree. Is there any way to get access some limited XPath functionality in Xerces-C? I'm looking for something like selectNodes("/for/bar/baz"). I could do this manually, but XPat...

Open source project for c++ developer?

I am a vc++ developer (but like Qt) interested in learning from open source project by contributing and reading the code. I use windows as primary development platform. Which project will be right for me to start? Is chromium a good choice? ...

What is a "translation unit" in C++

Hello everybody I am reading at the time the "Effective C++" written by Meyers and came across the term "translation unit". Could somebody please give me an explanation of: 1) What exactly it is 2) When should I consider using it when programming with C++ 3) If it is related only to C++, or it can be used with other programming lan...

Group sorting a vector in C++

I have a std::vector full of objects, each with a numeric group identifier associated with them. The object also has properties such as "size" and "name". I need to be able to sort the vector of objects by name, size and other properties while keeping them grouped together (e.g. by the group identifier mentioned above). How can this go...

Will multi threading provide any performance boost?

Hello everyone, I am new to programming in general so please keep that in mind when you answer my question. I have a program that takes a large 3D array (1 billion elements) and sums up elements along the various axis to produce a 2D array of a projection of each side of the data. The problem here is that it is very ram intensive as th...

Modify a Binary file(an after effect project file) in c# or c++

I need to change some text values inside an after effect project file that I assume it's a binary file. You cannot edit this file with a text editor, if you do next time you open it you will encounter the error message about corrupted project file. So i need to for example change "TextArea1" to "Some new text" so as you see the length o...

Overwriting function in another dll without edits to primary dll

This one game I do scripting for uses a primary dll in which our scripts we write (creatively named "scripts.dll" This scripts.dll, server-side, loads other plugins (.dlls as well). Question: I need to override an existing function in scripts.dll in, for example, pluginA.dll to where the one in scripts.dll doesn't get called. I had th...

Handle HTMLElementEvents2 when DWebBrowserEvents2 has been handled using ATL's macros

I'm creating a Browser Helper Object using VS2008, C++. My class has been derived from IDispEventImpl among many others class ATL_NO_VTABLE CHelloWorldBHO : public CComObjectRootEx<CComSingleThreadModel>, public CComCoClass<CHelloWorldBHO, &CLSID_HelloWorldBHO>, public IObjectWithSiteImpl<CHelloWorldBHO>, public IDispatc...