EVC 转写 c#

wolf_Knight 2010-01-12 04:35:04
有如下EVC代码:

#include "Fmd.h"
#include "Winbase.h"
#pragma comment(lib, "coredll.lib")

#define IOCTL_FMD_BLON CTL_CODE(0xE1B3, 0xE1E, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_FMD_BLOFF CTL_CODE(0xE1B3, 0xE1F, METHOD_BUFFERED, FILE_ANY_ACCESS)

iRet = DeviceIoControl(hFirm, IOCTL_FMD_BLON, NULL, NULL, NULL, NULL, NULL, NULL);

iRet = DeviceIoControl(hFirm, IOCTL_FMD_BLOFF, NULL, NULL, NULL, NULL, NULL, NULL);

要调用DeviceIoControl函数,请问c#该怎么调用。谢谢!
...全文
121 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
Uncle_Yong 2010-01-19
  • 打赏
  • 举报
回复
建议去读读CSDN中对参数的解释。

给你一个获取硬盘的基本参数大例子:

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

BOOL GetDriveGeometry(DISK_GEOMETRY *pdg)
{
HANDLE hDevice; // handle to the drive to be examined
BOOL bResult; // results flag
DWORD junk; // discard results

hDevice = CreateFile("\\\\.\\PhysicalDrive0", // drive to open
0, // no access to the drive
FILE_SHARE_READ | // share mode
FILE_SHARE_WRITE,
NULL, // default security attributes
OPEN_EXISTING, // disposition
0, // file attributes
NULL); // do not copy file attributes

if (hDevice == INVALID_HANDLE_VALUE) // cannot open the drive
{
return (FALSE);
}

bResult = DeviceIoControl(hDevice, // device to be queried
IOCTL_DISK_GET_DRIVE_GEOMETRY, // operation to perform
NULL, 0, // no input buffer
pdg, sizeof(*pdg), // output buffer
&junk, // # bytes returned
(LPOVERLAPPED) NULL); // synchronous I/O

CloseHandle(hDevice);

return (bResult);
}

int main(int argc, char *argv[])
{
DISK_GEOMETRY pdg; // disk drive geometry structure
BOOL bResult; // generic results flag
ULONGLONG DiskSize; // size of the drive, in bytes

bResult = GetDriveGeometry (&pdg);

if (bResult)
{
printf("Cylinders = %I64d\n", pdg.Cylinders);
printf("Tracks per cylinder = %ld\n", (ULONG) pdg.TracksPerCylinder);
printf("Sectors per track = %ld\n", (ULONG) pdg.SectorsPerTrack);
printf("Bytes per sector = %ld\n", (ULONG) pdg.BytesPerSector);

DiskSize = pdg.Cylinders.QuadPart * (ULONG)pdg.TracksPerCylinder *
(ULONG)pdg.SectorsPerTrack * (ULONG)pdg.BytesPerSector;
printf("Disk size = %I64d (Bytes) = %I64d (Mb)\n", DiskSize,
DiskSize / (1024 * 1024));
}
else
{
printf("GetDriveGeometry failed. Error %ld.\n", GetLastError());
}

return ((int)bResult);
}
wolf_Knight 2010-01-13
  • 打赏
  • 举报
回复
哪位高手补充一下啊
wolf_Knight 2010-01-12
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 52yyp 的回复:]
动态调用API:
class SysAPI
{
        [DllImport("Kernel32.dll ", EntryPoint = "DeviceIoControl")]
        public static extern int DeviceIoControl(IntPtr hDevice, UInt32 dwIoControlCode, IntPtr lpInBuffer, UInt32 nInBufferSize, IntPtr lpOutBuffer, UInt32 nOutBufferSize, IntPtr lpBytesReturned, IntPtr lpOverlapped
);
}

然后, SysAPI.DeviceIoControl(...), 配好你的参数就可以了。


[/Quote]


谢谢,如果我要配置上面参数,该如何配置?
Uncle_Yong 2010-01-12
  • 打赏
  • 举报
回复
动态调用API:
class SysAPI
{
[DllImport("Kernel32.dll ", EntryPoint = "DeviceIoControl")]
public static extern int DeviceIoControl(IntPtr hDevice, UInt32 dwIoControlCode, IntPtr lpInBuffer, UInt32 nInBufferSize, IntPtr lpOutBuffer, UInt32 nOutBufferSize, IntPtr lpBytesReturned, IntPtr lpOverlapped
);
}

然后, SysAPI.DeviceIoControl(...), 配好你的参数就可以了。

ILOVE_ASPNET 2010-01-12
  • 打赏
  • 举报
回复
up
平生我自如 2010-01-12
  • 打赏
  • 举报
回复
没人回答!我帮顶

110,566

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧