跳到主要內容

包裝OutputDebugString成為printf style的介面

下面的程式將OutputDebugString包裝成printf介面,有需要的人可以自行copy回去使用,這對於輸出Debug資訊上有一定程度的幫助,另外對於看Debug message的工具,個人推薦使用DbgView ,目前最新版本已經可以在Vista 32/64-bit平台下面使用。實在是一個非常方便的工具。


#ifdef DBG

void __cdecl DbgPrint(LPCTSTR format, ...)
{
static TCHAR DbgMsg[DBG_MAX_BUFFER_SIZE];
size_t len;
TCHAR *p = DbgMsg;
va_list args;

va_start(args, format);
StringCchVPrintf(p, sizeof(DbgMsg) - 1, format, args);
StringCchLength(DbgMsg, sizeof(DbgMsg) - 1, &len);
p += len;
va_end(args);

*p++ = '\r';
*p++ = '\n';
*p = '\0';

OutputDebugString(DbgMsg);
}

#endif // DBG

留言

這個網誌中的熱門文章

Portable Python

我常常需要把Python寫的script帶到其他電腦使用,因此,一個免安裝,可攜帶的Python就顯得十分重要。最近看過了幾個可攜式Python的方案,下面這個PortablePython是我覺得最合我意的方案。因為它提供了大部分會用到的Python module及工具,甚至連wxPython及PyGame也有。同時也有好用的Python編輯器PyScripter。所有開發Python所需的開發工具都一應俱全了!把它放到隨身碟中,就不用到處幫人安裝Python了。 PortablePython : http://www.portablepython.com/

一個Python程式可幫檔名加上日期與時間

很多時候,我們希望能夠將檔案或是目錄名稱加上一個時間及日期,以便release。所以,我就寫了一個小小的程式來達到這個目的。我把這個程式貼上來,讓有興趣的人可以拿去使用。 -- #!/usr/bin/env python # -*- coding: ascii -*- """ Usage: cfgfn.py [filename or directory list] """ import sys import os import time import re import glob ro = re.compile(r'(?P<FN> .*)-[0-9]{8}-[0-9]{4}(?P<EXT> .*)') for fnl in sys.argv[1:]: for fn in glob.glob(fnl): mo = ro.match(fn) if mo: pre = mo.group('FN') ext = mo.group('EXT') else: pre, ext = os.path.splitext(fn) newFn = pre + time.strftime('-%Y%m%d-%H%M') + ext os.rename(fn, newFn) print 'Rename %s -> %s' % (fn, newFn)