#define WINVER _WIN32_WCE
#include <windows.h>
#include "tracer.h"
HINSTANCE g_hInstance = NULL;
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPWSTR lpCmdLine,
int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
UNREFERENCED_PARAMETER(nCmdShow);
// store the hInstance in global
g_hInstance = hInstance;
return 0;
}
#define WINVER _WIN32_WCE
#include <windows.h>
#include "tracer.h"
HINSTANCE g_hInstance = NULL;
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPWSTR lpCmdLine,
int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
UNREFERENCED_PARAMETER(nCmdShow);
// store the hInstance in global
g_hInstance = hInstance;
MEMORYSTATUS mem_status = { 0 };
GlobalMemoryStatus(&mem_status);
WCHAR szText[MAX_PATH] = { 0 };
_snwprintf(szText, MAX_PATH, L"Memory use: %d%", mem_status.dwMemoryLoad);
::MessageBox(NULL, szText, L"Test", MB_OK);
return 0;
}
#ifndef _TRACER_HEADER_
#define _TRACER_HEADER_
#include <stdlib.h>
#include <wchar.h>
inline void __cdecl Tracer(LPCWSTR lpszFormat, ...)
{
va_list args;
va_start(args, lpszFormat);
int nBuf = 0;
WCHAR szBuffer[1024];
ZeroMemory(szBuffer, 1024 * sizeof(WCHAR));
nBuf = _vsnwprintf(szBuffer+nBuf, 1024, lpszFormat, args);
static HANDLE hFile = INVALID_HANDLE_VALUE;
if (hFile == INVALID_HANDLE_VALUE)
{
WCHAR szFileName[MAX_PATH];
ZeroMemory(szFileName, MAX_PATH * sizeof(WCHAR));
::GetModuleFileName(GetModuleHandle(NULL), szFileName, MAX_PATH);
int nLength = lstrlen(szFileName);
while (nLength > 0)
{
nLength--;
if(szFileName[nLength] == TCHAR('.'))
break;
}
szFileName[nLength + 1] = 0;
wcsncat(szFileName, L"txt", MAX_PATH - 2);
hFile = ::CreateFileW(szFileName, GENERIC_WRITE | GENERIC_READ,
FILE_SHARE_READ, NULL, CREATE_ALWAYS, 0, NULL);
if (hFile != INVALID_HANDLE_VALUE)
{
DWORD nErr = GetLastError();
DWORD nWritten = 0;
SetFilePointer(hFile, 0, 0, FILE_END);
if (nErr != ERROR_ALREADY_EXISTS)
{
char szHeader[2] = { (char)0xFF, (char)0xFE };
::WriteFile(hFile, szHeader, 2, &nWritten, NULL);
}
::WriteFile(hFile, L" ", 1 * sizeof(WCHAR), &nWritten, NULL);
WCHAR sz[2] = { WCHAR(13), WCHAR(10) };
::WriteFile(hFile, sz, 4, &nWritten, NULL);
}
}
if (hFile != INVALID_HANDLE_VALUE)
{
DWORD nLength = wcslen(szBuffer) * sizeof(WCHAR);
DWORD nWritten = 0;
::WriteFile(hFile, szBuffer, nLength, &nWritten, NULL);
WCHAR sz[2] = { WCHAR(13), WCHAR(10) };
::WriteFile(hFile, sz, 4, &nWritten, NULL);
FlushFileBuffers(hFile);
}
#ifndef _WIN32_WCE
::OutputDebugStringW(szBuffer);
::OutputDebugStringW(L"\r\n");
#endif
va_end(args);
}
#endif
#define WINVER _WIN32_WCE
#include <windows.h>
#include "tracer.h"
HINSTANCE g_hInstance = NULL;
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPWSTR lpCmdLine,
int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
UNREFERENCED_PARAMETER(nCmdShow);
// store the hInstance in global
g_hInstance = hInstance;
MEMORYSTATUS mem_status = { 0 };
GlobalMemoryStatus(&mem_status);
Tracer(L"Total physical memory %d\n", mem_status.dwTotalPhys);
Tracer(L"Memory usage %d\n", mem_status.dwMemoryLoad);
LPVOID p = NULL;
DWORD nDelta = 1024 * 1024;
DWORD nSize = 0;
do
{
if (p != NULL)
{
free(p);
p = NULL;
}
nSize += nDelta;
p = malloc(nSize);
if (p != NULL)
Tracer(L"p= %p, %d bytes allocated\n", p, nSize);
} while(p != NULL);
if (p != NULL)
{
free(p);
p = NULL;
}
return 0;
}
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (2)
Commented:
You have my vote above.
Commented: