求助:IRapiSinK的问题,搞不懂啊,懂的进来看看!进来的有分,解决的高分(60分-80分)相送

xin_zzq1 2009-03-24 01:19:40
我调用IRAPIDesktop类成员HRESULT Advise(IRAPISink* pISink,DWORD* pdwContext);去注册连接事件;但不知道Advise()函数里的第1个参数pISink指针怎样取得,懂的帮帮忙啊

DWORD dwtext=NOERROR;
HRESULT hr = S_OK;
// Initialize COM.
//hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
clearSession();
addNewInfo(_T("Try to connect a device....."));
CoInitialize(NULL);
// Create an instance of the IRAPIDesktop interface.
hr = CoCreateInstance(CLSID_RAPI,
NULL,
CLSCTX_INPROC_SERVER,
IID_IRAPIDesktop,
(void**)&mpIRapiDesktop);

if (hr ==0 && mpIRapiDesktop)
{
addNewInfo(_T("CoCreateInstance success"));
}else{
addNewInfo(_T("CoCreateInstance failure"));
return ;
}

hr=mpIRapiDesktop->Advise(mpIRapiSink,&dwtext);
...全文
125 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
xin_zzq1 2009-03-25
  • 打赏
  • 举报
回复
第一次搞~一点头绪都没啊
xin_zzq1 2009-03-25
  • 打赏
  • 举报
回复
有高手知道IRAPISink怎么样实现吗?说下大概也可以!!
xin_zzq1 2009-03-24
  • 打赏
  • 举报
回复
谢谢啊·我还以为IRAPISink系统提供呢,
jameshooo 2009-03-24
  • 打赏
  • 举报
回复
IRAPISink必须由你自己实现,然后作为第一个参数。你不实现怎么接收通知?
oyljerry 2009-03-24
  • 打赏
  • 举报
回复
查找你对应的连接点信息..然后连接
void CConnClientDlg::OnConnect()
{
if(m_dwCookie!=0)
{
return;
}

if(m_pIUnknown!=NULL)
{
HRESULT hResult;
hResult = m_pIUnknown->QueryInterface(IID_IConnectionPointContainer,
(void**)&pConnPtCont);
if(FAILED(hResult))
{
::AfxMessageBox("不能获取对象的IConnectionPointContainer接口!");
return;
}

ASSERT(pConnPtCont!=NULL);

hResult = pConnPtCont->FindConnectionPoint(IID_IEventSink,&pConnPt);
if(FAILED(hResult))
{
pConnPtCont->Release();
::AfxMessageBox("不能获取对象的IEventSink连接点接口!");
return;
}

ASSERT(pConnPt!=NULL);

//获取事件接收器指针

IUnknown* pIEventSink;

m_xEventSink.QueryInterface(IID_IUnknown,(void**)&pIEventSink);

//通过连接点接口的Advise方法将事件接收器指针传给可连接对象

if(SUCCEEDED(pConnPt->Advise(pIEventSink,&m_dwCookie)))
{
::AfxMessageBox("与可连接对象ConnObject建立连接成功!");
}
else
{
::AfxMessageBox("不能与ConnObject建立连接!");
}
pConnPt->Release();
pConnPtCont->Release();
return;
}
xin_zzq1 2009-03-24
  • 打赏
  • 举报
回复
上面的实现我知道,但我现在要实现的Advise函数就是不清楚第一个参数IRAPISink×怎么获得。怎么样取得IRAPSink这个类的初始值
oyljerry 2009-03-24
  • 打赏
  • 举报
回复
Use the following steps to initialize RAPI2 and create a session with a connected device.

1. Instantiate the IRAPIDesktop interface using COM's CoInitializeEx method.
2. Call IRAPIDesktop::Advise to register your applications implementation of the IRAPISink interface. This will alert your application when a device connects.
3. Once a device has connected, call IRAPIDesktop::EnumDevices to obtain an instance of the IRAPIEnumDevices interface.
4. Call IRAPIEnumDevices::Next to obtain an instance of the IRAPIDevice interface. This interface can be used to query for information about the selected device.
5. Call IRAPIDevice::CreateSession to establish a session with the selected device.
6. Initialize the underlying communications layer for the session by calling IRAPISession::CeRapiInit.
7. Call methods of the IRAPISession interface to perform operations on the connected device.
oyljerry 2009-03-24
  • 打赏
  • 举报
回复
int _tmain(int argc, _TCHAR* argv[])
{
HRESULT hr = S_OK;

// Initialize COM.
hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);

// Create an instance of the IRAPIDesktop interface.
IRAPIDesktop *pIRapiDesktop = NULL;
hr = CoCreateInstance(CLSID_RAPI,
NULL,
CLSCTX_INPROC_SERVER,
IID_IRAPIDesktop,
(void**)&pIRapiDesktop);

// Call EnumDevices to obtain an enumeration of connected devices.
IRAPIEnumDevices *pIRapiEnumDevices = NULL;
if (SUCCEEDED(hr) && pIRapiDesktop)
{
hr = pIRapiDesktop->EnumDevices(&pIRapiEnumDevices);
}

// Call Next to get an interface to the device.
IRAPIDevice *pIRapiDevice = NULL;
if (SUCCEEDED(hr) && pIRapiEnumDevices)
{
hr = pIRapiEnumDevices->Next(&pIRapiDevice);
}

// Call CreateSession to establish a session with the connected device.
IRAPISession *pIRapiSession = NULL;
if (SUCCEEDED(hr) && pIRapiDevice)
{
hr=pIRapiDevice->CreateSession(&pIRapiSession);
}

if (SUCCEEDED(hr) && pIRapiSession)
{
// Call CeRapiInit before you call any other IRAPISession methods.
hr = pIRapiSession->CeRapiInit();
if (FAILED(hr))
{
hr = pIRapiSession->CeRapiGetError();
}
else
{
// Make calls on the session object
BOOL bRet = pIRapiSession->CeCheckPassword(TEXT("Password"));

if (!bRet)
{
hr = pIRapiSession->CeRapiGetError();
if(SUCCEEDED(hr)) // If no rapi errors, call CeGetLastError for the error on device
{
DWORD dwErr = pIRapiSession->CeGetLastError();
}
}
}
}

return 0;

}
eagerle01 2009-03-24
  • 打赏
  • 举报
回复
xin_zzq1 2009-03-24
  • 打赏
  • 举报
回复
顶起来!不能沉啊!有高手懂的帮帮!
chuengchuenghq 2009-03-24
  • 打赏
  • 举报
回复
坐在杂总杂总在~!
xin_zzq1 2009-03-24
  • 打赏
  • 举报
回复
自己UP!

3,245

社区成员

发帖
与我相关
我的任务
社区描述
ATL,Active Template Library活动(动态)模板库,是一种微软程序库,支持利用C++语言编写ASP代码以及其它ActiveX程序。
社区管理员
  • ATL/ActiveX/COM社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧