Click here to Skip to main content
14,976,940 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questionc+ + coding Pin
javaid musa24-May-21 18:17
Memberjavaid musa24-May-21 18:17 
AnswerRe: c+ + coding Pin
CPallini24-May-21 20:00
mveCPallini24-May-21 20:00 
QuestionOptimizing this code ? Pin
Duc Axenn24-May-21 0:56
MemberDuc Axenn24-May-21 0:56 
SuggestionRe: Optimizing this code ? Pin
Richard MacCutchan24-May-21 0:02
mveRichard MacCutchan24-May-21 0:02 
GeneralRe: Optimizing this code ? Pin
Duc Axenn24-May-21 0:56
MemberDuc Axenn24-May-21 0:56 
SuggestionRe: Optimizing this code ? Pin
Randor 24-May-21 2:30
professional Randor 24-May-21 2:30 
GeneralRe: Optimizing this code ? Pin
Duc Axenn24-May-21 4:21
MemberDuc Axenn24-May-21 4:21 
GeneralRe: Optimizing this code ? Pin
Duc Axenn24-May-21 8:36
MemberDuc Axenn24-May-21 8:36 
Seriously... i hate myself,

I was so sure that it will be something weird that i 've make a quick refresh of my knowledges on c++, as i said there was years i touch it. I took some notes for the future this time, i'm pretty sure i have already dit it but i don't remember where are this notes... Thanks to that damn sickness.

I can't verify for a spanned volume, if somebody can it will great, last time i tried JODB it was on a netgear NAS that doesn't want anything else except it or raid 1 for the two bay it has. I tried JODB then one of the drives failed i understood how life could be fun...

For the code... if you could give me your feedback, because i recognize it's a bit special to understand how DeviceIOControl works with IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, but finally.. basically by running in debug mode i explored content of extents and realized there were an array... *ù*ù$^% of me. What could say QBert ? "@!#@?!" or something like these. I was so sure to found something weird, another handle with a special iteration behind... No.

Then i modified the part at the end, i let the if conditionnal to avoid problems in case of i retrieve nothing. I don't know if c++ allow to use something like extents?.Extents.Any(). Is there something near that in c++ ?

C++
if (extents)
	{
		vector<BYTE> interfaces;
		for (DWORD i = 0; i < extents->NumberOfDiskExtents; i++)
		{
			// process the extents
			int physicalDriveNumber = extents->Extents->DiskNumber;

			/*
				Once you have the physical drive numbers, you can convert them to physical drive  
                handles by building a path of the form
				\\.\PhysicalDrive# where the # is the decimal expansion of the drive number.
			*/

			wchar_t physicalDrivePath[80];
			swprintf_s(physicalDrivePath, L"\\\\.\\PhysicalDrive%d", physicalDriveNumber);
			driveHandle = CreateFile(physicalDrivePath,
				0, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
				nullptr, OPEN_EXISTING, 0, nullptr);

			interfaces.push_back( GetInterfaceType(driveHandle));
		}

		return interfaces;
	}


In the example i stay with int values that could be used as i want, i'm pretty sure i will stay on c#, i want to enhance an existing explorer system i made for my other applications and i don't know for the while how to call a windows written with something else than winform. I don't even know if it's possible.

Do you think it's ok now ? I'm very dumb to didn't see it at the beginning.


Edit --- (Thanks to Randor)
C++
BYTE& Drives::GetInterfaceType(HANDLE& driveHandle)
{
	STORAGE_PROPERTY_QUERY query{};
	query.PropertyId = StorageAdapterProperty;
	query.QueryType = PropertyStandardQuery;
	DWORD bytesWritten;
	STORAGE_ADAPTER_DESCRIPTOR result{};

	if (DeviceIoControl(driveHandle, IOCTL_STORAGE_QUERY_PROPERTY,
		&query, sizeof(query),
		&result, sizeof(result),
		&bytesWritten, nullptr))
	{
		// type 7 = usb
		printf("Interface type: %d", result.BusType);

		return result.BusType;
	}
}


Header
// Need
// - assert.h
// - atlstr.h

static vector<BYTE> GetPhysicalDrive(wstring path);

static BYTE GetInterfaceType(HANDLE &driveHandle);


modified 25-May-21 6:05am.

GeneralRe: Optimizing this code ? Pin
Randor 24-May-21 14:30
professional Randor 24-May-21 14:30 
GeneralRe: Optimizing this code ? Pin
Duc Axenn24-May-21 20:41
MemberDuc Axenn24-May-21 20:41 
GeneralRe: Optimizing this code ? Pin
Randor 25-May-21 12:25
professional Randor 25-May-21 12:25 
GeneralRe: Optimizing this code ? Pin
Duc Axenn26-May-21 2:53
MemberDuc Axenn26-May-21 2:53 
QuestionCloud Storage Pin
Bram van Kampen23-May-21 15:10
MemberBram van Kampen23-May-21 15:10 
AnswerRe: Cloud Storage Pin
Victor Nijegorodov23-May-21 22:06
MemberVictor Nijegorodov23-May-21 22:06 
GeneralRe: Cloud Storage Pin
Bram van Kampen29-May-21 14:49
MemberBram van Kampen29-May-21 14:49 
AnswerRe: Cloud Storage Pin
Gerry Schmitz24-May-21 7:14
mveGerry Schmitz24-May-21 7:14 
GeneralRe: Cloud Storage Pin
Bram van Kampen29-May-21 14:56
MemberBram van Kampen29-May-21 14:56 
AnswerRe: Cloud Storage Pin
Maximilien25-May-21 2:58
MemberMaximilien25-May-21 2:58 
GeneralRe: Cloud Storage Pin
Bram van Kampen10-Jun-21 14:00
MemberBram van Kampen10-Jun-21 14:00 
Question32 and 64 bit versions of the same project Pin
Richard Andrew x6415-May-21 16:36
professionalRichard Andrew x6415-May-21 16:36 
JokeRe: 32 and 64 bit versions of the same project Pin
Peter_in_278015-May-21 17:00
professionalPeter_in_278015-May-21 17:00 
GeneralRe: 32 and 64 bit versions of the same project Pin
Member 1520359919-May-21 5:05
MemberMember 1520359919-May-21 5:05 
GeneralMessage Closed Pin
22-May-21 1:40
MemberMember 1520359922-May-21 1:40 
AnswerRe: 32 and 64 bit versions of the same project Pin
Dave Kreskowiak15-May-21 18:10
mveDave Kreskowiak15-May-21 18:10 
AnswerRe: 32 and 64 bit versions of the same project PinPopular
Victor Nijegorodov15-May-21 21:25
MemberVictor Nijegorodov15-May-21 21:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.