COM.exe中0x003b1405处的未处理异常:0xC0000005:访问冲突读取位置0x00000402

时间:2016-02-09 09:13:41

标签: c++ com

我正在尝试读取PC的COM端口的地址。我需要知道使用哪一个,我想这个程序应该对我很有帮助。但似乎我无法从内存中读取该地址,为什么?

void main(void)
{
 unsigned int *ptraddr =nullptr;  /* Pointer to location of Port Addresses */
 unsigned int address =0;       /* Address of Port */
 int a=0;

 ptraddr=(unsigned int*)0x00000402;

 for (a = 0; a <  4; a++)
   {
    address = *ptraddr;
    if (address == 0)
                printf("No port found for COM%d \n",a+1);
    else
                printf("Address assigned to COM%d is %Xh\n",a+1,address);
    *ptraddr++;
   }
}

1 个答案:

答案 0 :(得分:0)

正如Joachim所说,由于你有权直接访问这样的外围设备,所以已经很久了。请看一下本教程:

http://www.codeguru.com/cpp/i-n/network/serialcommunications/article.php/c2503/CSerial--A-C-Class-for-Serial-Communications.htm