我在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
类函数未被调用且未被执行。
备注: -
TheDriver.ProcessCommand(&TheDriver,lpszKeyCombo)
调用DriverCallBack类函数,则调用函数但不执行windows命令。问:请告诉我错误在哪里?