24小时热门版块排行榜    

查看: 2377  |  回复: 15
当前只显示满足指定条件的回帖,点击这里查看本话题的所有回帖

leafmavis

木虫 (文坛精英)

[求助] VC++中如何应用porttalk

有个实验,是控制一个电动台做旋转运动(这部分VC++源代码由产品的制造商提供),从而给实验动物刺激,同时采集动物的脑电。我们想在旋转运动的开始和结束的时候,分别给并口一秒钟的高电平,以便在脑电信号采集系统上打上同步标记。我们做了一个并口的流水灯以验证并口操作的可靠性。用C++bulider 6.0时,利用PortTalk能控制流水灯工作;但用VC++ 6.0时,报错。因电动台的源码是VC++ 6.0,所以想请教高手。谢谢!
     下面是单纯的并口操作验证:
1、用C++bulider时,在工程目录下拷进这两个文件:PortTalk.sys; PortTalk.h。在Form中添加一个按键(功能为:使并口输出脉宽为1秒的高电平),并在Form中添加了并口初始化(因为计算机开机时并口各数据位是高电平,初始化就是将所有数据位置低)。程序运行正常,流水灯的开闭正常。

2、用VC++时,操作同上,但编译时报错。想请问一下,在VC++下如何使用PortTalk ?网上没说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)
回复此楼
春如杯中水
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

sudo

木虫 (正式写手)

【答案】应助回帖

★ ★
余泽成(金币+2): 谢谢参与应助! 2011-05-04 22:52:12
leafmavis(金币+7): 谢谢热情相助,VS2010下编译通过的h文件,用C++6.0还有14个错误,我再仔细研究下,谢谢! 2011-05-05 09:12:29
界面的部分都没有问题(话说这么简单的东西直接用console application不好嘛)

于是楼主能不能贴一下PortTalk.h这个文件的内容呢?

看样子像是把函数定义放到.h文件里面了(不是类模板等特殊情况的话这么做其实不好的),恩,所以先看看吧

PS:
贴代码的时候,放到
CODE:
这个里面

会比较好看一点
4楼2011-05-04 10:27:47
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
查看全部 16 个回答

yalefield

金虫 (文坛精英)

老汉一枚

【答案】应助回帖

★ ★
余泽成(金币+2): 谢谢参与应助! 2011-05-04 22:51:48
leafmavis(金币+2): 谢谢热情相助 2011-05-05 09:08:35
(1) 在您用到PortTalk中的函数时,首先要
#include "PortTalk.h"

(2) 等下一步您遇到更多错误时,再说咯。
2楼2011-05-04 08:42:37
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

leafmavis

木虫 (文坛精英)

谢谢您的回复,不过头文件是加上了的。附上C++源码,除 #include "PortTalk.h" 和最后面的按键响应函数,其他的都是自动生成的。请帮忙分析,谢谢!


// 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();  //关闭地址操作
}
春如杯中水
3楼2011-05-04 09:12:39
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

yalefield

金虫 (文坛精英)

老汉一枚


余泽成(金币+1): 谢谢参与应助! 2011-05-04 22:52:22
就是用<code>把代码部分括起来
5楼2011-05-04 10:49:08
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 0857调剂 +4 一ll半 2026-02-28 5/250 2026-03-02 02:33 by 908055542
[考研] 284求调剂 +8 天下熯 2026-02-28 8/400 2026-03-02 00:15 by 暮雨星晴
[考研] 求调剂 +5 yunziaaaaa 2026-03-01 6/300 2026-03-01 23:57 by ccp273206157
[考研] 材料化工调剂 +12 今夏不夏 2026-03-01 13/650 2026-03-01 23:32 by L135790
[考研] 材料学硕318求调剂 +5 February_Feb 2026-03-01 5/250 2026-03-01 23:31 by L135790
[考研] 0856材料与化工,270求调剂 +6 YXCT 2026-03-01 6/300 2026-03-01 23:21 by 向上的胖东
[考研] 江苏省农科院招调剂1名 +3 Qwertyuop 2026-03-01 3/150 2026-03-01 23:18 by aaadim
[考研] 0856调剂 +5 刘梦微 2026-02-28 5/250 2026-03-01 22:30 by wang_dand
[考研] 275求调剂 +3 明远求学 2026-03-01 3/150 2026-03-01 22:29 by 刘兵
[考研] 299求调剂 +3 Y墨明棋妙Y 2026-02-28 5/250 2026-03-01 21:01 by tangxiaotian
[考研] 0856材料求调剂 +11 hyf hyf hyf 2026-02-28 12/600 2026-03-01 18:57 by 18137688336
[考研] 材料学调剂 +9 提神豆沙包 2026-02-28 11/550 2026-03-01 18:15 by ms629
[考研] 化工专硕342,一志愿大连理工大学,求调剂 +3 kyf化工 2026-02-28 4/200 2026-03-01 16:49 by yywzz
[考研] 求调剂 +6 repeatt?t 2026-02-28 6/300 2026-03-01 14:37 by Sakura绘
[考研] 寻找调剂 +4 LYidhsjabdj 2026-02-28 4/200 2026-03-01 10:56 by sunny81
[硕博家园] 2025届双非化工硕士毕业,申博 +3 更多的是 2026-02-27 4/200 2026-03-01 10:04 by ztg729
[论文投稿] 求助coordination chemistry reviews 的写作模板 10+3 ljplijiapeng 2026-02-27 4/200 2026-03-01 09:07 by babero
[论文投稿] Optics letters投稿被拒求助 30+3 luckyry 2026-02-26 4/200 2026-03-01 09:06 by babero
[考研] 085600材料工程一志愿中科大总分312求调剂 +8 吃宵夜1 2026-02-28 10/500 2026-02-28 20:27 by L135790
[考研] 276求调剂 +3 路lyh123 2026-02-28 4/200 2026-02-28 19:45 by 路lyh123
信息提示
请填处理意见