December 26, 2007

How to get the maximum length of full path in windows?

_MAX_DIR = Maximum length of directory component
_MAX_DRIVE = Maximum length of drive component
_MAX_EXT = Maximum length of extension component
_MAX_FNAME = Maximum length of filename component
_MAX_PATH = Maximum length of full path.

The sum of the fields should not exceed _MAX_PATH.
(The sizes include space for 0-terminator.)

December 25, 2007

How to get the special folders of windows?

(For Windows XP)
SHGetFolderPath Function
http://msdn2.microsoft.com/en-us/library/bb762181.aspx

(For Windows Vista and later)
SHGetKnownFolderPath Function
http://msdn2.microsoft.com/en-us/library/bb762188.aspx

December 09, 2007

How to use critical section?

// Declaration
CRITICAL_SECTION CriticalSection;

// Initialize
::InitializeCriticalSection(&CriticalSection);

// Implementation
::EnterCriticalSection(&CriticalSection);
/* Code block */
::LeaveCriticalSection(&CriticalSection);

// Uninitialize
::DeleteCriticalSection(&CriticalSection);

December 06, 2007

Convert Any Value Type to STL String by Stringstream

#include <sstream>

using namespace std;

int a = 1;
double b = 2.0;
float c = 3.0;
unsigned int d = 4;
long long f = 5;
__int64 g = 6;

wstringstream stream; (use stringstream for string)
wstring str;
stream << g; (this can be replaced by any value type)
stream >> str;

Read/Write INI Files in C#

A Complete Win32 INI File Utility Class
http://www.codeproject.com/KB/files/win32fileutilityclass.aspx

C# wrap for calling windows api. Easy to use!

December 05, 2007

SYSTEMTIME, FILETIME, and LARGE_INTEGER

SYSTEMTIME to FILETIME
SystemTimeToFileTime Function
http://msdn2.microsoft.com/en-us/library/ms724948.aspx

FILETIME to SYSTEMTIME
FileTimeToSystemTime Function
http://msdn2.microsoft.com/en-us/library/ms724277.aspx

Copy FILETIME to LARGE_INTEGER
LARGE_INTEGER.LowPart = FILETIME.dwLowDateTime
LARGE_INTEGER.HighPart = FILETIME.dwHighDateTime

Copy LARGE_INTEGER to FILETIME
FILETIME.dwLowDateTime = LARGE_INTEGER.LowPart
FILETIME.dwHighDateTime = LARGE_INTEGER.HighPart

LARGE_INTEGER
Perform 64-bit arthimetic on LARGE_INTEGER.QuardPart member

December 01, 2007

How to change the tab order in a MFC dialog?

Step 1.
In resource view of the dialog, select menu [Format] -> [Tab Order] or just press Ctrl +D.

Step 2.
Then you can select item in specified order.