今天在看C++栏中时,看到一篇文章C++的获得硬盘id号文章,它使用了DLL库,此文的出处http://blog.csdn.net/fangshi168775/archive/2005/09/04/471016.aspx,很不错,它的CODE简单
这里我给出以前的一段C++结合汇编的代码,在BC++下运行通过,支持ASM必须安装TASM才能调试,不是微软的MASM哦
#include <stdio.h>
#include <stdlib.h>
#include <dos.h>
#include <conio.h>
#include <string.h>
#include <windows.h>
//#include "mmsystem.h"
//#include "ntport.h"
#include <vcl.h>
#pragma hdrstop
//---------------------------------------------------------------------------
#pragma argsused
#pragma warning (disable:4035)
static int inp(WORD rdx)
{
_asm xor eax, eax
_asm mov dx, rdx
_asm in al, dx
}
static WORD inpw(WORD rdx)
{
_asm xor eax, eax
_asm mov dx, rdx
_asm in ax, dx
}
static void outp(WORD rdx, int ral)
{
_asm mov dx, rdx
_asm mov eax, ral
_asm out dx, al
}
char *getascii (unsigned int in_data [], int off_start, int off_end);
char *getascii (unsigned int in_data [], int off_start, int off_end)
{
static char ret_val[255];
int loop, loop1;
for (loop = off_start, loop1 = 0; loop <= off_end; loop++)
{
ret_val[loop1++] = (char)(in_data[loop] / 256); /* Get High byte */
ret_val[loop1++] = (char)(in_data[loop] % 256); /* Get Low byte */
}
ret_val[loop1] = '0'; /* Make sure it ends in a NULL character */
return (ret_val);
}
int main(int argc, char* argv[])
{
unsigned int dd [256]; /* DiskData */
unsigned int dd_off; /* DiskData offset */
while (inp(0x1F7) != 0x50) /* Wait for controller not busy */
;
outp(0x1F6, 0xA0); /* Get first/second drive */
outp(0x1F7, 0xEC); /* Get drive info data */
while(inp(0x1F7) != 0x58) /* Wait for data ready */
;
for (dd_off = 0; dd_off != 256; dd_off++) /* Read "sector" */
dd[dd_off] = inpw(0x1F0);
printf ("Hard Disk [C] 的序列号 %s", getascii (dd, 10, 19));
return 0;
}
//---------------------------------------------------------------------------
我的主页:itbaby.jss.cn