VC ++中的接口继承||函数调用问题

时间:2017-08-14 09:20:27

标签: c++ visual-c++

我在VC ++中制作驱动程序。

我有包含我的界面的头文件。

我的问题是:我继承了两个接口,但我的应用程序没有调用两个接口函数。

我的实施:

devClass.h

class Driver;
class DriverCallBacks;

class Driver
{
 public:
   virtual BOOL open(LPCSTR lpszPort, DriverCallBacks *pCallBacks)=0;
   virtual DriverCallBacks * SetCallBacks(DriverCallBacks *pCallBacks)=0;
   virtual Display()=0;
}

Class DriverCallBacks
{
public:
    virtual BOOL ProcessCommand(Driver *pDriver, LPCSTR Combo)=0;
    virtual BOOL Type(Driver *pDriver, int nCount)=0;
}

DemoDriver.h

#include<devClass.h>

SampleDriver: public Driver, public DriverCallBacks
{
  public:
    DriverCallBacks *m_pCallBack;
    static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
    virtual BOOL open(LPCSTR lpszPort, DriverCallBacks *pCallBacks);
    virtual DriverCallBacks * SetCallBacks(DriverCallBacks *pCallBacks);
    virtual Display();
    virtual BOOL ProcessCommand(Driver *pDriver, LPCSTR Combo);
    virtual BOOL Type(Driver *pDriver, int nCount);
}

DemoDriver.cpp

#include"DemoDriver.h"
#define WM_KEYS_PRESS(WM_USER+1)

SampleDriver TheDriver;

extern "C" void __declspec(dllexport)GetInterface(Driver **ppDriver)
{
  *ppDriver = &TheDriver;
}

SampleDriver::SampleDriver()
{
   m_pCallBack=o;
}
BOOL SampleDriver::open(LPCSTR lpszPort, DriverCallBacks *pCallBacks)
{
    m_pCallBack=*pCallBacks;
    return TRUE;
}
BOOL SampleDriver::ProcessCommand(Driver *pDriver, LPCSTR Combo)
{
    return TRUE;
}
BOOL SampleDriver::Type(Driver *pDriver, int nCount)
{
    return TRUE;
}
DriverCallBacks * SampleDriver::SetCallBacks(DriverCallBacks *pCallBacks)
{
    m_pCallback = pCallBacks;
    DriverCallbacks * pOld = m_pCallbacks;
    return pOld;
}
LRESULT CALLBACK SampleDriver::WndProc(HWND, UINT, WPARAM, LPARAM)
{
    if(IsWindow(hWnd) && message == WM_KEYS_PRESS))
    {
        if (TheDriver.m_pCallback)
        {
            LPSTR lpszKeyCombo = (LPSTR)wParam;
            if (lpszKeyCombo && *lpszKeyCombo)
            {
                if (TheDriver.m_pCallback->ProcessCommand(&TheDriver,
                      lpszKeyCombo)== FALSE)
                {
                    //do something...
                }
            }
        }
    }
}
void SampleDriver::Display()
{
 //Displey something...
}

Driver类函数被执行但DriverCallBack类函数未被调用且未被执行。

备注: -

  1. 如果我用TheDriver.ProcessCommand(&TheDriver,lpszKeyCombo)调用DriverCallBack类函数,则调用函数但不执行windows命令。
  2. 包含windows命令的DriverCallBack函数。
  3. 问:请告诉我错误在哪里?

0 个答案:

没有答案