⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pci.cpp

📁 有关树WDM 驱动的编程.里面包含了许多实例,学习硬件的可以参考哦
💻 CPP
字号:
// pci.cpp : implementation file
//

#include "stdafx.h"
#include "pctest.h"
#include "pci.h"
#include "adc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern  PCHAR mDynVxDName;
              
/////////////////////////////////////////////////////////////////////////////
// Cpci dialog


Cpci::Cpci(CWnd* pParent /*=NULL*/)
	: CDialog(Cpci::IDD, pParent)
{
	//{{AFX_DATA_INIT(Cpci)
	m_irq = 0;
	m_io2 = _T("");
	m_mem = _T("");
	m_io1 = _T("");
	//}}AFX_DATA_INIT
   hDevice=NULL;
}


void Cpci::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(Cpci)
	DDX_Text(pDX, IDC_EDIT5, m_irq);
	DDX_Text(pDX, IDC_EDIT4, m_io2);
	DDX_Text(pDX, IDC_EDIT6, m_mem);
	DDX_Text(pDX, IDC_EDIT7, m_io1);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(Cpci, CDialog)
	//{{AFX_MSG_MAP(Cpci)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// Cpci message handlers

BOOL Cpci::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
		if(hDevice==NULL)
	{
	    hDevice = CreateFile(mDynVxDName,//"\\\\.\\MatyDevice0",
					  GENERIC_READ | GENERIC_WRITE,
					  FILE_SHARE_READ,
					  NULL,
					  OPEN_EXISTING,
					  0,
					  NULL);
	     if (hDevice == INVALID_HANDLE_VALUE)
		 {
		   AfxMessageBox("请检查板卡和驱动程序");
		   CDialog::OnCancel();
	       return FALSE;
		 }
	}
    
	pci=(pci_cfg*)malloc(sizeof(pci_cfg));

	BOOL status =  DeviceIoControl(
									hDevice, 
			    			    2236432,//IOCTL_PCI_CON,//0x222010 
									NULL, 
									0,
									pci, 
									sizeof(pci_cfg), 
									&nRet, 
 									NULL);
	 m_irq=pci->IRQ;
	 m_io1.Format("%x", pci->IOBase[0]); 
	 m_io2.Format("%x", pci->IOBase[1]); 
	 m_mem.Format("%x",pci->MemBase);
 	 UpdateData(FALSE);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
void Cpci::OnOK() 
{
	// TODO: Add extra validation here
		if(hDevice!=NULL)
	{
	CloseHandle( hDevice);
	hDevice=NULL;
	}
	CDialog::OnOK();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -