我试图获得物理驱动器的总大小(未分配+主分区+扩展分区大小).
我有磁盘名称 \\.\PhysicalDriveX
我尝试使用GetDiskFreeSpaceEx但是当分区是扩展分区时它没有给出正确的结果,在这种情况下它返回分区的总大小.
BOOL ret = FALSE;
ULARGE_INTEGER ulFreeSpace;
ULARGE_INTEGER ulTotalSpace;
ULARGE_INTEGER ulTotalFreeSpace;
__int64 ulTotalUsedSpace = 0;
GetDiskFreeSpaceEx(szBuffer, &ulFreeSpace, &ulTotalSpace, &ulTotalFreeSpace);
*diskSize = ulTotalSpace.QuadPart;
Run Code Online (Sandbox Code Playgroud)
我可以使用IOCTL_DISK_GET_DRIVE_LAYOUT_EX使用DeviceIoControl获取分区信息,但我对扩展分区大小感到困惑.
有没有办法可以在Windows上用C++准确地获取硬盘的总大小?
我的代码是
class CTemp{
public:
CTemp(){
printf("\nIn cons");
}
~CTemp(){
printf("\nIn dest");
}
};
void Dowork(CTemp obj)
{
printf("\nDo work");
}
int main()
{
CTemp * obj = new CTemp();
Dowork(*obj);
delete obj;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我得到的输出是
In cons
Do work
In dest
In dest
Run Code Online (Sandbox Code Playgroud)
现在为什么构造函数被调用一次但析构函数被调用两次?有人可以解释一下吗?
我上课了
class Names{
public static string One = "Value of One";
};
Run Code Online (Sandbox Code Playgroud)
我有一个方法
void GetValue(string strValue)
{
string strDef = "Names." + strValue;
//Now here i want to get the value of Names.One if the value of strValue is "One"
//I want to get the value of Names.One in a variable
strResult = ??;//what to do here
//so that the contents of strResult will be "Value of One"
}
Run Code Online (Sandbox Code Playgroud)
我这样叫GetValue
GetValue("One");
Run Code Online (Sandbox Code Playgroud)
我不想使用if else或字典.我想知道是否有可能以这种方式做到这一点?
我试过像这样的反射,但它总是返回null我也在类中有一个静态属性,所以我不创建一个对象
PropertyInfo pinfo = typeof(Names).GetProperty("One");
object value …Run Code Online (Sandbox Code Playgroud)