Setting a boost shared_ptr to NULL

0

Posted by Jaime | Posted in Coding | Posted on 25-04-2011

Tags: , , ,

If you need to set a boost shared_ptr to NULL, then you can do it like this:

boost::shared_ptr<OohClass>();

So, if you have a function that returns a boost shared_ptr and you want to pass NULL to represent either an error state or a not-found state, you can do this:

#include <map>
typedef boost::shared_ptr<OohClass> OohClassPtr;
typedef std::map< const char*, OohClassPtr > OohClassMap;
 
OohClassPtr FindMyClass( const char* key, OohClassMap& ocmRef )
{
	OohClassPtr ptr;
	OohClassMap::iterator itr = ocmRef.find(key);
	if (itr != ocmRef.end())
		ptr = itr->second;
	else
		ptr = boost::shared_ptr<OohClass>();
	return ptr;
}

Handy!

How to switch between a header file and implementation file in Visual Studio

0

Posted by Jaime | Posted in Coding, Tip | Posted on 25-04-2011

Tags: ,

Microsoft Visual Studio 2008
There used to be a button that would toggle you between the header file and implementation file that currently had the focus in Visual Studio.

For reasons unknown to me, that feature was taken out in Visual Studio.

Here is a macro though that brings that functionality back: I want my toggle button back!

Copying a project file to a known location

0

Posted by Jaime | Posted in Coding, Tip | Posted on 22-04-2011

Tags: , ,

Microsoft Visual Studio 2008
Within a Visual Studio C++ solution, you can copy a file to a known location as part of the build process.

To do that, you have so set the “Custom Build Step” parameters found in the Visual Studio project’s property page:

Command line: copy "$(InputPath)" "$(TargetDir)" > nul
Description: Copying $(InputFileName)
Outputs: $(TargetDir)$(InputFileName)

Note, the first line is the actual copy command. If you want to see the command without executing it, you can place @echo in front of the command.

Also note, the second line prints some text to the output screen, so you know what is going on.

For some projects, I have to run Visual Studio in adminstrator mode, otherwise the IDE is unable to copy the file to the restricted location.

I found instructions on how to run Visual Studio in administrative mode at: gottoknow dot com :

  1. Click the ‘Start’ button.
  2. Click ‘All Programs’
  3. In the menu, locate and click on the folder that says ‘Microsoft Visual Studio 2010’ (your version might be 2005, or 2008).
  4. Now right-click on the ‘Microsoft Visual Studio 2010’ program file, which will bring up the ‘Properties’ pop-up box.
  5. Select the ‘Compatibility’ tab, and then in the Privilege Level section, check the box next to “Run this program as an administrator”
  6. Click the ‘Apply’ button, then click the ‘OK’ button.
  7. Now each time you open Microsoft Visual Studio 2010, it will be running in (Administrator) mode.

References:
http://msdn.microsoft.com/en-us/library/b0bktkzs(v=vs.80).aspx

MacDependency

3

Posted by Jaime | Posted in Coding | Posted on 20-04-2011

Tags: , ,

I found this useful tool, thanks to my coworker, that is an alternative to using the otool tool: MacDependency

VMR9

0

Posted by Jaime | Posted in Coding | Posted on 18-04-2011

Tags: , ,

Right now I’m dealing with some code of mine that isn’t working on a Microsoft product.

I got a webcam, a Microsoft Life Cam VX1000, that doesn’t want to work with DirectX.

It’s weird. A Microsoft product that doesn’t want to work with a Microsoft SDK.

I see on the web though that there are a lot of people who have the same problem.

When I get a solution, I’ll post the answer to help anyone else who is having the same problem.