| #include "stdafx.h"
#include <malloc.h>
#include <windows.h>
int main(int argc, char* argv[])
{
char *szBuffer;
{
// *****************************************
// C++ の new と delete
// *****************************************
UINT uBufferSize;
uBufferSize = GetWindowsDirectory( NULL, 0 );
szBuffer = new char[uBufferSize+10]; // 確保
GetWindowsDirectory( szBuffer, uBufferSize );
printf( "%s\n", szBuffer );
delete [] szBuffer; // 解放
}
{
// *****************************************
// ランタイムライブラリ
// *****************************************
UINT uBufferSize;
uBufferSize = GetSystemDirectory( NULL, 0 );
szBuffer = (char *)malloc( (size_t)(uBufferSize+10) ); // 確保
GetSystemDirectory( szBuffer, uBufferSize );
printf( "%s\n", szBuffer );
free( (void *)szBuffer ); // 解放
}
{
// *****************************************
// Win32 API
// *****************************************
DWORD nBufferSize;
nBufferSize = GetCurrentDirectory( 0, NULL );
szBuffer = (char *)GlobalAlloc(GMEM_FIXED, nBufferSize+10); // 確保
GetCurrentDirectory( nBufferSize, szBuffer );
printf( "%s\n", szBuffer );
GlobalFree( (HGLOBAL)szBuffer ); // 解放
}
return 0;
}
| |