forked from ljc545w/ComWeChatRobot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomclient.cpp
More file actions
65 lines (58 loc) · 1.91 KB
/
Copy pathcomclient.cpp
File metadata and controls
65 lines (58 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "pch.h"
#ifdef USE_COM
#include <atlbase.h>
#include <atlcom.h>
#include "../CWeChatRobot/WeChatRobotCOM_i.h"
#include "../CWeChatRobot/WeChatRobotCOM_i.c"
#include <iostream>
#include <thread>
// CComModule m_commodule;
class CSink : public CComObjectRoot,
public _IRobotEventEvents
{
BEGIN_COM_MAP(CSink)
COM_INTERFACE_ENTRY(IDispatch)
COM_INTERFACE_ENTRY(_IRobotEventEvents)
END_COM_MAP()
public:
virtual ~CSink() {}
STDMETHODIMP GetTypeInfoCount(UINT *pctinfo) { return E_NOTIMPL; }
STDMETHODIMP GetTypeInfo(UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo) { return E_NOTIMPL; }
STDMETHODIMP GetIDsOfNames(REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId) { return E_NOTIMPL; }
STDMETHODIMP Invoke(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
{
#ifdef _DEBUG
printf("sink, id: %d, parm: %f", dispIdMember, pDispParams->rgvarg[0].fltVal);
#endif
return S_OK;
}
};
BOOL PostComMessage(DWORD pid, int msgtype, unsigned long long msgid, VARIANT *msg)
{
HRESULT hr = S_OK;
hr = CoInitializeEx(0, COINIT_APARTMENTTHREADED);
if (FAILED(hr))
return false;
CComPtr<IRobotEvent> spRobotEvent;
hr = ::CoCreateInstance(CLSID_RobotEvent, NULL, CLSCTX_ALL, IID_IRobotEvent, (LPVOID *)&spRobotEvent);
if (SUCCEEDED(hr))
{
/*
// 这段逻辑用于回调到微信
CComObject<CSink>* sinkptr = nullptr;
CComObject<CSink>::CreateInstance(&sinkptr);
DWORD cookies = 0;
AtlAdvise(spRobotEvent, sinkptr, __uuidof(_IRobotEventEvents), &cookies);
*/
int __result = 0;
spRobotEvent->CPostMessage(pid, msgtype, msgid, msg, &__result);
}
else
{
CoUninitialize();
return false;
}
CoUninitialize();
return true;
}
#endif // !USE_COM