| 5 | 1/1 | 返回列表 |
| 查看: 2430 | 回復: 15 | ||
| 當前只顯示滿足指定條件的回帖,點擊這里查看本話題的所有回帖 | ||
leafmavis木蟲 (文壇精英)
|
[求助]
VC++中如何應用porttalk
|
|
|
有個實驗,是控制一個電動臺做旋轉運動(這部分VC++源代碼由產(chǎn)品的制造商提供),從而給實驗動物刺激,同時采集動物的腦電。我們想在旋轉運動的開始和結束的時候,分別給并口一秒鐘的高電平,以便在腦電信號采集系統(tǒng)上打上同步標記。我們做了一個并口的流水燈以驗證并口操作的可靠性。用C++bulider 6.0時,利用PortTalk能控制流水燈工作;但用VC++ 6.0時,報錯。因電動臺的源碼是VC++ 6.0,所以想請教高手。謝謝! 下面是單純的并口操作驗證: 1、用C++bulider時,在工程目錄下拷進這兩個文件:PortTalk.sys; PortTalk.h。在Form中添加一個按鍵(功能為:使并口輸出脈寬為1秒的高電平),并在Form中添加了并口初始化(因為計算機開機時并口各數(shù)據(jù)位是高電平,初始化就是將所有數(shù)據(jù)位置低)。程序運行正常,流水燈的開閉正常。 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) |


金蟲 (文壇精英)
老漢一枚
木蟲 (文壇精英)
|
謝謝您的回復,不過頭文件是加上了的。附上C++源碼,除 #include "PortTalk.h" 和最后面的按鍵響應函數(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(); //關閉地址操作 } |

木蟲 (正式寫手)
|
界面的部分都沒有問題(話說這么簡單的東西直接用console application不好嘛) 于是樓主能不能貼一下PortTalk.h這個文件的內(nèi)容呢? 看樣子像是把函數(shù)定義放到.h文件里面了(不是類模板等特殊情況的話這么做其實不好的),恩,所以先看看吧 PS: 貼代碼的時候,放到 會比較好看一點 |
| 最具人氣熱帖推薦 [查看全部] | 作者 | 回/看 | 最后發(fā)表 | |
|---|---|---|---|---|
|
[有機交流]
高溫高壓反應求助
10+4
|
chibby 2026-03-25 | 4/200 |
|
|---|---|---|---|---|
|
[考研] 學碩274求調(diào)劑 +5 | Li李魚 2026-03-26 | 5/250 |
|
|
[考研] 一志愿上海理工能源動力(085800)310分求調(diào)劑 +3 | zhangmingc 2026-03-27 | 4/200 |
|
|
[考研] 08開頭275求調(diào)劑 +4 | 拉誰不重要 2026-03-26 | 4/200 |
|
|
[考研] 化學308分求調(diào)劑 +8 | 你好明天你好 2026-03-23 | 9/450 |
|
|
[考研] 22408 359分調(diào)劑 +3 | Qshers 2026-03-27 | 3/150 |
|
|
[論文投稿] Journal of Mechanical Science and Technology +3 | Russ_ss 2026-03-25 | 5/250 |
|
|
[考研] 081200-11408-276學碩求調(diào)劑 +3 | 崔wj 2026-03-26 | 3/150 |
|
|
[考研] 調(diào)劑求收留 +7 | 果然有我 2026-03-26 | 7/350 |
|
|
[考研] 求調(diào)劑 +5 | 蘆lty 2026-03-25 | 6/300 |
|
|
[考研] 機械學碩310分,數(shù)一英一,一志愿211本科雙非找調(diào)劑信息 +3 | @357 2026-03-25 | 3/150 |
|
|
[考研] 289求調(diào)劑 +17 | 碩星赴 2026-03-23 | 17/850 |
|
|
[考研] 一志愿北京化工大學材料與化工(085600)296求調(diào)劑 +9 | 稻妻小編 2026-03-26 | 9/450 |
|
|
[考研] 299求調(diào)劑 +4 | 15188958825 2026-03-25 | 4/200 |
|
|
[考研] 材料與化工304求B區(qū)調(diào)劑 +3 | 邱gl 2026-03-25 | 3/150 |
|
|
[考研] 306求0703調(diào)劑一志愿華中師范 +10 | 紙魚ly 2026-03-21 | 11/550 |
|
|
[論文投稿] 急發(fā)核心期刊論文 +3 | 賢達問津 2026-03-23 | 5/250 |
|
|
[考研] 293求調(diào)劑 +3 | 濤濤Wjt 2026-03-22 | 5/250 |
|
|
[考研] 生物學調(diào)劑 +5 | Surekei 2026-03-21 | 5/250 |
|
|
[考研] 一志愿南大,0703化學,分數(shù)336,求調(diào)劑 +3 | 收到VS 2026-03-21 | 3/150 |
|