biblioteka windows.h - funkcja QueryDosDevice

0
#include <Windows.h>



int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR cmdIn, int showMode)
{
	TCHAR targetPath[5000];

	QueryDosDevice(NULL,targetPath,5000);

	MessageBox(0,targetPath,L"Info",0);



	return 0;
}

Dlaczego w message box'ie pojawia się lakoniczne

global
, skoro:

If lpDeviceName is NULL, the function retrieves a list of all existing MS-DOS device names. Each null-terminated string stored into the buffer is the name of an existing MS-DOS device, for example, \Device\HarddiskVolume1 or \Device\Floppy0.

Źródło: http://msdn.microsoft.com/en-us/library/windows/desktop/aa365461%28v=vs.85%29.aspx

1

The first null-terminated string stored into the buffer is the current mapping for the device. The other null-terminated strings represent undeleted prior mappings for the device.

Stringi zawsze są guardowane za pomocą bajtu \0 (NULL), jak można przeczytać wyżej funkcja wrzuca do bufora kilka stringów jeden obok drugiego. Message Box się zatrzymuje na pierwszym, bo napotyka NULL.

0

Niby poprawiłem ale czuję niedosyt, bo pewnie dało się prościej.

#ifndef UNICODE
#define UNICODE
#endif

#include <Windows.h>



int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR cmdIn, int showMode)
{
	TCHAR targetPath[5000];

	QueryDosDevice(NULL,targetPath,5000);

	for(int i=0; i<5000;i++)
	if (targetPath[i]=='\0')(targetPath[i]='\n');
			
	MessageBox(0,targetPath,L"Info",0);

	return 0;
}
0
        wchar_t targetPath[5000];
        QueryDosDevice(NULL,targetPath,5000);
	const wchar_t* device = &targetPath[0];
	while (device[0] != '\0')
	{
		MessageBox(0, device, L"Info", 0);
		device += wcslen(device)+1;
	}

1 użytkowników online, w tym zalogowanych: 0, gości: 1