| 5 | 1/1 | 返回列表 |
| 查看: 2395 | 回復(fù): 15 | |||
| 當(dāng)前只顯示滿足指定條件的回帖,點(diǎn)擊這里查看本話題的所有回帖 | |||
leafmavis木蟲 (文壇精英)
|
[求助]
VC++中如何應(yīng)用porttalk
|
||
|
有個實(shí)驗(yàn),是控制一個電動臺做旋轉(zhuǎn)運(yùn)動(這部分VC++源代碼由產(chǎn)品的制造商提供),從而給實(shí)驗(yàn)動物刺激,同時采集動物的腦電。我們想在旋轉(zhuǎn)運(yùn)動的開始和結(jié)束的時候,分別給并口一秒鐘的高電平,以便在腦電信號采集系統(tǒng)上打上同步標(biāo)記。我們做了一個并口的流水燈以驗(yàn)證并口操作的可靠性。用C++bulider 6.0時,利用PortTalk能控制流水燈工作;但用VC++ 6.0時,報錯。因電動臺的源碼是VC++ 6.0,所以想請教高手。謝謝! 下面是單純的并口操作驗(yàn)證: 1、用C++bulider時,在工程目錄下拷進(jìn)這兩個文件:PortTalk.sys; PortTalk.h。在Form中添加一個按鍵(功能為:使并口輸出脈寬為1秒的高電平),并在Form中添加了并口初始化(因?yàn)橛?jì)算機(jī)開機(jī)時并口各數(shù)據(jù)位是高電平,初始化就是將所有數(shù)據(jù)位置低)。程序運(yùn)行正常,流水燈的開閉正常。 2、用VC++時,操作同上,但編譯時報錯。想請問一下,在VC++下如何使用PortTalk ?網(wǎng)上沒說PortTalk不能用于VC++呀 --------------------Configuration: fang1 - Win32 Debug-------------------- Compiling resources... Compiling... StdAfx.cpp Compiling... fang1.cpp fang1Dlg.cpp e:\work\vc\learn1\fang1\porttalk.h(41) : error C2065: 'ShowMessage' : undeclared identifier e:\work\vc\learn1\fang1\porttalk.h(80) : error C2065: 'SC_HANDLE' : undeclared identifier e:\work\vc\learn1\fang1\porttalk.h(80) : error C2146: syntax error : missing ';' before identifier 'SchSCManager' e:\work\vc\learn1\fang1\porttalk.h(80) : error C2065: 'SchSCManager' : undeclared identifier e:\work\vc\learn1\fang1\porttalk.h(81) : error C2146: syntax error : missing ';' before identifier 'schService' e:\work\vc\learn1\fang1\porttalk.h(81) : error C2065: 'schService' : undeclared identifier e:\work\vc\learn1\fang1\porttalk.h(85) : error C2065: 'OpenSCManager' : undeclared identifier e:\work\vc\learn1\fang1\porttalk.h(85) : error C2065: 'SC_MANAGER_ALL_ACCESS' : undeclared identifier e:\work\vc\learn1\fang1\porttalk.h(94) : error C2065: 'OpenService' : undeclared identifier e:\work\vc\learn1\fang1\porttalk.h(94) : error C2065: 'SERVICE_ALL_ACCESS' : undeclared identifier e:\work\vc\learn1\fang1\porttalk.h(110) : error C2065: 'StartService' : undeclared identifier e:\work\vc\learn1\fang1\porttalk.h(112) : error C2065: 'CloseServiceHandle' : undeclared identifier e:\work\vc\learn1\fang1\porttalk.h(118) : error C2146: syntax error : missing ';' before identifier 'SchSCManager' e:\work\vc\learn1\fang1\porttalk.h(119) : error C2146: syntax error : missing ';' before identifier 'schService' e:\work\vc\learn1\fang1\porttalk.h(129) : error C2065: 'CreateService' : undeclared identifier Generating Code... Error executing cl.exe. fang1.exe - 15 error(s), 0 warning(s) |

木蟲 (文壇精英)
|
謝謝各位熱心的回復(fù)。 加上這段后還報錯。 e:\work\vc\learn1\fang1\porttalk.h(51) : error C2660: 'MessageBoxA' : function does not take 1 parameters e:\work\vc\learn1\fang1\porttalk.h(65) : error C2660: 'MessageBoxA' : function does not take 1 parameters e:\work\vc\learn1\fang1\porttalk.h(90) : error C2065: 'SC_HANDLE' : undeclared identifier e:\work\vc\learn1\fang1\porttalk.h(90) : error C2146: syntax error : missing ';' before identifier 'SchSCManager' e:\work\vc\learn1\fang1\porttalk.h(90) : error C2065: 'SchSCManager' : undeclared identifier e:\work\vc\learn1\fang1\porttalk.h(91) : error C2146: syntax error : missing ';' before identifier 'schService' e:\work\vc\learn1\fang1\porttalk.h(91) : error C2065: 'schService' : undeclared identifier e:\work\vc\learn1\fang1\porttalk.h(95) : error C2065: 'OpenSCManager' : undeclared identifier e:\work\vc\learn1\fang1\porttalk.h(95) : error C2065: 'SC_MANAGER_ALL_ACCESS' : undeclared identifier e:\work\vc\learn1\fang1\porttalk.h(99) : error C2660: 'MessageBoxA' : function does not take 1 parameters e:\work\vc\learn1\fang1\porttalk.h(104) : error C2065: 'OpenService' : undeclared identifier e:\work\vc\learn1\fang1\porttalk.h(104) : error C2065: 'SERVICE_ALL_ACCESS' : undeclared identifier e:\work\vc\learn1\fang1\porttalk.h(120) : error C2065: 'StartService' : undeclared identifier e:\work\vc\learn1\fang1\porttalk.h(122) : error C2065: 'CloseServiceHandle' : undeclared identifier e:\work\vc\learn1\fang1\porttalk.h(128) : error C2146: syntax error : missing ';' before identifier 'SchSCManager' e:\work\vc\learn1\fang1\porttalk.h(129) : error C2146: syntax error : missing ';' before identifier 'schService' e:\work\vc\learn1\fang1\porttalk.h(139) : error C2065: 'CreateService' : undeclared identifier Error executing cl.exe. fang1.exe - 17 error(s), 0 warning(s) > |

金蟲 (文壇精英)
老漢一枚
木蟲 (文壇精英)
|
謝謝您的回復(fù),不過頭文件是加上了的。附上C++源碼,除 #include "PortTalk.h" 和最后面的按鍵響應(yīng)函數(shù),其他的都是自動生成的。請幫忙分析,謝謝! // fang1Dlg.cpp : implementation file // #include "stdafx.h" #include "fang1.h" #include "fang1Dlg.h" #include "PortTalk.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CAboutDlg dialog used for App About class CAboutDlg : public CDialog { public: CAboutDlg(); // Dialog Data //{{AFX_DATA(CAboutDlg) enum { IDD = IDD_ABOUTBOX }; //}}AFX_DATA // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CAboutDlg) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL // Implementation protected: //{{AFX_MSG(CAboutDlg) //}}AFX_MSG DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { //{{AFX_DATA_INIT(CAboutDlg) //}}AFX_DATA_INIT } void CAboutDlg: oDataExchange(CDataExchange* pDX){ CDialog: oDataExchange(pDX);//{{AFX_DATA_MAP(CAboutDlg) //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) //{{AFX_MSG_MAP(CAboutDlg) // No message handlers //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CFang1Dlg dialog CFang1Dlg::CFang1Dlg(CWnd* pParent /*=NULL*/) : CDialog(CFang1Dlg::IDD, pParent) { //{{AFX_DATA_INIT(CFang1Dlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CFang1Dlg: oDataExchange(CDataExchange* pDX){ CDialog: oDataExchange(pDX);//{{AFX_DATA_MAP(CFang1Dlg) // NOTE: the ClassWizard will add DDX and DDV calls here //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CFang1Dlg, CDialog) //{{AFX_MSG_MAP(CFang1Dlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDC_BUTTON1, OnButton1) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CFang1Dlg message handlers BOOL CFang1Dlg::OnInitDialog() { CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != NULL) { CString strAboutMenu; strAboutMenu.LoadString(IDS_ABOUTBOX); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); } } // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon // TODO: Add extra initialization here return TRUE; // return TRUE unless you set the focus to a control } void CFang1Dlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } else { CDialog::OnSysCommand(nID, lParam); } } // If you add a minimize button to your dialog, you will need the code below // to draw the icon. For MFC applications using the document/view model, // this is automatically done for you by the framework. void CFang1Dlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CDialog::OnPaint(); } } // The system calls this to obtain the cursor to display while the user drags // the minimized window. HCURSOR CFang1Dlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } void CFang1Dlg::OnButton1() { // TODO: Add your control notification handler code here OpenPortTalk(); //打開地址操作 outportb(0x378,0xFF); Sleep(1000); outportb(0x378,0x00); ClosePortTalk(); //關(guān)閉地址操作 } |

木蟲 (正式寫手)
|
界面的部分都沒有問題(話說這么簡單的東西直接用console application不好嘛) 于是樓主能不能貼一下PortTalk.h這個文件的內(nèi)容呢? 看樣子像是把函數(shù)定義放到.h文件里面了(不是類模板等特殊情況的話這么做其實(shí)不好的),恩,所以先看看吧 PS: 貼代碼的時候,放到 會比較好看一點(diǎn) |
| 最具人氣熱帖推薦 [查看全部] | 作者 | 回/看 | 最后發(fā)表 | |
|---|---|---|---|---|
|
[考研] 287求調(diào)劑 +7 | 晨昏線與星海 2026-03-19 | 8/400 |
|
|---|---|---|---|---|
|
[考研] 一志愿蘇州大學(xué)材料求調(diào)劑,總分315(英一) +5 | sbdksD 2026-03-19 | 5/250 |
|
|
[考研] 350求調(diào)劑 +5 | weudhdk 2026-03-19 | 5/250 |
|
|
[考研] 290求調(diào)劑 +7 | ^O^乜 2026-03-19 | 7/350 |
|
|
[考研] 材料學(xué)碩297已過四六級求調(diào)劑推薦 +11 | adaie 2026-03-19 | 11/550 |
|
|
[考研] 一志愿武理材料工程348求調(diào)劑 +3 |  ̄^ ̄゜汗 2026-03-19 | 4/200 |
|
|
[考研] 一志愿吉林大學(xué)材料學(xué)碩321求調(diào)劑 +11 | Ymlll 2026-03-18 | 15/750 |
|
|
[考研] 招收調(diào)劑碩士 +4 | lidianxing 2026-03-19 | 12/600 |
|
|
[考研] 081700化工學(xué)碩調(diào)劑 +3 | 【1】 2026-03-16 | 3/150 |
|
|
[考研] 0703化學(xué)調(diào)劑 +4 | 18889395102 2026-03-18 | 4/200 |
|
|
[考研] 311求調(diào)劑 +4 | 冬十三 2026-03-18 | 4/200 |
|
|
[考研] 344求調(diào)劑 +6 | knight344 2026-03-16 | 7/350 |
|
|
[考研] 材料專碩306英一數(shù)二 +10 | z1z2z3879 2026-03-16 | 13/650 |
|
|
[考研] 070300化學(xué)319求調(diào)劑 +6 | 錦鯉0909 2026-03-17 | 6/300 |
|
|
[考研] 301求調(diào)劑 +9 | yy要上岸呀 2026-03-17 | 9/450 |
|
|
[考研] 一志愿蘇州大學(xué)材料工程(085601)專碩有科研經(jīng)歷三項(xiàng)國獎兩個實(shí)用型專利一項(xiàng)省級立項(xiàng) +6 | 大火山小火山 2026-03-16 | 8/400 |
|
|
[考研] 0703化學(xué)調(diào)劑 290分有科研經(jīng)歷,論文在投 +7 | 膩膩gk 2026-03-14 | 7/350 |
|
|
[考研] 288求調(diào)劑 +4 | 奇點(diǎn)0314 2026-03-14 | 4/200 |
|
|
[考研] 080500,材料學(xué)碩302分求調(diào)劑學(xué)校 +4 | 初識可樂 2026-03-14 | 5/250 |
|
|
[考研] 一志愿哈工大材料324分求調(diào)劑 +5 | 閆旭東 2026-03-14 | 5/250 |
|