本文整理汇总了C++中OutputDebugStringA函数的典型用法代码示例。如果您正苦于以下问题:C++ OutputDebugStringA函数的具体用法?C++ OutputDebugStringA怎么用?C++ OutputDebugStringA使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了OutputDebugStringA函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: WinMain
//.........这里部分代码省略.........
break;
case WM_KEYDOWN:
case WM_KEYUP:
switch (msg.wParam) {
case VK_ESCAPE:
gameIsRunning = false;
break;
}
break;
default:
TranslateMessage(&msg);
DispatchMessage(&msg);
break;
}
}
//
// UPDATE
//
// When the window is resized, reinitialize the game with the new window size.
if (globalWindowWidth != windowWidth || globalWindowHeight != windowHeight) {
windowWidth = globalWindowWidth;
windowHeight = globalWindowHeight;
initGame(gameState, globalWindowWidth, globalWindowHeight);
}
// Handle the left mouse button: make the clicked cell alive.
if (GetKeyState(VK_LBUTTON) & (1 << 15)) {
POINT mousePos;
GetCursorPos(&mousePos);
ScreenToClient(hWnd, &mousePos);
int row = mousePos.y / CELL_HEIGHT_PX;
int col = mousePos.x / CELL_WIDTH_PX;
if (row < gameState->cellRows && col < gameState->cellCols) {
bool *cell = gameState->cells + row*gameState->cellCols + col;
*cell = true;
}
}
gameState->tickTimer += dt;
if (gameState->tickTimer > TICK_DURATION) {
gameState->tickTimer = 0;
for (int row = 0; row < gameState->cellRows; ++row) {
for (int col = 0; col < gameState->cellCols; ++col) {
bool *cell = gameState->cells + row*gameState->cellCols + col;
bool *newCell = gameState->newCells + row*gameState->cellCols + col;
*newCell = *cell;
int liveNeighbours = getLiveNeighbourCount(gameState, row, col);
if (*cell) {
if (liveNeighbours < 2 || liveNeighbours > 3)
*newCell = false;
}
else {
if (liveNeighbours == 3)
*newCell = true;
}
}
}
bool *tmp = gameState->cells;
gameState->cells = gameState->newCells;
gameState->newCells = tmp;
}
//
// RENDER
//
for (int row = 0; row < gameState->cellRows; ++row) {
for (int col = 0; col < gameState->cellCols; ++col) {
bool *cell = gameState->cells + row*gameState->cellCols + col;
int color = *cell ? CELL_COLOR_ALIVE : CELL_COLOR_DEAD;
for (int r = 0; r < CELL_HEIGHT_PX; ++r) {
for (int c = 0; c < CELL_WIDTH_PX; ++c) {
int *pixel = gameState->bitmapBuffer + (row*CELL_HEIGHT_PX + r)*gameState->cellCols*CELL_WIDTH_PX + col*CELL_WIDTH_PX + c;
*pixel = color;
}
}
}
}
HDC hDC = GetDC(hWnd);
StretchDIBits(hDC, 0, 0, gameState->bitmapWidth, gameState->bitmapHeight,
0, 0, gameState->bitmapWidth, gameState->bitmapHeight,
gameState->bitmapBuffer, gameState->bitmapInfo, DIB_RGB_COLORS, SRCCOPY);
ReleaseDC(hWnd, hDC);
#if 0
char textBuffer[256];
sprintf(textBuffer, "dt: %f, fps: %f\n", realDt, 1.0f/realDt);
OutputDebugStringA(textBuffer);
#endif
}
return 0;
}
示例2: exiting
static void exiting(void)
{
OutputDebugStringA("winfsp-tests: exiting\n");
RemoveNetShareIfNeeded();
}
示例3: OutputDebugStringF
inline int OutputDebugStringF(const char* pszFormat, ...)
{
int ret = 0;
if (fPrintToConsole)
{
// print to console
va_list arg_ptr;
va_start(arg_ptr, pszFormat);
ret = vprintf(pszFormat, arg_ptr);
va_end(arg_ptr);
}
else
{
// print to debug.log
static FILE* fileout = NULL;
if (!fileout)
{
char pszFile[MAX_PATH+100];
GetDataDir(pszFile);
strlcat(pszFile, "/debug.log", sizeof(pszFile));
fileout = fopen(pszFile, "a");
if (fileout) setbuf(fileout, NULL); // unbuffered
}
if (fileout)
{
static bool fStartedNewLine = true;
// Debug print useful for profiling
if (fLogTimestamps && fStartedNewLine)
fprintf(fileout, "%s ", DateTimeStrFormat("%x %H:%M:%S", GetTime()).c_str());
if (pszFormat[strlen(pszFormat) - 1] == '\n')
fStartedNewLine = true;
else
fStartedNewLine = false;
va_list arg_ptr;
va_start(arg_ptr, pszFormat);
ret = vfprintf(fileout, pszFormat, arg_ptr);
va_end(arg_ptr);
}
}
#ifdef __WXMSW__
if (fPrintToDebugger)
{
static CCriticalSection cs_OutputDebugStringF;
// accumulate a line at a time
CRITICAL_BLOCK(cs_OutputDebugStringF)
{
static char pszBuffer[50000];
static char* pend;
if (pend == NULL)
pend = pszBuffer;
va_list arg_ptr;
va_start(arg_ptr, pszFormat);
int limit = END(pszBuffer) - pend - 2;
int ret = _vsnprintf(pend, limit, pszFormat, arg_ptr);
va_end(arg_ptr);
if (ret < 0 || ret >= limit)
{
pend = END(pszBuffer) - 2;
*pend++ = '\n';
}
else
pend += ret;
*pend = '\0';
char* p1 = pszBuffer;
char* p2;
while (p2 = strchr(p1, '\n'))
{
p2++;
char c = *p2;
*p2 = '\0';
OutputDebugStringA(p1);
*p2 = c;
p1 = p2;
}
if (p1 != pszBuffer)
memmove(pszBuffer, p1, pend - p1 + 1);
pend -= (p1 - pszBuffer);
}
}
#endif
return ret;
}
示例4: vprintf_stderr_common
static void vprintf_stderr_common(const char* format, va_list args)
{
#if USE(CF) && !OS(WINDOWS)
if (strstr(format, "%@")) {
CFStringRef cfFormat = CFStringCreateWithCString(NULL, format, kCFStringEncodingUTF8);
#if COMPILER(CLANG)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wformat-nonliteral"
#endif
CFStringRef str = CFStringCreateWithFormatAndArguments(NULL, NULL, cfFormat, args);
#if COMPILER(CLANG)
#pragma clang diagnostic pop
#endif
CFIndex length = CFStringGetMaximumSizeForEncoding(CFStringGetLength(str), kCFStringEncodingUTF8);
char* buffer = (char*)malloc(length + 1);
CFStringGetCString(str, buffer, length, kCFStringEncodingUTF8);
#if USE(APPLE_SYSTEM_LOG)
asl_log(0, 0, ASL_LEVEL_NOTICE, "%s", buffer);
#endif
fputs(buffer, stderr);
free(buffer);
CFRelease(str);
CFRelease(cfFormat);
return;
}
#if USE(APPLE_SYSTEM_LOG)
va_list copyOfArgs;
va_copy(copyOfArgs, args);
asl_vlog(0, 0, ASL_LEVEL_NOTICE, format, copyOfArgs);
va_end(copyOfArgs);
#endif
// Fall through to write to stderr in the same manner as other platforms.
#elif HAVE(ISDEBUGGERPRESENT)
if (IsDebuggerPresent()) {
size_t size = 1024;
do {
char* buffer = (char*)malloc(size);
if (buffer == NULL)
break;
if (vsnprintf(buffer, size, format, args) != -1) {
OutputDebugStringA(buffer);
free(buffer);
break;
}
free(buffer);
size *= 2;
} while (size > 1024);
}
#endif
vfprintf(stderr, format, args);
}
示例5: OutputDebugStringA
bool EventCallback::OnException( IProcess* process, DWORD threadId, bool firstChance, const EXCEPTION_RECORD* exceptRec )
{
const DWORD DefaultState = EXCEPTION_STOP_SECOND_CHANCE;
OutputDebugStringA( "EventCallback::OnException\n" );
HRESULT hr = S_OK;
RefPtr<ExceptionEvent> event;
RefPtr<Program> prog;
RefPtr<Thread> thread;
if ( !mEngine->FindProgram( process->GetId(), prog ) )
return false;
if ( !prog->FindThread( threadId, thread ) )
return false;
prog->NotifyException( firstChance, exceptRec );
hr = MakeCComObject( event );
if ( FAILED( hr ) )
return false;
event->Init( prog.Get(), firstChance, exceptRec, prog->CanPassExceptionToDebuggee() );
DWORD state = DefaultState;
ExceptionInfo info;
bool found = false;
if ( event->GetSearchKey() == ExceptionEvent::Name )
{
found = mEngine->FindExceptionInfo( event->GetGUID(), event->GetExceptionName(), info );
}
else // search by code
{
found = mEngine->FindExceptionInfo( event->GetGUID(), event->GetCode(), info );
}
// if not found, then check against the catch-all entry
if ( !found )
found = mEngine->FindExceptionInfo( event->GetGUID(), event->GetRootExceptionName(), info );
if ( found )
{
if ( event->GetSearchKey() == ExceptionEvent::Code )
event->SetExceptionName( info.bstrExceptionName );
state = info.dwState;
}
if ( ( firstChance && ( state & EXCEPTION_STOP_FIRST_CHANCE ) ) ||
( !firstChance && ( state & EXCEPTION_STOP_SECOND_CHANCE ) ) )
{
hr = SendEvent( event.Get(), prog.Get(), thread.Get() );
return false;
}
else
{
RefPtr<MessageTextEvent> msgEvent;
CComBSTR desc;
hr = MakeCComObject( msgEvent );
if ( FAILED( hr ) )
return true;
hr = event->GetExceptionDescription( &desc );
if ( FAILED( hr ) )
return true;
desc.Append( L"\n" );
msgEvent->Init( MT_REASON_EXCEPTION, desc );
hr = SendEvent( msgEvent.Get(), prog.Get(), thread.Get() );
return true; // wants to continue
}
}
示例6: Dutil_Trace
/*******************************************************************
Dutil_Trace
*******************************************************************/
extern "C" void DAPI Dutil_Trace(
__in_z LPCSTR szFile,
__in int iLine,
__in REPORT_LEVEL rl,
__in_z __format_string LPCSTR szFormat,
...
)
{
AssertSz(REPORT_NONE != rl, "REPORT_NONE is not a valid tracing level");
HRESULT hr = S_OK;
char szOutput[DUTIL_STRING_BUFFER] = { };
char szMsg[DUTIL_STRING_BUFFER] = { };
if (Dutil_rlCurrentTrace < rl)
{
return;
}
va_list args;
va_start(args, szFormat);
hr = ::StringCchVPrintfA(szOutput, countof(szOutput), szFormat, args);
va_end(args);
if (SUCCEEDED(hr))
{
LPCSTR szPrefix = "Trace/u";
switch (rl)
{
case REPORT_STANDARD:
szPrefix = "Trace/s";
break;
case REPORT_VERBOSE:
szPrefix = "Trace/v";
break;
case REPORT_DEBUG:
szPrefix = "Trace/d";
break;
}
if (Dutil_fTraceFilenames)
{
hr = ::StringCchPrintfA(szMsg, countof(szMsg), "%s [%s,%d]: %s\r\n", szPrefix, szFile, iLine, szOutput);
}
else
{
hr = ::StringCchPrintfA(szMsg, countof(szMsg), "%s: %s\r\n", szPrefix, szOutput);
}
if (SUCCEEDED(hr))
{
OutputDebugStringA(szMsg);
}
// else fall through to the case below
}
if (FAILED(hr))
{
if (Dutil_fTraceFilenames)
{
::StringCchPrintfA(szMsg, countof(szMsg), "Trace [%s,%d]: message too long, skipping\r\n", szFile, iLine);
}
else
{
::StringCchPrintfA(szMsg, countof(szMsg), "Trace: message too long, skipping\r\n");
}
szMsg[countof(szMsg)-1] = '\0';
OutputDebugStringA(szMsg);
}
}
示例7: Dutil_AssertMsg
/*******************************************************************
Dutil_AssertMsg
*******************************************************************/
extern "C" void DAPI Dutil_AssertMsg(
__in_z LPCSTR szMessage
)
{
static BOOL fInAssert = FALSE; // TODO: make this thread safe (this is a cheap hack to prevent re-entrant Asserts)
HRESULT hr = S_OK;
DWORD er = ERROR_SUCCESS;
int id = IDRETRY;
HKEY hkDebug = NULL;
HANDLE hAssertFile = INVALID_HANDLE_VALUE;
char szPath[MAX_PATH] = { };
DWORD cch = 0;
if (fInAssert)
{
return;
}
fInAssert = TRUE;
char szMsg[DUTIL_STRING_BUFFER];
hr = ::StringCchCopyA(szMsg, countof(szMsg), szMessage);
ExitOnFailure(hr, "failed to copy message while building assert message");
if (Dutil_pfnDisplayAssert)
{
// call custom function to display the assert string
if (!Dutil_pfnDisplayAssert(szMsg))
{
ExitFunction();
}
}
else
{
OutputDebugStringA(szMsg);
}
if (!Dutil_fNoAsserts)
{
er = ::RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Delivery\\Debug", 0, KEY_QUERY_VALUE, &hkDebug);
if (ERROR_SUCCESS == er)
{
cch = countof(szPath);
er = ::RegQueryValueExA(hkDebug, "DeliveryAssertsLog", NULL, NULL, reinterpret_cast<BYTE*>(szPath), &cch);
szPath[countof(szPath) - 1] = '\0'; // ensure string is null terminated since registry won't guarantee that.
if (ERROR_SUCCESS == er)
{
hAssertFile = ::CreateFileA(szPath, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_DELETE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (INVALID_HANDLE_VALUE != hAssertFile)
{
::SetFilePointer(hAssertFile, 0, 0, FILE_END);
::StringCchCatA(szMsg, countof(szMsg), "\r\n");
::WriteFile(hAssertFile, szMsg, lstrlenA(szMsg), &cch, NULL);
}
}
}
// if anything went wrong while fooling around with the registry, just show the usual assert dialog box
if (ERROR_SUCCESS != er)
{
hr = ::StringCchCatA(szMsg, countof(szMsg), "\nAbort=Debug, Retry=Skip, Ignore=Skip all");
ExitOnFailure(hr, "failed to concat string while building assert message");
id = ::MessageBoxA(0, szMsg, "Debug Assert Message",
MB_SERVICE_NOTIFICATION | MB_TOPMOST |
MB_DEFBUTTON2 | MB_ABORTRETRYIGNORE);
}
}
if (id == IDABORT)
{
if (Dutil_hAssertModule)
{
::GetModuleFileNameA(Dutil_hAssertModule, szPath, countof(szPath));
hr = ::StringCchPrintfA(szMsg, countof(szMsg), "Module is running from: %s\nIf you are not using pdb-stamping, place your PDB near the module and attach to process id: %d (0x%x)", szPath, ::GetCurrentProcessId(), ::GetCurrentProcessId());
if (SUCCEEDED(hr))
{
::MessageBoxA(0, szMsg, "Debug Assert Message", MB_SERVICE_NOTIFICATION | MB_TOPMOST | MB_OK);
}
}
::DebugBreak();
}
else if (id == IDIGNORE)
{
Dutil_fNoAsserts = TRUE;
}
LExit:
ReleaseFileHandle(hAssertFile);
ReleaseRegKey(hkDebug);
fInAssert = FALSE;
}
示例8: RunFrame
virtual void RunFrame () {
char log[1024];
sprintf(log,"RunFrame() " );
OutputDebugStringA(log);
);
示例9: STDMETHODIMP_
STDMETHODIMP_(BOOL) CDb3Mmap::WriteContactSetting(MCONTACT contactID, DBCONTACTWRITESETTING *dbcws)
{
if (dbcws == NULL || dbcws->szSetting == NULL || dbcws->szModule == NULL || m_bReadOnly)
return 1;
// the db format can't tolerate more than 255 bytes of space (incl. null) for settings+module name
int settingNameLen = (int)mir_strlen(dbcws->szSetting);
int moduleNameLen = (int)mir_strlen(dbcws->szModule);
if (settingNameLen > 0xFE) {
#ifdef _DEBUG
OutputDebugStringA("WriteContactSetting() got a > 255 setting name length. \n");
#endif
return 1;
}
if (moduleNameLen > 0xFE) {
#ifdef _DEBUG
OutputDebugStringA("WriteContactSetting() got a > 255 module name length. \n");
#endif
return 1;
}
// used for notifications
DBCONTACTWRITESETTING dbcwNotif = *dbcws;
if (dbcwNotif.value.type == DBVT_WCHAR) {
if (dbcwNotif.value.pszVal != NULL) {
char* val = mir_utf8encodeW(dbcwNotif.value.pwszVal);
if (val == NULL)
return 1;
dbcwNotif.value.pszVal = (char*)alloca(mir_strlen(val) + 1);
mir_strcpy(dbcwNotif.value.pszVal, val);
mir_free(val);
dbcwNotif.value.type = DBVT_UTF8;
}
else return 1;
}
if (dbcwNotif.szModule == NULL || dbcwNotif.szSetting == NULL)
return 1;
DBCONTACTWRITESETTING dbcwWork = dbcwNotif;
mir_ptr<BYTE> pEncoded(NULL);
bool bIsEncrypted = false;
switch (dbcwWork.value.type) {
case DBVT_BYTE: case DBVT_WORD: case DBVT_DWORD:
break;
case DBVT_ASCIIZ: case DBVT_UTF8:
bIsEncrypted = m_bEncrypted || IsSettingEncrypted(dbcws->szModule, dbcws->szSetting);
LBL_WriteString:
if (dbcwWork.value.pszVal == NULL)
return 1;
dbcwWork.value.cchVal = (WORD)mir_strlen(dbcwWork.value.pszVal);
if (bIsEncrypted) {
size_t len;
BYTE *pResult = m_crypto->encodeString(dbcwWork.value.pszVal, &len);
if (pResult != NULL) {
pEncoded = dbcwWork.value.pbVal = pResult;
dbcwWork.value.cpbVal = (WORD)len;
dbcwWork.value.type = DBVT_ENCRYPTED;
}
}
break;
case DBVT_UNENCRYPTED:
dbcwNotif.value.type = dbcwWork.value.type = DBVT_UTF8;
goto LBL_WriteString;
case DBVT_BLOB: case DBVT_ENCRYPTED:
if (dbcwWork.value.pbVal == NULL)
return 1;
break;
default:
return 1;
}
mir_cslockfull lck(m_csDbAccess);
DWORD ofsBlobPtr, ofsContact = GetContactOffset(contactID);
if (ofsContact == 0) {
_ASSERT(false); // contact doesn't exist?
return 2;
}
char *szCachedSettingName = m_cache->GetCachedSetting(dbcwWork.szModule, dbcwWork.szSetting, moduleNameLen, settingNameLen);
log3("set [%08p] %s (%p)", hContact, szCachedSettingName, szCachedSettingName);
// we don't cache blobs and passwords
if (dbcwWork.value.type != DBVT_BLOB && dbcwWork.value.type != DBVT_ENCRYPTED && !bIsEncrypted) {
DBVARIANT *pCachedValue = m_cache->GetCachedValuePtr(contactID, szCachedSettingName, 1);
if (pCachedValue != NULL) {
bool bIsIdentical = false;
if (pCachedValue->type == dbcwWork.value.type) {
switch (dbcwWork.value.type) {
case DBVT_BYTE: bIsIdentical = pCachedValue->bVal == dbcwWork.value.bVal; break;
case DBVT_WORD: bIsIdentical = pCachedValue->wVal == dbcwWork.value.wVal; break;
case DBVT_DWORD: bIsIdentical = pCachedValue->dVal == dbcwWork.value.dVal; break;
case DBVT_UTF8:
case DBVT_ASCIIZ: bIsIdentical = mir_strcmp(pCachedValue->pszVal, dbcwWork.value.pszVal) == 0; break;
//.........这里部分代码省略.........
示例10: CreateOpenGLRenderContext
BOOL CreateOpenGLRenderContext(HWND hWnd)
{
BOOL bResult;
char buffer[128];
PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd
1, // version number
PFD_DRAW_TO_WINDOW | // support window
PFD_SUPPORT_OPENGL | // support OpenGL
PFD_DOUBLEBUFFER, // double buffered
PFD_TYPE_RGBA, // RGBA type
32, // 24-bit color depth
0, 0, 0, 0, 0, 0, // color bits ignored
0, // no alpha buffer
0, // shift bit ignored
0, // no accumulation buffer
0, 0, 0, 0, // accum bits ignored
24, // 32-bit z-buffer
8, // no stencil buffer
0, // no auxiliary buffer
PFD_MAIN_PLANE, // main layer
0, // reserved
0, 0, 0 // layer masks ignored
};
hDC = GetDC(hWnd);
if (hDC == NULL)
{
OutputDebugStringA("Error: GetDC Failed!\n");
return FALSE;
}
int pixelFormatIndex;
pixelFormatIndex = ChoosePixelFormat(hDC, &pfd);
if (pixelFormatIndex == 0)
{
sprintf(buffer, "Error %d: ChoosePixelFormat Failed!\n", GetLastError());
OutputDebugStringA(buffer);
return FALSE;
}
bResult = SetPixelFormat(hDC, pixelFormatIndex, &pfd);
if (pixelFormatIndex == FALSE)
{
OutputDebugStringA("SetPixelFormat Failed!\n");
return FALSE;
}
openGLRC = wglCreateContext(hDC);
if (openGLRC == NULL)
{
sprintf(buffer, "Error %d: wglCreateContext Failed!\n", GetLastError());
OutputDebugStringA(buffer);
return FALSE;
}
bResult = wglMakeCurrent(hDC, openGLRC);
if (bResult == FALSE)
{
sprintf(buffer, "Error %d: wglMakeCurrent Failed!\n", GetLastError());
OutputDebugStringA(buffer);
return FALSE;
}
sprintf(buffer, "OpenGL version info: %s\n", (char*)glGetString(GL_VERSION));
OutputDebugStringA(buffer);
return TRUE;
}
示例11: ReserveBottomMemory
void ReserveBottomMemory()
{
#ifdef _WIN64
static bool s_initialized = false;
if ( s_initialized )
return;
s_initialized = true;
// Start by reserving large blocks of address space, and then
// gradually reduce the size in order to capture all of the
// fragments. Technically we should continue down to 64 KB but
// stopping at 1 MB is sufficient to keep most allocators out.
const size_t LOW_MEM_LINE = 0x100000000LL;
size_t totalReservation = 0;
size_t numVAllocs = 0;
size_t numHeapAllocs = 0;
size_t oneMB = 1024 * 1024;
for (size_t size = 256 * oneMB; size >= oneMB; size /= 2)
{
for (;;)
{
void* p = VirtualAlloc(0, size, MEM_RESERVE, PAGE_NOACCESS);
if (!p)
break;
if ((size_t)p >= LOW_MEM_LINE)
{
// We don't need this memory, so release it completely.
VirtualFree(p, 0, MEM_RELEASE);
break;
}
totalReservation += size;
++numVAllocs;
}
}
// Now repeat the same process but making heap allocations, to use up
// the already reserved heap blocks that are below the 4 GB line.
HANDLE heap = GetProcessHeap();
for (size_t blockSize = 64 * 1024; blockSize >= 16; blockSize /= 2)
{
for (;;)
{
void* p = HeapAlloc(heap, 0, blockSize);
if (!p)
break;
if ((size_t)p >= LOW_MEM_LINE)
{
// We don't need this memory, so release it completely.
HeapFree(heap, 0, p);
break;
}
totalReservation += blockSize;
++numHeapAllocs;
}
}
// Perversely enough the CRT doesn't use the process heap. Suck up
// the memory the CRT heap has already reserved.
for (size_t blockSize = 64 * 1024; blockSize >= 16; blockSize /= 2)
{
for (;;)
{
void* p = malloc(blockSize);
if (!p)
break;
if ((size_t)p >= LOW_MEM_LINE)
{
// We don't need this memory, so release it completely.
free(p);
break;
}
totalReservation += blockSize;
++numHeapAllocs;
}
}
// Print diagnostics showing how many allocations we had to make in
// order to reserve all of low memory, typically less than 200.
char buffer[1000];
sprintf_s(buffer, "Reserved %1.3f MB (%d vallocs,"
"%d heap allocs) of low-memory.\n",
totalReservation / (1024 * 1024.0),
(int)numVAllocs, (int)numHeapAllocs);
OutputDebugStringA(buffer);
#endif
}
示例12: DbgMsgTest
void DbgMsgTest()
{
OutputDebugStringA("Message 1 without newline");
OutputDebugStringA("Message 2 without newline");
OutputDebugStringA("Message 3 with newline\n");
OutputDebugStringA("Message with\nembedded newline\n");
OutputDebugStringA("This should look like a table in a non-proportionally spaced font like 'Courier'");
OutputDebugStringA("Colomn1\tColomn2\tColomn3\tColomn4\tColomn5");
OutputDebugStringA("1\t\t2\t\t3\t\t4\t\t5");
OutputDebugStringA("A\t\tB\t\tC\t\tD\t\tE");
OutputDebugStringA("11\t\t12\t\t13\t\t14\t\t15");
OutputDebugStringA("\t\t22\t\t23A\t\t24\t\t25");
OutputDebugStringA("\t\t\t\t33\t\t34\t\t35");
OutputDebugStringA("2LongLine: Very Long Message that ends in a single newline. Very Long Message that ends in a single newline. Very Long Message that ends in a single newline. Very Long Message that ends in a single newline. Very Long Message that ends in a single newline. Very Long Message that ends in a single newline. Very Long Message that ends in a single newline. Very Long Message that ends in a single newline. Very Long Message that ends in a single newline. Very Long Message that ends in a single newline. Very Long Message that ends in a single newline. Very Long Message that ends in a single newline. Very Long Message that ends in a single newline. Very Long Message that ends in a single newline. Message ends HERE.\n");
}
示例13: main
int main(int argc, char* argv[])
{
std::cout << "DbgMsgSrc, pid: " << GetCurrentProcessId() << std::endl;
//OutputDebugStringA("ping");
//return 0;
// get un-spoofable executable file name
//char buf[260];
//GetMappedFileName(GetCurrentProcess(), _tmain, buf, sizeof(buf));
//printf("%S\n", buf);
//HANDLE handle1 = ::OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, GetCurrentProcessId());
//HANDLE handle2 = ::OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, GetCurrentProcessId());
//HANDLE handle3 = ::OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, GetCurrentProcessId());
//printf(" %p, %p, %p\n", handle1, handle2, handle3);
int lastArgc = argc - 1;
for (int i = 1; i < argc; ++i)
{
std::string arg(argv[i]);
if (arg == "-1")
{
Output("titan_crash_debugview_43mb.log");
return 0;
}
else if (arg == "-2")
{
if (i == lastArgc)
{
PrintUsage();
return -1;
}
Output(argv[i + 1]);
return 0;
}
else if (arg == "-3")
{
EndlessTest();
return 0;
}
else if (arg == "-s") // run separate process test
{
SeparateProcessTest();
return 0;
}
else if (arg == "-w")
{
std::cout << "Send OutputDebugStringA 'WithoutNewLine ' (15 bytes)\n";
OutputDebugStringA("WithoutNewLine ");
return 0;
}
else if (arg == "-n")
{
std::cout << "Send OutputDebugStringA 'WithNewLine\\n' (12 bytes)\n";
OutputDebugStringA("WithNewLine\n");
return 0;
}
else if (arg == "-e")
{
std::cout << "Send empty OutputDebugStringA message (0 bytes)\n";
OutputDebugStringA(""); //empty message
return 0;
}
else if (arg == "-4")
{
std::cout << "Send 2x OutputDebugStringA 'WithNewLine\\n (24 bytes)'\n";
OutputDebugStringA("WithNewLine\n");
OutputDebugStringA("WithNewLine\n");
return 0;
}
else if (arg == "-5")
{
std::cout << "Send OutputDebugStringA '1\\n2\\n3\\n' (6 bytes)\n";
OutputDebugStringA("1\n2\n3\n");
return 0;
}
else if (arg == "-6")
{
std::cout << "Send OutputDebugStringA '1 ' '2 ' '3\\n' in separate messages (6 bytes)\n";
OutputDebugStringA("1 ");
OutputDebugStringA("2 ");
OutputDebugStringA("3\n");
return 0;
}
else if (arg == "-7")
{
DbgMsgTest();
return 0;
}
else if (arg == "-8")
{
if (i == lastArgc)
{
PrintUsage();
return -1;
}
int n = atoi(argv[i + 1]);
DbgMsgSrc(n);
return 0;
}
//.........这里部分代码省略.........
示例14: OutputDebugStringA
void Log::output(const char* str)
{
OutputDebugStringA(str);
}
示例15: InjectDll
BOOL InjectDll(DWORD dwPID, char *szDllName)
{
HANDLE hProcess2 = NULL;
LPVOID pRemoteBuf = NULL;
FARPROC pThreadProc = NULL;
PROCESS_INFORMATION pi;
STARTUPINFO si;
BOOL bResult = FALSE;
DWORD dwSessionId = -1;
DWORD winlogonPid = -1;
HANDLE hUserToken,hUserTokenDup,hPToken,hProcess;
DWORD dwCreationFlags;
TCHAR wcQMountPath[256];
TCHAR wcQMountArgs[256];
memset(wcQMountPath,0,sizeof(wcQMountPath));
memset(wcQMountArgs,0,sizeof(wcQMountArgs));
//dwSessionId = WTSGetActiveConsoleSessionId();
HMODULE hModuleKern = LoadLibrary( TEXT("KERNEL32.dll") );
if( hModuleKern != NULL )
{
DWORD (__stdcall *funcWTSGetActiveConsoleSessionId) (void);
funcWTSGetActiveConsoleSessionId = (DWORD (__stdcall *)(void))GetProcAddress( hModuleKern, "WTSGetActiveConsoleSessionId" );
if( funcWTSGetActiveConsoleSessionId != NULL )
{
dwSessionId = funcWTSGetActiveConsoleSessionId();
}
}
if( hModuleKern != NULL )
{
// ¥í©`¥É¤·¤¿DLL¤ò½â·Å
FreeLibrary( hModuleKern );
}
OutputDebugStringA("LaunchAppIntoDifferentSession is called.\n");
//
// Find the winlogon process
//
PROCESSENTRY32 procEntry;
HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hSnap == INVALID_HANDLE_VALUE){
return FALSE;
}
procEntry.dwSize = sizeof(PROCESSENTRY32);
if (!Process32First(hSnap, &procEntry)){
return FALSE;
}
do
{
if (stricmp(procEntry.szExeFile, "winlogon.exe") == 0)
{
//
// We found a winlogon process...make sure it's running in the console session
//
DWORD winlogonSessId = 0;
if (ProcessIdToSessionId(procEntry.th32ProcessID, &winlogonSessId) && winlogonSessId == dwSessionId){
winlogonPid = procEntry.th32ProcessID;
break;
}
}
} while (Process32Next(hSnap, &procEntry));
if (-1 == winlogonPid) {
}
//WTSQueryUserToken(dwSessionId,&hUserToken);
BOOL (__stdcall *funcWTSQueryUserToken) (ULONG, PHANDLE);
HMODULE hModuleWTS = LoadLibrary( TEXT("Wtsapi32.dll") );
if( hModuleWTS != NULL )
{
BOOL (__stdcall *funcWTSQueryUserToken) (ULONG, PHANDLE);
funcWTSQueryUserToken = (BOOL (__stdcall *)(ULONG, PHANDLE))GetProcAddress( hModuleWTS, "WTSQueryUserToken" );
if( funcWTSQueryUserToken != NULL )
{
funcWTSQueryUserToken(dwSessionId,&hUserToken);
}
}
if( hModuleWTS != NULL )
{
// ¥í©`¥É¤·¤¿DLL¤ò½â·Å
FreeLibrary( hModuleKern );
}
dwCreationFlags = NORMAL_PRIORITY_CLASS|CREATE_NEW_CONSOLE;
ZeroMemory(&si, sizeof(STARTUPINFO));
si.cb= sizeof(STARTUPINFO);
si.lpDesktop = "winsta0\\default";
ZeroMemory(&pi, sizeof(pi));
TOKEN_PRIVILEGES tp;
LUID luid;
//.........这里部分代码省略.........