c++

Is it possible to lower the privilege level when calling CoCreateInstance on Vista?

Okay, I have a plugin for IE that when installed needs to (with the user's permission) restart IE. To do this I have a DLL that is invoked by the installer. And it works, but the problem is that when IE is restarted on Vista, it is restarted with the administrator privileges of the installer, which is a problem for a number of reasons. ...

Reference initialization in C++

Greetings, everyone! Examining my own code, I came up to this interesting line: const CString &refStr = ( CheckCondition() ) ? _T("foo") : _T("bar"); Now I am completely at a loss, and cannot understand why it is legal. As far as I understand, const reference must be initialized, either with r-value or l-value. Uninitialized referenc...

crash when calling library

Let's hope I can dumb this down without leaving out crucial details... I've got a test program: #include <lib.h> const char * INPUT = "xyz"; int main() { initializeLib(); LibProcess * process = createLibProcess(); fprintf( stderr, "Before run(%s)\n", INPUT ); process->run(INPUT); fprintf( stderr, "After run(%s)\n...

How to make a string preprocessor definition from command-line in VC 2005 (C++)?

The documentation tells me that /D command-line switch can be used to do this, like so: CL /DDEBUG TEST.C would define a DEBUG symbol, and CL /DDEBUG=2 TEST.C would give it the value 2. But what do I do if I would like to get the equivalent of a string define, such as #define DEBUG "abc" ? ...

Debug DLL's under Windows with GDB

Hello! I have some project consisting of a couple of DLL's which have been compiled with MinGW with debug information, and another project with EXE target which uses these DLLs (compiled with MinGW too). The problem is, I need to put breakpoints on functions inside those DLLs, but GDB, although sets them, just silently ignores them at ...

Designing efficient C++ code for fibers

How do I utilize fibers best in my game code? Should it only be used to manage nonpreemptive context-switches while loading resources (i.e. files from disk)? Or do I allow all types of game entities to run in a fiber? How do I schedule? C++ or pseudo code samples greatly appreciated! ...

How do ensure that while writing C++ code itself it will not cause any memory leaks?

Running valgrind or purify would be the next steps But while while writing the code itself how do you ensure that it will not cause any memory leaks? You can ensure following things:- 1: Number of new equal to delete 2: Opened File descriptor is closed or not Is there any thing else? ...

what is wrong in my code getting current page path??

Hi I have my visualstudio vcproj file at c:\vsproj\example\test\test.vcproj under this path i have some other files like e test.cpp file and also a dll test.dll is there. so totally under tha path c:\vsproj\example\test i have 1) test.vsproj 2) test.dll 3) test.cpp normally to get the cuurent folder path we use ".\" so i have appli...

Why does C++ need a separate header file?

I've never really understood why C++ needs a separate header file with the same functions as in the .cpp file. It makes creating classes and refactoring them very difficult, and it adds unnecessary files to the project. And then there is the problem with having to include header files, but having to explicitly check if it has already bee...

How to determine whether output iterator has been modified

I have a template function that takes the following form: template < class ITER1, class ITER2 > bool example(ITER1 Input1, ITER1 Input2, ITER2 Output) { ITER2 OrigOutput(Output); // ... std::copy(Input1, Input2, Output); return (OrigOutput != Output); } And I'm calling example() like this: std::vector < int > Input...

Catching default exceptions in C++

I was just wondering if a system exception like say divide by zero actually "throws" something to the application. Would it be possible to catch this somehow by default?. i mean we can define a custom divide fn which checks for null divisor and throws an exception, but just thought it would be nice if this exception was thrown by defaul...

boost signal double free?

I'm having a hell of a time trying to debug some kind of memory access error, which I believe is a double free. The code is too complex to post, but I can try to describe it. Basically, I have two threads. When the worker thread is created, it instantiates a new boost::signal object, and stores it in a shared_ptr. The parent then querie...

Does the memory get released when I throw an exception?

Hi, I was debating with some colleges about what happens when you throw an exception in a dynamically allocated class. I know that malloc gets called, and then the constructor of the class. The constructor never returns, so what happens to the malloc? Consider the following class B { public: B() { cout << "B::B()" ...

Overhead due to use of Events

I have a custom thread pool class, that creates some threads that each wait on their own event (signal). When a new job is added to the thread pool, it wakes the first free thread so that it executes the job. The problem is the following : I have around 1000 loops of each around 10'000 iterations do to. These loops must be executed sequ...

What is the meaning and usage of __stdcall ?

I come across _stdcall a lot these days. And in my opinion msdn doesn't explain very clearly what it really means, when and why should it be used, if at all. I would appreciate if someone would provide an explanation, preferably, with an example, or 2. Thanks ...

Crossfading scenes in OpenGL

I would like to render two scenes in OpenGL, and then do a visual crossfade from one scene to the second. Can anyone suggest a starting point for learning how to do this? Cheers ...

Problem using BeginInvoke in Managed C++ WinForms

Hello, I am seeing something I do not understand while using Control.BeginInvoke to update a WinForms form in response to an event from a backgraound thread. The app is written in Managed C++. There are four classes involved: 1) a MyMonitor class that has a timer that goes off every second or so, and examines the state of a de...

Why i can't declare following function in Visual C++ "string timeToStr(string);"?

When i'm trying to declare a function with a string parameter in .h file an error occurs. I haven't forgot to include string.h =) Everything builds fine when i'm using char[], but the i want the argument to be a string. ...

How do I implement no-op macro (or template) in C++?

How do I implement no-op macro in C++? #include <iostream> #ifdef NOOP #define conditional_noop(x) what goes here? #else #define conditional_noop(x) std::cout << (x) #endif int main() { conditional_noop(123); } I want this to do nothing when NOOP is defined and print "123", when NOOP is...

Symbian panics when deleting dynamic array

Hi I am trying to allocate a char array of size 1000. This array is passed to a function where it should be filled with the data that has been received from the TCP Socket. The problem occurs then when I try to delete[] buffer: Here I get as a result a User Panic 42. Unfortunately, I do not really see what is going wrong in this simple ...