将信息输出到afxDump对象,只在_DEBUG定义时输出,最多输出512个字符,格式化与printf类似) afxDump对象(afx.h, CDumpContext) (afxDump调用OutputDebugString 把信息输出到Debug窗口,继承CObject的类可以重载Dump方法格式化此类的Dump信息,输出时把afxDump作为Dump方法的参数) OutputDebugString(windows.h ) (TRACE, afxDump在使用MFC时使用,不使用MFC时可以用OutputDebugString,AfxOutputDebugString和OutputDebugString用法一样) 用法示例 DEBUG char strErr[512]; sprintf(strErr, "Count = %d, Description = %s\n", nCount, strDesc); OutputDebugString
其实在窗口模式下,windows提供了一个函数OutputDebugString,用于向开发环境的debug窗口输出信息,结合C语言的可变参数,就能实现跟printf一样的功能了,下面就是一个简单的采用 OutputDebugString封装的调试输出函数,用法跟printf一样: #include <windows.h> #include <stdarg.h> void OutputDbgInfo( va_start(arg, format); _vsntprintf(szData, sizeof(szData)-1, format, arg); va_end(arg); OutputDebugString 在console下,用这个函数格式化后直接用printf输出,在窗口程序下结合上面的OutputDebugString函数,也能方面的知道错误描述了,完整的函数如下: #include <windows.h (LPTSTR)lpDisplayBuf, LocalSize(lpDisplayBuf), TEXT("err code: %d, %s"), dwErrcode, lpMsgBuf); OutputDebugString
if (m_CreateService == NULL) { ::CloseServiceHandle(m_CreateService); //OutputDebugString bRet) { // OutputDebugString(TEXT("安装驱动失败")); } bRet = StartDriver(ServiceName bRet) { //OutputDebugString(TEXT("启动驱动失败")); return; } Sleep(3000); bRet) { //OutputDebugString(TEXT("停止驱动失败")); return; } Sleep(1000); bRet) { //OutputDebugString(TEXT("删除驱动失败")); return; } } int APIENTRY wWinMain
numByteWritten = 0; if(ReadProcessMemory(hProc, baseOffs,buf,si.dwPageSize,&numByteWritten) == FALSE) OutputDebugString (TEXT("bad\n")); //GetLastError()==ERROR_PARTIALLY_READ; numByteWritten == 0; else OutputDebugString( ReadProcessMemory(hProc, baseOffs,buf,si.dwPageSize,&numByteWritten) == FALSE) { assert(mbi.Protect & 0x100); OutputDebugString (mbi.Protect & 0x100)); OutputDebugString(TEXT("good\n")); } 版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。
, “Title”, MB_OK); 例子2:OutputDebugString的使用 windows API对OutputDebugString的定义如下: WINBASEAPI VOID WINAPI OutputDebugStringW #else #define OutputDebugString OutputDebugStringA #endif // ! UNICODE 当选则“使用Unicode字符集”时,调用函数OutputDebugString,实际使用的是OutputDebugStringW,OutputDebugStringW的入参的类型是LPCWSTR ,使用OutputDebugString时,字符串前需加L OutputDebugString(L“测试12345”); 当选则“使用多字节字符集”时,调用函数OutputDebugString,实际使用的是 OutputDebugStringA,OutputDebugStringA的入参类型是LPCSTR OutputDebugString(“测试12345”); 因此,“使用Unicode字符集”和“使用多字节字符集
IO,具体代码如下: DOWRD WINAPI CIOCPServer::_WorkerThreadProc(LPVOID lpParam) { #ifdef _DEBUG ::OutputDebugString lpol,WSA_INFINITE); if(dwTrans == -1) { #ifdef _DEBUG ::OutputDebugString } pThis->HandleIO(dwKey,pBuffer,dwTrans,nError); } #ifdef _DEBUG ::OutputDebugString dwTrans,int nError) { CIOCPContext *pContext = (CIOCPContext*)dwKey; #ifdef _DEBUG ::OutputDebugString //检查套接字是否已经打开 if(pContext->bClosing) { #ifdef _DEBUG ::OutputDebugString
//进行注入 if (NULL == hProHandle) { OutputDebugString 是我们自己写的 //wcscat(szBuf, TEXT("x64Test.dll"));//DLL这里就不写了,用我的吧,我会发上去的 OutputDebugString hThreadHandle) { OutputDebugString(TEXT("注入失败了")); return; } OutputDebugString(TEXT("注入了")); return;
m_EventImageShow); DeleteCriticalSection(&m_DealImageMutex); } 处理线程 void Thread_DealImage(LPVOID *lpParam) { OutputDebugString WAIT_OBJECT_0 == WaitForMultipleObjects(2,eventHandle,TRUE,0)) { _CRITICAL_LOCK(_critical_data2); OutputDebugString } ResetEvent(MultiThrDlg->m_EventDealImage); ResetEvent(MultiThrDlg->m_EventAllowReceiveImage); OutputDebugString WAIT_OBJECT_0 == WaitForSingleObject((MultiThrDlg->m_EventImageShow),0)) { _CRITICAL_LOCK(_critical_data2); OutputDebugString ; } } ResetEvent(MultiThrDlg->m_EventImageShow); ResetEvent(MultiThrDlg->m_EventAllowReceiveImage); OutputDebugString
nSBCode << " nPos:" << nPos << " GetPos():" << slider_audio_device_volume_.GetPos() << "\r\n"; OutputDebugString L"SB_THUMBPOSITION" << " nPos:" << nPos << " GetPos():" << slider_audio_device_volume_.GetPos() << "\r\n"; OutputDebugString L"SB_THUMBTRACK" << " nPos:" << nPos << " GetPos():" << slider_audio_device_volume_.GetPos() << "\r\n"; OutputDebugString
DWORD d = *(UNALIGNED PDWORD)test;//UNALIGNED在x86平台无效 if ((int)&d % sizeof(d) == 0) OutputDebugString (TEXT("***********对齐***********\n")); else OutputDebugString(TEXT("***********未对齐********
线程函数是一个全局函数,如下: DWORD WINAPI Thread1(LPVOID lpParam) { while(1) { OutputDebugString(“11111”); g_bExitThread) { OutputDebugString(“11111”); Sleep(10); } return 0; } 然后在需要它退出的时候把g_bExitThread pDlg->m_bExitThread) { OutputDebugString(“11111”); Sleep(10); } return 0; } 当有几个线程一起跑的时候 pDlg->m_bExitThread) { OutputDebugString(“11111”); pDlg->m_csForVec.Lock(); pDlg->m_vecTest.push_back pDlg->m_bExitThread2) { OutputDebugString(“222”); pDlg->m_csForVec.Lock(); pDlg->m_vecTest.push_back
MAX_PATH]; BOOL bRecord = FALSE; PROCESS_HEAP_ENTRY phe = {}; HeapLock(GetProcessHeap()); OutputDebugString i].m_pszSourceFile,g_pMemBlockList[i].m_iSourceLine,phe.lpData,phe.cbData); OutputDebugString T("未记录的内存块(Point=0x%08X,Size=%u)\n") ,phe.lpData,phe.cbData); //OutputDebugString (pszOutPutInfo); } } } HeapUnlock(GetProcessHeap()); OutputDebugString
OutputDebugString(“The Length of stack is %d/n”, nTop); //输出栈顶位置 for (int i = 1; i <= nTop; ++ i) { int t = lua_type(L, i); OutputDebugString(“%s:”, lua_typename switch(t) { case LUA_TNUMBER: OutputDebugString(“%f” , lua_tostring(L,i)); break; case LUA_TNIL: OutputDebugString (“Is NULL”); break; case LUA_TBOOLEAN: OutputDebugString
LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &luid)) { CloseHandle(hToken); OutputDebugString hToken, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), &oldtp, &dwSize)) { CloseHandle(hToken); OutputDebugString
g_ServiceStatus.dwCheckPoint = 0; if (SetServiceStatus (g_StatusHandle , &g_ServiceStatus) == FALSE) { OutputDebugString g_ServiceStatus.dwCheckPoint = 1; if (SetServiceStatus (g_StatusHandle, &g_ServiceStatus) == FALSE) { OutputDebugString g_ServiceStatus.dwCheckPoint = 0; if (SetServiceStatus (g_StatusHandle, &g_ServiceStatus) == FALSE) { OutputDebugString g_ServiceStatus.dwCheckPoint = 3; if (SetServiceStatus (g_StatusHandle, &g_ServiceStatus) == FALSE) { OutputDebugString ; if (SetServiceStatus (g_StatusHandle, &g_ServiceStatus) == FALSE) { OutputDebugString
]; swprintf_s(buffer, length, CastToWideChar(format), CastToWideChar(parameter)); OutputDebugString wchar_t *buffer = new wchar_t[length]; swprintf_s(buffer, length, format, parameter); OutputDebugString
LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &luid)) { CloseHandle(hToken); OutputDebugString hToken, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), &oldtp, &dwSize)) { CloseHandle(hToken); OutputDebugString
for (int i = 0; i < 100; ++i) { AcquireSRWLockExclusive(&g_rw); //写 OutputDebugString { for (int i = 0; i < 100; ++i) { AcquireSRWLockShared(&g_rw); //读 OutputDebugString
可以捕获程序中由 TRACE()和 OutputDebugString()输出的信息。 说的具体一点,在程序中使用如下函数: 1)、 OutputDebugString 或者在MFC中使用TRACE 2)、内核模式中使用Out_Debug_String,DbgPrint ,_Debug_Printf_Service
str); str = ""; str.Format(TEXT("类的大小 = %d \r\n"),pCurClass->m_nObjectSize); OutputDebugString (str); str = ""; str.Format(TEXT("类的编号%d \r\n"), pCurClass->m_wSchema); OutputDebugString str); str = ""; str.Format(TEXT("类的父类指针 %p \r\n"), pCurClass->m_pBaseClass); OutputDebugString str.Format(TEXT("类的父类名称 %s \r\n"), pCurClass->m_pBaseClass->m_lpszClassName); OutputDebugString str); } str = TEXT("--------------------------------\r\n"); OutputDebugString