October 04, 2008

How to convert STL string / wstring to upper / lower case?

This is the STL algorithm way, I think it is better than the itoa() way.

Sample Code:

#include <cctype>
#include <string>

#include <algorithm>


using namespace std;

// Convert string to lower case
string strTest = "I am a STL string";
transform(
  strTest.begin(), strTest.end(),
  strTest.begin(),
  tolower); // toupper for upper case

// Convert wstring to upper case
wstring wstrTest = L"I am a STL wstring";
transform(
  wstrTest.begin(), wstrTest.end(),
  wstrTest.begin(),
  towupper); // towlower for lower case

Reference in MSDN:

September 28, 2008

How to mute an Audio Capture Filter of webcam in DirectShow?

If you want to mute an audio capture of webcam, you have to query IAMAudioInputMixer interface on its INPUT PIN, and then use put_Enable method to disable it.

Both the audio capture filter itself and its input pin have IAMAudioInputMixer interface, but the put_Enable / get_Enable methods are implemented on input pin only.

Reference in MSDN:
http://msdn.microsoft.com/en-us/library/ms783820.aspx

September 07, 2008

How to get the string from GUID in DirectShow?

There is a very useful global array that contains strings representing the GUIDs defined in Uuids.h

char* GuidNames[guid]

Example:
const char* GetMajorTypeString(CMediaType* pMediaType)
{
  return GuidNames[*(pMediaType->Type())];
}

Reference:
http://msdn.microsoft.com/en-us/library/ms783758.aspx

September 06, 2008

Small, simple, cross-platform, free and fast C++ XML Parser

I prefer using this one of XML Parser. It is really simple and convenience. And it contains ONLY TWO files, including "xmlparser.cpp" and "xmlparser.h"

I can compile it without error on VC++ (Visual C++) 2003 and 2005, and it works very well.

You can get more detail information on author's web site.

Small, simple, cross-platform, free and fast C++ XML Parser
http://www.applied-mathematics.net/tools/xmlParser.html

September 05, 2008

The easiest way to toggle / next bookmark in Visual Studio

Shortcuts:
Toggle Bookmark: Ctrl + K Ctrl +K
Next Bookmark: Ctrl + K Ctrl + N

Tips:
You can find the above shortcuts on the bookmark menu, but it is NOT the easiest way to do that.

The other Shortcuts:
Toggle Bookmark: Ctrl + F2
Next Bookmark: F2
(The key mapping is "Visual C++")

August 29, 2008

Why did the RegQueryValueEx() return ERROR_MORE_DATA?

Q: Why does the RegQueryValueEx() always return ERROR_MORE_DATA?

A: If the lpData buffer is too small to receive the data, the function returns ERROR_MORE_DATA.

Windows API:

LONG WINAPI RegQueryValueEx(
  __in HKEY hKey,
  __in_opt LPCTSTR lpValueName,
  __reserved LPDWORD lpReserved,
  __out_opt LPDWORD lpType,
  __out_opt LPBYTE lpData,
  __inout_opt LPDWORD lpcbData
);

Tips:
When you are using RegQueryValueExW(), the parameter of lpcbData
SHOULD be the array size in BYTES, not in characters.

MSDN Reference:

August 21, 2008

How to use Application Verifier for a service on Vista?

Q: After added the execution file of a service to Application Verifier(AV), I still can not find any log reported by AV.

A: You can find the logs here "c:\windows\system32\config\systemprofile\appverifierlogs". You can also copy it to the current user profile, then view logs from AV.