windows编程 以及 设置IP

 

在Windows 下,各盘符其实是系统中一个文件,我们了可以通过CreateFile来打开,然后再通过DeviceIoControl函数发送不同的控制码获取相关的信息。

这里的信息包括盘符大小,StartingOffset,DiskNumber,ExtentLength等。

 

 

  1. #include<windows.h>
  2. #include<stdio.h>
  3. #include <winioctl.h>
  4. #define IOCTL_VOLUME_BASE ((DWORD) 'V')
  5. #define IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS CTL_CODE(IOCTL_VOLUME_BASE, 0, METHOD_BUFFERED, FILE_ANY_ACCESS)
  6. void Show(char* pName)
  7. {
  8. printf("%s\n",pName);
  9. //char* pName = "\\\\.\\D:";
  10. HANDLE hDevice = CreateFile(pName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
  11. if (hDevice == INVALID_HANDLE_VALUE)
  12. {
  13. return ;
  14. }
  15. typedef struct _DISK_EXTENT {
  16. ULONG DiskNumber;
  17. LARGE_INTEGER StartingOffset;
  18. LARGE_INTEGER ExtentLength;
  19. } DISK_EXTENT, *PDISK_EXTENT;
  20. typedef struct _VOLUME_DISK_EXTENTS {
  21. ULONG NumberOfDiskExtents;
  22. DISK_EXTENT Extents[1];
  23. } VOLUME_DISK_EXTENTS, *PVOLUME_DISK_EXTENTS;
  24. VOLUME_DISK_EXTENTS vde;
  25. ULONG rtn;
  26. BOOL ok= DeviceIoControl(hDevice,
  27. IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS,
  28. NULL,
  29. 0,
  30. &vde,
  31. sizeof(vde),
  32. &rtn,
  33. NULL);
  34. if(!ok)
  35. {
  36. DWORD e =GetLastError();
  37. e =e;
  38. }
  39. PDISK_EXTENT pdisk = vde.Extents;
  40. printf("DiskID:%d\n",pdisk->DiskNumber);
  41. printf("NumberOfDiskExtents:%d\n",vde.NumberOfDiskExtents);
  42. printf("start:%I64d\n",pdisk->StartingOffset.QuadPart/512);
  43. printf("ExtentLength:%I64d\n",pdisk->ExtentLength.QuadPart/512);
  44. printf("\n");
  45. CloseHandle(hDevice);
  46. }
  47. void main()
  48. {
  49. DWORD dw=GetLogicalDriveStrings(0,NULL);
  50. LPTSTR lpDriveStrings=(LPTSTR) HeapAlloc( GetProcessHeap(),0,dw*sizeof(TCHAR));
  51. GetLogicalDriveStrings(dw,lpDriveStrings);
  52. for(;strlen(lpDriveStrings);)
  53. {
  54. printf("%s\n",lpDriveStrings);
  55. lpDriveStrings+=strlen(lpDriveStrings);
  56. lpDriveStrings++;
  57. }
  58. Show("\\\\.\\C:");
  59. Show("\\\\.\\D:");
  60. Show("\\\\.\\E:");
  61. Show("\\\\.\\F:");
  62. Show("\\\\.\\G:");
  63. Show("\\\\.\\H:");
  64. Show("\\\\.\\I:");
  65. Show("\\\\.\\M:");
  66. }

 

 

#include<windows.h>
#include<stdio.h>
#include <winioctl.h>


#define IOCTL_VOLUME_BASE ((DWORD) 'V')
#define IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS CTL_CODE(IOCTL_VOLUME_BASE, 0, METHOD_BUFFERED, FILE_ANY_ACCESS)
void Show(char* pName)
{
printf("%s\n",pName);
//char* pName = "\\\\.\\D:";
HANDLE hDevice = CreateFile(pName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
if (hDevice == INVALID_HANDLE_VALUE)
{
return ;
}
typedef struct _DISK_EXTENT {
ULONG DiskNumber;
LARGE_INTEGER StartingOffset;
LARGE_INTEGER ExtentLength;
} DISK_EXTENT, *PDISK_EXTENT;
typedef struct _VOLUME_DISK_EXTENTS {
ULONG NumberOfDiskExtents;
DISK_EXTENT Extents[1];
} VOLUME_DISK_EXTENTS, *PVOLUME_DISK_EXTENTS;
VOLUME_DISK_EXTENTS vde;
ULONG rtn;
BOOL ok= DeviceIoControl(hDevice,
IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS,
NULL,
0,
&vde,
sizeof(vde),
&rtn,
NULL);
if(!ok)
{
DWORD e =GetLastError();
e =e;
}
PDISK_EXTENT pdisk = vde.Extents;
printf("DiskID:%d\n",pdisk->DiskNumber);
printf("NumberOfDiskExtents:%d\n",vde.NumberOfDiskExtents);
printf("start:%I64d\n",pdisk->StartingOffset.QuadPart/512);
printf("ExtentLength:%I64d\n",pdisk->ExtentLength.QuadPart/512);
printf("\n");
printf("IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS=%d \r\n",IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS);
printf("IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS=%x \r\n",IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS);
CloseHandle(hDevice);
}


void Show1(char* pName)
{
printf("%s\n",pName);
//char* pName = "\\\\.\\D:";
HANDLE hDevice = CreateFile(pName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
if (hDevice == INVALID_HANDLE_VALUE)
{
return ;
}


typedef struct _DRIVE_LAYOUT_INFORMATION_MBR {
DWORD Signature;
DWORD CheckSum;
} DRIVE_LAYOUT_INFORMATION_MBR, *PDRIVE_LAYOUT_INFORMATION_MBR;

typedef struct _DRIVE_LAYOUT_INFORMATION_GPT {
GUID DiskId;
LARGE_INTEGER StartingUsableOffset;
LARGE_INTEGER UsableLength;
DWORD MaxPartitionCount;
} DRIVE_LAYOUT_INFORMATION_GPT, *PDRIVE_LAYOUT_INFORMATION_GPT;

typedef enum _PARTITION_STYLE {
PARTITION_STYLE_MBR,
PARTITION_STYLE_GPT,
PARTITION_STYLE_RAW
} PARTITION_STYLE;

typedef struct _PARTITION_INFORMATION_MBR {
BYTE PartitionType;
BOOLEAN BootIndicator;
BOOLEAN RecognizedPartition;
DWORD HiddenSectors;
GUID PartitionId;
} PARTITION_INFORMATION_MBR, *PPARTITION_INFORMATION_MBR;

typedef struct _PARTITION_INFORMATION_GPT {
GUID PartitionType;
GUID PartitionId;
DWORD64 Attributes;
WCHAR Name[36];
} PARTITION_INFORMATION_GPT, *PPARTITION_INFORMATION_GPT;

typedef struct _PARTITION_INFORMATION_EX {
PARTITION_STYLE PartitionStyle;
LARGE_INTEGER StartingOffset;
LARGE_INTEGER PartitionLength;
DWORD PartitionNumber;
BOOLEAN RewritePartition;
BOOLEAN IsServicePartition;
union {
PARTITION_INFORMATION_MBR Mbr;
PARTITION_INFORMATION_GPT Gpt;
} DUMMYUNIONNAME;
} PARTITION_INFORMATION_EX, *PPARTITION_INFORMATION_EX;

typedef struct _DRIVE_LAYOUT_INFORMATION_EX {
DWORD PartitionStyle;
DWORD PartitionCount;
union {
DRIVE_LAYOUT_INFORMATION_MBR Mbr;
DRIVE_LAYOUT_INFORMATION_GPT Gpt;
} DUMMYUNIONNAME;
PARTITION_INFORMATION_EX PartitionEntry[1];
} DRIVE_LAYOUT_INFORMATION_EX, *PDRIVE_LAYOUT_INFORMATION_EX;

typedef struct _DRIVE_LAYOUT_INFORMATION {
DWORD PartitionCount;
DWORD Signature;
PARTITION_INFORMATION PartitionEntry[1];
} DRIVE_LAYOUT_INFORMATION, *PDRIVE_LAYOUT_INFORMATION;

DRIVE_LAYOUT_INFORMATION_EX vdc_ex;
// DRIVE_LAYOUT_INFORMATION vdc;

ULONG rtn;
BOOL ok= DeviceIoControl(hDevice,
IOCTL_DISK_GET_DRIVE_LAYOUT,
NULL,
0,
&vdc_ex,
sizeof(vdc_ex),
&rtn,
NULL);
if(!ok)
{
DWORD e =GetLastError();
e =e;
}
// PDISK_EXTENT pdisk = vdc.PartitionStyle;

//printf("PartitionCount:%d\n",vdc.PartitionCount);
//printf("Signature:%d\n",vdc.Signature);

printf("PartitionStyle:%d\n",vdc_ex.PartitionStyle);
printf("PartitionCount:%d\n",vdc_ex.PartitionCount);



printf("\n");
// printf("IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS=%d \r\n",IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS);
printf("IOCTL_DISK_GET_DRIVE_LAYOUT=%x \r\n",IOCTL_DISK_GET_DRIVE_LAYOUT);
CloseHandle(hDevice);
}

void Show2(char* pName)
{
printf("%s\n",pName);
//char* pName = "\\\\.\\D:";
HANDLE hDevice = CreateFile(pName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
if (hDevice == INVALID_HANDLE_VALUE)
{
return ;
}


typedef struct _DRIVE_LAYOUT_INFORMATION_MBR {
DWORD Signature;
DWORD CheckSum;
} DRIVE_LAYOUT_INFORMATION_MBR, *PDRIVE_LAYOUT_INFORMATION_MBR;

typedef struct _DRIVE_LAYOUT_INFORMATION_GPT {
GUID DiskId;
LARGE_INTEGER StartingUsableOffset;
LARGE_INTEGER UsableLength;
DWORD MaxPartitionCount;
} DRIVE_LAYOUT_INFORMATION_GPT, *PDRIVE_LAYOUT_INFORMATION_GPT;

typedef enum _PARTITION_STYLE {
PARTITION_STYLE_MBR,
PARTITION_STYLE_GPT,
PARTITION_STYLE_RAW
} PARTITION_STYLE;

typedef struct _PARTITION_INFORMATION_MBR {
BYTE PartitionType;
BOOLEAN BootIndicator;
BOOLEAN RecognizedPartition;
DWORD HiddenSectors;
GUID PartitionId;
} PARTITION_INFORMATION_MBR, *PPARTITION_INFORMATION_MBR;

typedef struct _PARTITION_INFORMATION_GPT {
GUID PartitionType;
GUID PartitionId;
DWORD64 Attributes;
WCHAR Name[36];
} PARTITION_INFORMATION_GPT, *PPARTITION_INFORMATION_GPT;

typedef struct _PARTITION_INFORMATION_EX {
PARTITION_STYLE PartitionStyle;
LARGE_INTEGER StartingOffset;
LARGE_INTEGER PartitionLength;
DWORD PartitionNumber;
BOOLEAN RewritePartition;
BOOLEAN IsServicePartition;
union {
PARTITION_INFORMATION_MBR Mbr;
PARTITION_INFORMATION_GPT Gpt;
} DUMMYUNIONNAME;
} PARTITION_INFORMATION_EX, *PPARTITION_INFORMATION_EX;

typedef struct _DRIVE_LAYOUT_INFORMATION_EX {
DWORD PartitionStyle;
DWORD PartitionCount;
union {
DRIVE_LAYOUT_INFORMATION_MBR Mbr;
DRIVE_LAYOUT_INFORMATION_GPT Gpt;
} DUMMYUNIONNAME;
PARTITION_INFORMATION_EX PartitionEntry[1];
} DRIVE_LAYOUT_INFORMATION_EX, *PDRIVE_LAYOUT_INFORMATION_EX;

typedef struct _DRIVE_LAYOUT_INFORMATION {
DWORD PartitionCount;
DWORD Signature;
PARTITION_INFORMATION PartitionEntry[1];
} DRIVE_LAYOUT_INFORMATION, *PDRIVE_LAYOUT_INFORMATION;

// DRIVE_LAYOUT_INFORMATION_EX vdc_ex;
DRIVE_LAYOUT_INFORMATION vdc;

ULONG rtn;
BOOL ok= DeviceIoControl(hDevice,
IOCTL_DISK_GET_DRIVE_LAYOUT,
NULL,
0,
&vdc,
sizeof(vdc),
&rtn,
NULL);
if(!ok)
{
DWORD e =GetLastError();
e =e;
}
// PDISK_EXTENT pdisk = vdc.PartitionStyle;

printf("PartitionCount:%d\n",vdc.PartitionCount);
printf("Signature:%d\n",vdc.Signature);

printf("PartitionType:%d\n",vdc.PartitionEntry[0].PartitionType);

//printf("PartitionStyle:%d\n",vdc_ex.PartitionStyle);
//printf("PartitionCount:%d\n",vdc_ex.PartitionCount);



printf("\n");
// printf("IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS=%d \r\n",IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS);
printf("IOCTL_DISK_GET_DRIVE_LAYOUT=%x \r\n",IOCTL_DISK_GET_DRIVE_LAYOUT);
CloseHandle(hDevice);
}
void Show3(char* pName)
{
printf("%s\n",pName);
//char* pName = "\\\\.\\D:";
HANDLE hDevice = CreateFile(pName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
if (hDevice == INVALID_HANDLE_VALUE)
{
return ;
}


typedef struct _DRIVE_LAYOUT_INFORMATION_MBR {
DWORD Signature;
DWORD CheckSum;
} DRIVE_LAYOUT_INFORMATION_MBR, *PDRIVE_LAYOUT_INFORMATION_MBR;

typedef struct _DRIVE_LAYOUT_INFORMATION_GPT {
GUID DiskId;
LARGE_INTEGER StartingUsableOffset;
LARGE_INTEGER UsableLength;
DWORD MaxPartitionCount;
} DRIVE_LAYOUT_INFORMATION_GPT, *PDRIVE_LAYOUT_INFORMATION_GPT;

typedef enum _PARTITION_STYLE {
PARTITION_STYLE_MBR,
PARTITION_STYLE_GPT,
PARTITION_STYLE_RAW
} PARTITION_STYLE;

typedef struct _PARTITION_INFORMATION_MBR {
BYTE PartitionType;
BOOLEAN BootIndicator;
BOOLEAN RecognizedPartition;
DWORD HiddenSectors;
GUID PartitionId;
} PARTITION_INFORMATION_MBR, *PPARTITION_INFORMATION_MBR;

typedef struct _PARTITION_INFORMATION_GPT {
GUID PartitionType;
GUID PartitionId;
DWORD64 Attributes;
WCHAR Name[36];
} PARTITION_INFORMATION_GPT, *PPARTITION_INFORMATION_GPT;

typedef struct _PARTITION_INFORMATION_EX {
PARTITION_STYLE PartitionStyle;
LARGE_INTEGER StartingOffset;
LARGE_INTEGER PartitionLength;
DWORD PartitionNumber;
BOOLEAN RewritePartition;
BOOLEAN IsServicePartition;
union {
PARTITION_INFORMATION_MBR Mbr;
PARTITION_INFORMATION_GPT Gpt;
} DUMMYUNIONNAME;
} PARTITION_INFORMATION_EX, *PPARTITION_INFORMATION_EX;

typedef struct _DRIVE_LAYOUT_INFORMATION_EX {
DWORD PartitionStyle;
DWORD PartitionCount;
union {
DRIVE_LAYOUT_INFORMATION_MBR Mbr;
DRIVE_LAYOUT_INFORMATION_GPT Gpt;
} DUMMYUNIONNAME;
PARTITION_INFORMATION_EX PartitionEntry[1];
} DRIVE_LAYOUT_INFORMATION_EX, *PDRIVE_LAYOUT_INFORMATION_EX;

typedef struct _DRIVE_LAYOUT_INFORMATION {
DWORD PartitionCount;
DWORD Signature;
PARTITION_INFORMATION PartitionEntry[1];
} DRIVE_LAYOUT_INFORMATION, *PDRIVE_LAYOUT_INFORMATION;

// DRIVE_LAYOUT_INFORMATION_EX vdc_ex;
DRIVE_LAYOUT_INFORMATION vdc;

ULONG rtn;
BOOL ok= DeviceIoControl(hDevice,
IOCTL_DISK_GET_PARTITION_INFO,
NULL,
0,
&vdc,
sizeof(vdc),
&rtn,
NULL);
if(!ok)
{
DWORD e =GetLastError();
e =e;
}
// PDISK_EXTENT pdisk = vdc.PartitionStyle;

printf("PartitionCount:%d\n",vdc.PartitionCount);
printf("Signature:%d\n",vdc.Signature);

printf("PartitionType:%d\n",vdc.PartitionEntry[0].PartitionType);

//printf("PartitionStyle:%d\n",vdc_ex.PartitionStyle);
//printf("PartitionCount:%d\n",vdc_ex.PartitionCount);



printf("\n");
// printf("IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS=%d \r\n",IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS);
printf("IOCTL_DISK_GET_DRIVE_LAYOUT=%x \r\n",IOCTL_DISK_GET_DRIVE_LAYOUT);
CloseHandle(hDevice);
}

 

int _tmain(int argc, _TCHAR* argv[])
{
printf("hello world \r\n");
DWORD dw=GetLogicalDriveStrings(0,NULL);
LPTSTR lpDriveStrings=(LPTSTR) HeapAlloc( GetProcessHeap(),0,dw*sizeof(TCHAR));
GetLogicalDriveStrings(dw,lpDriveStrings);
for(;strlen(lpDriveStrings);)
{
printf("%s\n",lpDriveStrings);
lpDriveStrings+=strlen(lpDriveStrings);
lpDriveStrings++;
}
Show("\\\\.\\C:");
// Show("\\\\.\\D:");

Show1("\\\\.\\C:");
Show2("\\\\.\\C:");
// Show1("\\\\.\\D:");

return 0;
}

 

 

 

 

VS2010 cannot convert parameter 1 from 'char *' to 'LPCWSTR'

在VC 6.0中编译成功的项目在VS2010中运行可能会出现类型错误。原因是VS2010默认编码方式是Unicode。 比如:不能从const char *转换为LPCWSTR

解决方法: 项目菜单—项目属性—配置属性—常规—项目默认值—字符集,将使用Unicode字符集改为未设置。

 

 

 

 

 

 

 

 

 

2015 环境安装:http://c.biancheng.net/view/453.html

DVDFab 下载地址:


DVDFab 的安装非常简单,这里不再赘述,大家只需要注意一点,安装过程中 Windows 安全中心会发出警告,询问我们是否确定安装,如下图所示

 

下载VS2015

VS2015 社区版(Community)下载地址:

  • 迅雷下载(较快):ed2k://|file|cn_visual_studio_community_2015_x86_dvd_6847368.iso|4013920256|EB7F6605EDE67509E218E29173AC6574|/
  • 百度网盘(较慢):https://pan.baidu.com/s/16aB2go8n4J6vvxzKBA8CTg    提取码:tjcs


以上是 Visual Studio 2015 Community 简体中文版下载地址。VS2015 比较大,有 3.73GB,建议用迅雷下载。

 

解决CREATEFILE函数中不能从const char* 转换到LPCTSTR的问题

问题的原因:
因为在vc6里面默认使用字符ANSII方式编码,而在vs2010及以上默认使用UNICODE方式编码,
它们对一些字符所占内存空间的位数不同,所以就导致了这个问题。
背景介绍:
一、首先我们要明白这几个关键字的含义:
LPSTR: 32bit指针 指向一个字符串,每个字符占1字节。 相当于 char  
LPCSTR: 32-bit指针 指向一个常字符串,每个字符占1字节。 相当于 const char 
 
LPTSTR: 32-bit指针 每字符可能占1字节或2字节,取决于Unicode是否定义 
LPCTSTR:32-bit指针 指向一个常字符串,每字符可能占1字节或2字节,取决于Unicode是否定义 
LPWSTR: 32-bit指针,指向一个unicode字符串的指针,每个字符占2字节。 
LPCWSTR:32-bit指针, 指向一个unicode字符串常量的指针,每个字符占2字节。 
在上面的类型中,L表示long, P表示指针,C表示constant, T表示指针指向的字符占的字节数取决于Unicode是否定义,W表示wide,STR就是string的意思。 
编译器有时候会根据编码方式来选择定义为LPCWSTR还是LPCTSTR
二、ANSI和Unicode的区别
Windows使用两种字符集ANSI和Unicode,前者在处理英文字符时使用单字节方式,在处理中文字符时使用双字节方式。后者不管是英文字符还是中文字符都是采用双字节方式表示。
解决方法:
1.进行强制转换: 
如使用MessageBox(hwnd,”TEST”,NULL,0)就会报错,如果使用强制转换(LPCWSTR)”TEST”,虽然能够通过,但是编码会出错。 
可行的办法是使用 _T(“test.txt”)转换,或者TEXT(“test.txt” ),或者L"test.txt"都可以
pFile = CreateFile(_T(“test.txt”), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
pFile = CreateFile(TEXT(“test.txt” ), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
pFile = CreateFile(L"test.txt", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
只是需要加上头文件tchar.h
2.更改编码格式 
项目菜单——项目属性(最后一个)——配置属性——常规——项目默认值——字符集,将使用Unicode字符集改为未设置即可。

 
 
 
 
printf
wc

int 参数将转换为宽字符 (wchar_t) 并且将列显生成的宽字符。

ws

参数必须为 wchar_t 数组。会一直读取数组中的字节,直到达到终止空字符或数据结尾,并将其解释和列显为宽字符。如果未指定精度,则会将其视为是无穷的,所以将列显所有宽字符,直到达到第一个空字符。如果指定了精度,则仅会列显在对应屏幕列数中显示的那一部分宽字符数组。

x, X

charshortintlong 或 long long 参数将列显为无符号十六进制(以 16 为基数)整数。signed 类型或 unsigned 类型的参数可用于与此转换。如果使用 x 形式的转换,则将使用字母数字 abcdef。如果使用 X 形式的转换,则将使用字母数字 ABCDEF。如果指定了 # 标志,则将在非零结果的开头加上 0x(对于 %x)或 0X(对于 %X)。

 

 

 

分区文件系统:

 

 

 

PartitionType   FAT31 FAT16   NTFS

EFI basic data

GPT与NTFS关系

 

 

 

数据类型

Windows常见数据类型可以参考如下:

windows  类型:

type (

BOOL uint32

BOOLEAN byte

BYTE byte

DWORD uint32

DWORD64 uint64

HANDLE uintptr

HLOCAL uintptr

LARGE_INTEGER int64

LONG int32

LPVOID uintptr

SIZE_T uintptr

UINT uint32

ULONG_PTR uintptr

ULONGLONG uint64

WORD uint16

)

 

 

 

 

 

获取磁盘大小:

IOCTL_DISK_GET_DRIVE_GEOMETRY_EX

 

typedef union _LARGE_INTEGER {

    struct {

        ULONG LowPart;

        LONG HighPart;

    } DUMMYSTRUCTNAME;

    struct {

        ULONG LowPart;

        LONG HighPart;

    } u;

#endif //MIDL_PASS

    LONGLONG QuadPart;

} LARGE_INTEGER;

//  lld  llu 64位 
typedef struct _DISK_GEOMETRY_EX {
  DISK_GEOMETRY Geometry;
  LARGE_INTEGER DiskSize;
  BYTE          Data[1];
} DISK_GEOMETRY_EX, *PDISK_GEOMETRY_EX;

 

 

 

 

 

 

 

 

 设置IP:

1.ip

 

netsh interface ip set address name="本地连接" source=static addr=192.168.36.153 mask=255.255.255.0 gateway=192.168.36.1

 
2.
netsh interface ip set address name="本地连接" source=static addr=192.168.36.153 mask=255.255.255.0 gateway=192.168.36.1
 
下面是,设置DNS为动态获取的命令:
 
netsh interface ip set dns name="本地连接" source=dhcp
 
设置首选DNS服务器地址:
netsh interface ip set dns name="本地连接" source=static addr=101.226.4.6 register=primary
后面的register参数不加也可以
 
设置备用DNS服务器地址:
netsh interface ip add dns name="本地连接" addr=114.114.114.114 index=2
 
 

 

 

 

 

 

 

 

参考:

 http://c.biancheng.net/view/453.html

 https://docs.oracle.com/cd/E19253-01/819-6959/chp-fmt-1/index.html      // printf  ws

 https://www.cnblogs.com/chaikefusibushiji/category/1072524.html

https://www.cnblogs.com/chaikefusibushiji/p/6775775.html

 https://www.404bugs.com/details/911566662558076928

https://blog.csdn.net/sinat_32100995/article/details/77359847

https://docs.microsoft.com/zh-cn/windows/win32/fileio/disk-partition-types

https://www.cnblogs.com/chaikefusibushiji/p/6775774.html       //deviceiocontrol

https://blog.csdn.net/runhua/article/details/98098447         // 使用GO语言调用Windows API

 

https://cloud.tencent.com/developer/article/1597570  // LARGE_INTEGER类型

https://docs.microsoft.com/en-us/windows/win32/api/winioctl/ni-winioctl-ioctl_disk_get_drive_geometry_ex    // 

 

 

IOCTL_DISK_GET_DRIVE_GEOMETRY_EX

netsh interface ip set address name="本地连接" source=static addr=192.168.36.153 mask=255.255.255.0 gateway=192.168.36.1
posted @ 2022-04-25 13:55  redrobot  阅读(359)  评论(0编辑  收藏  举报