c++

Executable reading itself

I need to read data added to the end of an executable from within that executable . On win32 I have a problem that I cannot open the .exe for reading. I have tried CreateFile and std::ifstream. Is there a way of specifying non-exclusive read access to a file that wasn't initially opened with sharing. EDIT- Great thing about stackoverflo...

randomness

Hi Guys, I need some help regarding algorithm for randomness. So Problem is. There are 50 events going to happen in 8 hours duration. Events can happen at random times. Now it means in each second there is a chance of event happening is 50/(8*60*60)= .001736. How can I do this with random generation algorithm? I can get random number ...

How to safely escape a string from C++

I'm writing a simple program to browse the local network and pass on filenames to mplayer using "system". However, sometimes filenames contain spaces or quotes. Obviously I could write my own function to escape those, but I'm not sure exactly what characters do or do not need escaping. Is there a function available in the CRT or somewhe...

Best resource for learning more about using winsock

I am a Software engineering student, well-versed in C++, but I am interested in programming using I/O from more varied sources than just file I/O with .txt files. For example, I have heard a bit about using winsock and win32 to get input and output over networks. Does anyone know of a good resource for this? ...

calculate seconds-to-date for pre-epoch date/times using MS VS2003

Hi all, I have this routine that calculates the seconds-to-date for a struct tm. On Linux my implementation using mktime works fine, but mktime on windows VS2003/.NET 1.1 returns -1 for pre-epoch datetimes. How do I calculate meaningful time_t values (i.e. value + secondsToEpoch == secondsToDatetime ) from a for pre-epoch dates...

Lambda expression exercise

I have been trying to learn more about lambda expressions lately, and thought of a interesting exercise... is there a way to simplify a c++ integration function like this: // Integral Function double integrate(double a, double b, double (*f)(double)) { double sum = 0.0; // Evaluate integral{a,b} f(x) dx for(int n = 0 ; n <...

Forcing something to be destructed last in C++

I am working on a C++ app which internally has some controller objects that are created and destroyed regularly (using new). It is necessary that these controllers register themselves with another object (let's call it controllerSupervisor), and unregister themselves when they are destructed. The problem I am now facing is happening whe...

How does VC++ mangle local static variable names?

Here's some code I have: MyClass* MyClass::getInstance() { static MyClass instance; return &instance; } I want to look into this singleton's current values. But I'm currently paused three hours into execution, and the reason I'm paused is that I'm out of memory. So I can't put a breakpoint in this method there to see what the va...

How can I access element attributes from an IXMLDOMNode?

Hi all, I'm building an XML DOM document in C++. My problem is this: I execute an XPATH query from an Element in my Document, which I know will return another Element. The elementPtr->selectSingleNode call returns an IXMLDOMNode. How can I gain access to the attributes of this node? Part of me wants to downcast the Node to an Element,...

What are the pros + cons of Link-Time Code Generation? (VS 2005)

I've heard that enabling Link-Time Code Generation (the /LTCG switch) can be a major optimization for large projects with lots of libraries to link together. My team is using it in the Release configuration of our solution, but the long compile-time is a real drag. One change to one file that no other file depends on triggers another 45 ...

Generate Random numbers uniformly over entire range

I need to generate random numbers with in specified interval [max,min] Also the random numbers should be uniformly distributed over interval, not located to particular point Currenly I am generating as: for(int i=0;i<6;i++) { DWORD random= rand()%(max-min+1) + min; } From my tests random numbers are generated around one point only ...

STL::Map - Walk through list or use find?

Say I have a method that needs to pull 8 values from a map with 100 elements in it. Which do you think would be preferable: Walk in a for loop from begin to end once, pulling the elements out by switching on the key? Or using find 8 times to get those values? ...

How can I pass a reference parameter (&) (not pointer) using p/invoke in C#?

I have a C++ API prototype void Func(int& size); How can I translate it to P/Invoke in C#? From what I know, if I use public static extern Func(ref int size); , the function will receive a pointer to the int instead of the value. ...

Is it worth porting a small C# "engine" to C++ or similar?

So, following a tutorial I found on MSDN I've created what you might call an "engine" using DirectX and C#. I haven't seen a lot of this sort of thing (Personally, that is) done in C# and the majority seem to favour C/C++ so I'm curious as to whether using C# will come back to bite me, or whether I should just go ahead? The reason I ask...

strtok and replace a substring in C++

If I have a string "12 23 34 56" What's the easiest way to change it to "\x12 \x23 \x34 \x56"? ...

get VC debugger to show more frames in a stack overflow

I was remote debugging a stack overflow from a recursive function. The Visual Studio IDE only showed the first 1,000 frames (all the same function), but I needed to go up further too see what the cause was. Does anybody know how to get VS to 'move up' in a stack listing? Thanks. ...

Using strtok with a string argument (instead of char*)?

I have a string that I would like to tokenize. But the strtok() function requires my string to be a char*. How can I do this quickly? token = strtok(str.c_str(), " "); fails because it turns it into a const char*, not a char* ...

Strange issue running infinite while loop in EXE

I am facing strange issue on Windows CE: Running 3 EXEs 1)First exe doing some work every 8 minutes unless exit event is signaled. 2)Second exe doing some work every 5 minutes unless exit event signaled. 3)Third exe while loop is running and in while loop it do some work at random times. This while loop continues until exit event signa...

What happens to namespace?

when a dll is created out of the source code in a given namespaces a,b with functions a::open,b::open will there be any conflict in calling these function. ...

how dll created out of c++ source and how it is used in other sources?

how is dll created out of c++ source and how it is used in other source? ...