#include <Windows.h>
#include <cstdio>
#include <io.h>
#include <fcntl.h>
void OpenConsole()
{
int hCrt;
FILE *hf;
AllocConsole();
hCrt = _open_osfhandle(
(long) GetStdHandle(STD_OUTPUT_HANDLE),
_O_TEXT
);
hf = _fdopen( hCrt, "w" );
*stdout = *hf;
setvbuf( stdout, NULL, _IONBF, 0 );
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR cmdin , int showMode)
{
LPTSTR volumeNameBuffer=NULL,fileSystemNameBuffer=NULL;
LPDWORD volumeSerialNumber,maximumComponentLength,fileSystemFlags;
OpenConsole();
printf("C volume info: \n");
//(1) if(!GetVolumeInformation("C:\\",volumeNameBuffer,MAX_PATH+1,volumeSerialNumber,maximumComponentLength,fileSystemFlags,fileSystemNameBuffer,10))
MessageBox(0,"Error!","Error!",0);
//(2)
/*if(!GetVolumeInformation(volumeNameBuffer,MAX_PATH,fileSystemNameBuffer,10))
MessageBox(0,"Error!","Error!",0);*/
printf("volume name: %s, file system: %s\n",volumeNameBuffer, fileSystemNameBuffer);
Sleep(10000);
return 0;
}
Informacje n.t naszej nieszczęsnej funkcji:
http://msdn.microsoft.com/query/dev10.query?appId=Dev10IDEF1&l=EN-US&k=k%28GETVOLUMEINFORMATION%29;k%28DevLang-%22C%2B%2B%22%29&rd=true
Problem jest następujący: w pierwszym przypadku (1) korzystam z rozszerzonej wersji funkcji(podaję wszystkie parametry, łącznie z opcjonalnymi). Wychodzi run-time error:
Run-Time Check Failure #3 - The variable 'fileSystemFlags' is being used without being initialized.
Po co niby miałem to inicjalizować, skoro do tej zmiennej ma wchodzić output funkcji?
(2)
Wyskakuje błąd kompilacji,wynika z niego tak jakby wszystkie parametry były obowiązkowe:
1>c:\users\tomek\documents\visual studio 2010\projects\file_creation_winapi\file_creation_winapi\file_creation_main.cpp(33): error C2660: 'GetVolumeInformationA' : function does not take 4 arguments