EvoTalk

Posts Tagged ‘winapi

28 七月, 2006

Get Processes Memory Usage

Posted by: asd In: C++| Code Snippet| 程式設計

從 msdn 摘錄
Collecting Memory Usage Information For a Process
view plain

C++:

<div>

<pre>#include &lt;windows.h&gt;

#include &lt;stdio.h&gt;

#include "psapi.h"

 

void PrintMemoryInfo( DWORD processID )

{

    HANDLE hProcess;

    PROCESS_MEMORY_COUNTERS pmc;

 

    // Print the process identifier.

 

    printf( "\nProcess ID: %u\n", processID );

 

    // Print information about the memory usage of the process.

 

    hProcess = OpenProcess(  PROCESS_QUERY_INFORMATION

          [...]

Tags: ,

30 三月, 2006

CreateDir

Posted by: asd In: C++| Code Snippet| 程式設計

Create a directory structure
view plain

C++:

void CreateDir(char* Path)

{

char DirName[256];

char* p = Path;

char* q = DirName;

while(*p)

{

if (('\' == *p) || ('/' == *p))

{

if (':' != *(p-1))

{

CreateDirectory(DirName, NULL);

}

}

*q++ = *p++;

*q = '';

}

CreateDirectory(DirName, NULL);

}

Tags:

Deleting a directory structure
view plain

C++:

BOOL DeleteDirectory(const TCHAR* sPath) {

HANDLE hFind;  // file handle

WIN32_FIND_DATA FindFileData;

 

TCHAR DirPath[MAX_PATH];

TCHAR FileName[MAX_PATH];

 

_tcscpy(DirPath,sPath);

_tcscat(DirPath,"\*");    // searching all files

_tcscpy(FileName,sPath);

_tcscat(FileName,"\");

hFind = FindFirstFile(DirPath,&amp;FindFileData); // find the first file

if(hFind == INVALID_HANDLE_VALUE) return FALSE;

_tcscpy(DirPath,FileName);

bool bSearch = true;

while(bSearch) { // until we finds an entry

if(FindNextFile(hFind,&amp;FindFileData)) {

if(IsDots(FindFileData.cFileName)) continue;

_tcscat(FileName,FindFileData.cFileName);

if((FindFileData.dwFileAttributes &amp; FILE_ATTRIBUTE_DIRECTORY)) {

// we have found a directory, recurse

if(!DeleteDirectory(FileName)) {

FindClose(hFind);

return FALSE; [...]

Tags:

13 一月, 2006

Cannot Use .Net GetCurrentDirectory

Posted by: asd In: C++| Code Snippet| 程式設計

Windows .net form 程式若 include "vcclr.h",程式內呼叫
String *strp = System::IO::Directory::GetCurrentDirectory()
會產生
error C2039: 'GetCurrentDirectoryA' : 不是 'System::IO::Directory' 的成員
error C2660: 'GetCurrentDirectoryA' : 函式不使用 0 引數
等錯誤。只要在include vcclr.h 後面加上
#undef GetCurrentDirectory
就可以通過編譯。
原因就是 winapi 的
GetcurrentDirectory

System::IO::GetGurrentdirectory
名稱衝突,所以把 winapi 的先 undef 掉。

Tags: