TEST.CXX
资源名称:MSDN_VC98.zip [点击查看]
上传用户:bangxh
上传日期:2007-01-31
资源大小:42235k
文件大小:2k
源码类别:
Windows编程
开发平台:
Visual C++
- //+---------------------------------------------------------------------------
- //
- // Microsoft Windows
- // Copyright 1992 - 1997 Microsoft Corporation.
- //
- // File: test.cxx
- //
- // Contents: test application for CMALSPY sample library
- //
- //----------------------------------------------------------------------------
- #include <windows.h>
- #include <ole2.h>
- #include "cmallspy.hxx"
- extern "C" void printf(CHAR*, ...);
- const UINT NALLOCATIONS = 573;
- int __cdecl main(int argc, char **argv)
- {
- HRESULT hr;
- LPMALLOCSPY pMallocSpy = new CMallocSpy();
- // Initialize
- CoInitialize(NULL);
- hr = CoRegisterMallocSpy(pMallocSpy);
- if (hr != S_OK)
- {
- printf("CoRegisterMallocSpy failed with %xn", hr);
- CoUninitialize();
- return 0;
- }
- printf("CoRegisterMallocSpy succeeded.n");
- // Allocate enoungh to force an expansion
- LPMALLOC pMalloc;
- void *allocs[NALLOCATIONS];
- ULONG j;
- if ((hr = CoGetMalloc(MEMCTX_TASK, &pMalloc)) != S_OK)
- {
- printf("CoGetMalloc failed with %xn", hr);
- CoUninitialize();
- return 0;
- }
- printf("CoGetMalloc succeeded.n");
- printf("Allocating %u memory blocks.n", NALLOCATIONS);
- for (j = 0; j < NALLOCATIONS; j++)
- {
- allocs[j] = pMalloc->Alloc(173);
- }
- // Now release everything
- printf("Releasing %u memory blocks.n", NALLOCATIONS);
- for (j = 0; j < NALLOCATIONS; j++)
- {
- pMalloc->Free(allocs[j]);
- allocs[j] = NULL;
- }
- printf("Test complete.n");
- // All done
- CoRevokeMallocSpy();
- CoUninitialize();
- return 0;
- }