c++ - stuff I can never remember

entry point functions for finding info in MSDN

building boost

.\bjam --build-type=complete toolset=msvc-9.0 --build-dir=build90
note don't put dots in the output build directory or bjam gets confused, don't use the -q option and don't use powershell, use normal command prompt.

boost bind

How to use boost bind to search for a record that has a member variable with a specified value.

struct foo {
    int _a;
};

typedef std::vector< foo >  vecT;

vecT&   vec = getFooVec();

vecT::iterator  pos = 
    pos = std::find_if(
            vec.begin(), vec.end(),
            boost::bind(
                std::equal_to< int >(),
                    boost::bind(&foo::_a, _1),
                    42));

		

boost::tokenizer

You'd think the boost tokenizer header would have some typedefs for iteratoring over std::wstring, but no.

typedef std::wstring                                      strT;
typedef strT::const_iterator                              cIter;
typedef	boost::char_separator< wchar_t >                  separator;
typedef	boost::tokenizer< separator, cIter, std::wstring> tokeniser;
typedef	tokeniser::const_iterator                         tokIt;

separator sep(L"/");
tokeniser toker(str, sep);
tokIt     it(toker.begin()), end(toker.end());

for(; it != end; ++it) {
   const std::wstring  str(*it);
}
		

find path of dll, instead of the .exe that you get when you call GetModuleFileName(0, ...);

extern "C" void * _ReturnAddress(void);

#pragma intrinsic(_ReturnAddress)

void pathToCallingFunctionsDll(std::wstring &rPath) {
   wchar_t buff[256];
   buff[0] = '\0';

   HMODULE  module;

   if( TRUE == GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS,
         reinterpret_cast< LPCWSTR >(_ReturnAddress()), &module) ) {
      GetModuleFileName(module, buff, 256);
      rPath = buff;
   }
}
		

find dlls a program is trying to load.

For visual studio:
Set a break point at {,,kernel32.dll}_LoadLibraryExW@12
Ignore the warning about not being able to find the location.
Open a memory display window, type ESP into the address. Right click on the memory window, select 4-Byte integer display. The 1st int is the return address, the 2nd is the pointer to the library name. Copy it into the address bit of another memory display window. (don't forget the 0x prefix to indicate it's HEX)

MIDL

Midl compiler will not produce some of the required output files if you don't have at least one interface in your IDL.

finding linker directives in static libs.

Use the visual studio command line tool dumpbin. use the /directives switch and apply to each .obj, checking the /DEFAULTLIB: bits.

random spirit snippets

parse spread sheet cell refs

static void assign(size_t val, size_t& dst)
{
   dst = val;
}

static void assignCol(std::wstring::const_iterator begin, std::wstring::const_iterator end, std::wstring& dst)
{
   dst.assign(begin, end);
}

using namespace boost::spirit::classic;

typedef std::wstring::const_iterator                     const_iterator;
typedef scanner< const_iterator, scanner_policies_t >    wstring_skip_scanner;
typedef rule< wstring_skip_scanner >                     rule;
typedef parse_info< const_iterator >                     parse_info;

rule        cellParser((*alpha_p)[ boost::bind(&assignCol, _1, _2, boost::ref(col)) ] >> int_p[ boost::bind(&assign, _1, boost::ref(row)) ]);
parse_info  rv = parse< const_iterator >(cell.begin(), cell.end(), cellParser, space_p);
		

standard pre-compiled header contents - for visual studio environments.

#pragma once

#ifndef STRICT
#	define STRICT
#endif

#ifndef WINVER
#  define WINVER 0x0501
#endif
#ifndef _WIN32_WINNT
#  define _WIN32_WINNT 0x0501
#endif

#ifndef  WIN32_LEAN_AND_MEAN
#	define  WIN32_LEAN_AND_MEAN
#endif

#ifndef NOMINMAX
#	define NOMINMAX
#endif
#include <windows.h>

#ifndef _USE_MATH_DEFINES
#	define _USE_MATH_DEFINES
#endif

#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <vector>

#define _ATL_APARTMENT_THREADED
#define _ATL_NO_AUTOMATIC_NAMESPACE
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS
#define _ATL_ALL_WARNINGS

#include <atlbase.h>
#include <atlconv.h>
#include <atlcom.h>
#include <atlwin.h>

using namespace ATL;

#pragma warning (disable: 4251)  //'x' : class 'y' needs to have dll-interface to be used by clients of class 'z'
#pragma warning (disable: 4275)  // non dll-interface class 'x' used as base for dll-interface class 'y'

		

debugger visualisation for visual studio

Control how the debugger displays variables by setting environment variable '_vcee_autoexp' to point to your own autoexp.dat file. Look in the autoexp.dat file provided w/ VS for documentation: C:\Program Files\Microsoft Visual Studio 9.0\Common7\Packages\Debugger\autoexp.dat


ssTk.co.uk
Last updated: 02 February 2012