未验证 提交 3cb69994 编写于 作者: J Jack Li 提交者: GitHub

Merge pull request #84 from amchii/feat/message-deduplication

Feat/message deduplication
......@@ -14,11 +14,15 @@ repos:
- -i
- --style=file
- --fallback-style=none
files: |
(?x)^(
.*?\.cpp|
.*?\.c|
.*?\.h
)
files: |
exclude: |
(?x)^(
.*?\.cpp|
.*?\.c|
.*?\.h
)
\ No newline at end of file
.*?_i\.h|
.*?_p\.c
)
......@@ -8,17 +8,20 @@
// CRobotEvent
STDMETHODIMP CRobotEvent::CPostMessage(DWORD pid,int msgtype,VARIANT* msg, int* __result)
STDMETHODIMP CRobotEvent::CPostMessage(DWORD pid, int msgtype, unsigned long long msgid, VARIANT *msg, int *__result)
{
// TODO: 在此处添加实现代码
// 将收到的消息广播给所有用户
switch (msgtype) {
case WX_MESSAGE: {
Fire_OnGetMessageEvent(pid, msg);
switch (msgtype)
{
case WX_MESSAGE:
{
Fire_OnGetMessageEvent(pid, msgid, msg);
break;
}
case WX_LOG_MESSAGE:{
case WX_LOG_MESSAGE:
{
break;
}
default:
......@@ -32,7 +35,7 @@ STDMETHODIMP CRobotEvent::CPostMessage(DWORD pid,int msgtype,VARIANT* msg, int*
* \param pid 微信PID
* \param cookie Cookie
*/
STDMETHODIMP CRobotEvent::CRegisterWxPidWithCookie(DWORD pid, DWORD cookie, int* __result)
STDMETHODIMP CRobotEvent::CRegisterWxPidWithCookie(DWORD pid, DWORD cookie, int *__result)
{
WxPidToEventCookie[pid].insert(cookie);
*__result = 0;
......
// RobotEvent.h: CRobotEvent 的声明
#pragma once
#include "resource.h" // 主符号
#include "resource.h" // 主符号
#include "WeChatRobotCOM_i.h"
#include "_IRobotEventEvents_CP.h"
using namespace ATL;
// CRobotEvent
class ATL_NO_VTABLE CRobotEvent :
public CComObjectRootEx<CComMultiThreadModel>,
public CComCoClass<CRobotEvent, &CLSID_RobotEvent>,
public IConnectionPointContainerImpl<CRobotEvent>,
public CProxy_IRobotEventEvents<CRobotEvent>,
public IDispatchImpl<IRobotEvent, &IID_IRobotEvent, &LIBID_WeChatRobotCOMLib, /*wMajor =*/ 1, /*wMinor =*/ 0>
class ATL_NO_VTABLE CRobotEvent : public CComObjectRootEx<CComMultiThreadModel>,
public CComCoClass<CRobotEvent, &CLSID_RobotEvent>,
public IConnectionPointContainerImpl<CRobotEvent>,
public CProxy_IRobotEventEvents<CRobotEvent>,
public IDispatchImpl<IRobotEvent, &IID_IRobotEvent, &LIBID_WeChatRobotCOMLib, /*wMajor =*/1, /*wMinor =*/0>
{
public:
CRobotEvent()
{
}
DECLARE_REGISTRY_RESOURCEID(107)
DECLARE_CLASSFACTORY_SINGLETON(CRobotEvent)
CRobotEvent()
{
}
BEGIN_COM_MAP(CRobotEvent)
COM_INTERFACE_ENTRY(IRobotEvent)
COM_INTERFACE_ENTRY(IDispatch)
COM_INTERFACE_ENTRY(IConnectionPointContainer)
END_COM_MAP()
DECLARE_REGISTRY_RESOURCEID(107)
DECLARE_CLASSFACTORY_SINGLETON(CRobotEvent)
BEGIN_CONNECTION_POINT_MAP(CRobotEvent)
CONNECTION_POINT_ENTRY(__uuidof(_IRobotEventEvents))
END_CONNECTION_POINT_MAP()
BEGIN_COM_MAP(CRobotEvent)
COM_INTERFACE_ENTRY(IRobotEvent)
COM_INTERFACE_ENTRY(IDispatch)
COM_INTERFACE_ENTRY(IConnectionPointContainer)
END_COM_MAP()
BEGIN_CONNECTION_POINT_MAP(CRobotEvent)
CONNECTION_POINT_ENTRY(__uuidof(_IRobotEventEvents))
END_CONNECTION_POINT_MAP()
DECLARE_PROTECT_FINAL_CONSTRUCT()
DECLARE_PROTECT_FINAL_CONSTRUCT()
HRESULT FinalConstruct()
{
return S_OK;
}
HRESULT FinalConstruct()
{
return S_OK;
}
void FinalRelease()
{
}
void FinalRelease()
{
}
public:
STDMETHOD(CPostMessage)(DWORD pid, int msgtype, VARIANT* msg, int* __result);
STDMETHOD(CRegisterWxPidWithCookie)(DWORD pid, DWORD cookie, int* __result);
STDMETHOD(CPostMessage)
(DWORD pid, int msgtype, unsigned long long msgid, VARIANT *msg, int *__result);
STDMETHOD(CRegisterWxPidWithCookie)
(DWORD pid, DWORD cookie, int *__result);
};
OBJECT_ENTRY_AUTO(__uuidof(RobotEvent), CRobotEvent)
......@@ -68,7 +68,7 @@ interface IWeChatRobot : IDispatch
]
interface IRobotEvent : IDispatch
{
[id(1), helpstring("用于微信主动推送消息")] HRESULT CPostMessage([in] DWORD pid, [in] int msgtype, [in] VARIANT* msg, [out, retval] int* __result);
[id(1), helpstring("用于微信主动推送消息")] HRESULT CPostMessage([in] DWORD pid, [in] int msgtype,[in] unsigned long long msgid, [in] VARIANT* msg, [out, retval] int* __result);
[id(2), helpstring("用于客户端通过微信PID注册消息接收服务")] HRESULT CRegisterWxPidWithCookie([in] DWORD pid, [in] DWORD cookie, [out, retval] int* __result);
};
[
......
......@@ -245,6 +245,7 @@
<ClInclude Include="targetver.h" />
<ClInclude Include="SearchContact.h" />
<ClInclude Include="templatefunc.h" />
<ClInclude Include="utils.h" />
<ClInclude Include="VerifyFriendApply.h" />
<ClInclude Include="WeChatRobot.h" />
<ClInclude Include="WeChatRobotCOM_i.h" />
......
......@@ -238,6 +238,9 @@
<ClInclude Include="templatefunc.h">
<Filter>template</Filter>
</ClInclude>
<ClInclude Include="utils.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="WeChatRobotCOM.cpp">
......
......@@ -5,4 +5,7 @@
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
<LocalDebuggerWorkingDirectory>D:\VS2019C++\MyWeChatRobot\Debug\</LocalDebuggerWorkingDirectory>
</PropertyGroup>
<PropertyGroup>
<ShowAllFiles>false</ShowAllFiles>
</PropertyGroup>
</Project>
\ No newline at end of file
......@@ -845,6 +845,7 @@ EXTERN_C const IID IID_IRobotEvent;
virtual /* [helpstring][id] */ HRESULT STDMETHODCALLTYPE CPostMessage(
/* [in] */ DWORD pid,
/* [in] */ int msgtype,
/* [in] */ unsigned long long msgid,
/* [in] */ VARIANT *msg,
/* [retval][out] */ int *__result) = 0;
......@@ -915,6 +916,7 @@ EXTERN_C const IID IID_IRobotEvent;
IRobotEvent * This,
/* [in] */ DWORD pid,
/* [in] */ int msgtype,
/* [in] */ unsigned long long msgid,
/* [in] */ VARIANT *msg,
/* [retval][out] */ int *__result);
......@@ -960,8 +962,8 @@ EXTERN_C const IID IID_IRobotEvent;
( (This)->lpVtbl -> Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) )
#define IRobotEvent_CPostMessage(This,pid,msgtype,msg,__result) \
( (This)->lpVtbl -> CPostMessage(This,pid,msgtype,msg,__result) )
#define IRobotEvent_CPostMessage(This,pid,msgtype,msgid,msg,__result) \
( (This)->lpVtbl -> CPostMessage(This,pid,msgtype,msgid,msg,__result) )
#define IRobotEvent_CRegisterWxPidWithCookie(This,pid,cookie,__result) \
( (This)->lpVtbl -> CRegisterWxPidWithCookie(This,pid,cookie,__result) )
......
......@@ -49,7 +49,7 @@
#include "WeChatRobotCOM_i.h"
#define TYPE_FORMAT_STRING_SIZE 1239
#define PROC_FORMAT_STRING_SIZE 2179
#define PROC_FORMAT_STRING_SIZE 2185
#define EXPR_FORMAT_STRING_SIZE 1
#define TRANSMIT_AS_TABLE_SIZE 0
#define WIRE_MARSHAL_TABLE_SIZE 2
......@@ -2019,11 +2019,11 @@ static const WeChatRobotCOM_MIDL_PROC_FORMAT_STRING WeChatRobotCOM__MIDL_ProcFor
0x6c, /* Old Flags: object, Oi2 */
/* 2078 */ NdrFcLong( 0x0 ), /* 0 */
/* 2082 */ NdrFcShort( 0x7 ), /* 7 */
/* 2084 */ NdrFcShort( 0x18 ), /* x86 Stack size/offset = 24 */
/* 2086 */ NdrFcShort( 0x10 ), /* 16 */
/* 2084 */ NdrFcShort( 0x20 ), /* x86 Stack size/offset = 32 */
/* 2086 */ NdrFcShort( 0x20 ), /* 32 */
/* 2088 */ NdrFcShort( 0x24 ), /* 36 */
/* 2090 */ 0x46, /* Oi2 Flags: clt must size, has return, has ext, */
0x5, /* 5 */
0x6, /* 6 */
/* 2092 */ 0x8, /* 8 */
0x45, /* Ext Flags: new corr desc, srv corr check, has range on conformance */
/* 2094 */ NdrFcShort( 0x0 ), /* 0 */
......@@ -2044,69 +2044,76 @@ static const WeChatRobotCOM_MIDL_PROC_FORMAT_STRING WeChatRobotCOM__MIDL_ProcFor
/* 2110 */ 0x8, /* FC_LONG */
0x0, /* 0 */
/* Parameter msg */
/* Parameter msgid */
/* 2112 */ NdrFcShort( 0x10b ), /* Flags: must size, must free, in, simple ref, */
/* 2112 */ NdrFcShort( 0x48 ), /* Flags: in, base type, */
/* 2114 */ NdrFcShort( 0xc ), /* x86 Stack size/offset = 12 */
/* 2116 */ NdrFcShort( 0x4cc ), /* Type Offset=1228 */
/* 2116 */ 0xb, /* FC_HYPER */
0x0, /* 0 */
/* Parameter msg */
/* 2118 */ NdrFcShort( 0x10b ), /* Flags: must size, must free, in, simple ref, */
/* 2120 */ NdrFcShort( 0x14 ), /* x86 Stack size/offset = 20 */
/* 2122 */ NdrFcShort( 0x4cc ), /* Type Offset=1228 */
/* Parameter __result */
/* 2118 */ NdrFcShort( 0x2150 ), /* Flags: out, base type, simple ref, srv alloc size=8 */
/* 2120 */ NdrFcShort( 0x10 ), /* x86 Stack size/offset = 16 */
/* 2122 */ 0x8, /* FC_LONG */
/* 2124 */ NdrFcShort( 0x2150 ), /* Flags: out, base type, simple ref, srv alloc size=8 */
/* 2126 */ NdrFcShort( 0x18 ), /* x86 Stack size/offset = 24 */
/* 2128 */ 0x8, /* FC_LONG */
0x0, /* 0 */
/* Return value */
/* 2124 */ NdrFcShort( 0x70 ), /* Flags: out, return, base type, */
/* 2126 */ NdrFcShort( 0x14 ), /* x86 Stack size/offset = 20 */
/* 2128 */ 0x8, /* FC_LONG */
/* 2130 */ NdrFcShort( 0x70 ), /* Flags: out, return, base type, */
/* 2132 */ NdrFcShort( 0x1c ), /* x86 Stack size/offset = 28 */
/* 2134 */ 0x8, /* FC_LONG */
0x0, /* 0 */
/* Procedure CRegisterWxPidWithCookie */
/* 2130 */ 0x33, /* FC_AUTO_HANDLE */
/* 2136 */ 0x33, /* FC_AUTO_HANDLE */
0x6c, /* Old Flags: object, Oi2 */
/* 2132 */ NdrFcLong( 0x0 ), /* 0 */
/* 2136 */ NdrFcShort( 0x8 ), /* 8 */
/* 2138 */ NdrFcShort( 0x14 ), /* x86 Stack size/offset = 20 */
/* 2140 */ NdrFcShort( 0x10 ), /* 16 */
/* 2142 */ NdrFcShort( 0x24 ), /* 36 */
/* 2144 */ 0x44, /* Oi2 Flags: has return, has ext, */
/* 2138 */ NdrFcLong( 0x0 ), /* 0 */
/* 2142 */ NdrFcShort( 0x8 ), /* 8 */
/* 2144 */ NdrFcShort( 0x14 ), /* x86 Stack size/offset = 20 */
/* 2146 */ NdrFcShort( 0x10 ), /* 16 */
/* 2148 */ NdrFcShort( 0x24 ), /* 36 */
/* 2150 */ 0x44, /* Oi2 Flags: has return, has ext, */
0x4, /* 4 */
/* 2146 */ 0x8, /* 8 */
/* 2152 */ 0x8, /* 8 */
0x41, /* Ext Flags: new corr desc, has range on conformance */
/* 2148 */ NdrFcShort( 0x0 ), /* 0 */
/* 2150 */ NdrFcShort( 0x0 ), /* 0 */
/* 2152 */ NdrFcShort( 0x0 ), /* 0 */
/* 2154 */ NdrFcShort( 0x0 ), /* 0 */
/* 2156 */ NdrFcShort( 0x0 ), /* 0 */
/* 2158 */ NdrFcShort( 0x0 ), /* 0 */
/* Parameter pid */
/* 2154 */ NdrFcShort( 0x48 ), /* Flags: in, base type, */
/* 2156 */ NdrFcShort( 0x4 ), /* x86 Stack size/offset = 4 */
/* 2158 */ 0x8, /* FC_LONG */
/* 2160 */ NdrFcShort( 0x48 ), /* Flags: in, base type, */
/* 2162 */ NdrFcShort( 0x4 ), /* x86 Stack size/offset = 4 */
/* 2164 */ 0x8, /* FC_LONG */
0x0, /* 0 */
/* Parameter cookie */
/* 2160 */ NdrFcShort( 0x48 ), /* Flags: in, base type, */
/* 2162 */ NdrFcShort( 0x8 ), /* x86 Stack size/offset = 8 */
/* 2164 */ 0x8, /* FC_LONG */
/* 2166 */ NdrFcShort( 0x48 ), /* Flags: in, base type, */
/* 2168 */ NdrFcShort( 0x8 ), /* x86 Stack size/offset = 8 */
/* 2170 */ 0x8, /* FC_LONG */
0x0, /* 0 */
/* Parameter __result */
/* 2166 */ NdrFcShort( 0x2150 ), /* Flags: out, base type, simple ref, srv alloc size=8 */
/* 2168 */ NdrFcShort( 0xc ), /* x86 Stack size/offset = 12 */
/* 2170 */ 0x8, /* FC_LONG */
/* 2172 */ NdrFcShort( 0x2150 ), /* Flags: out, base type, simple ref, srv alloc size=8 */
/* 2174 */ NdrFcShort( 0xc ), /* x86 Stack size/offset = 12 */
/* 2176 */ 0x8, /* FC_LONG */
0x0, /* 0 */
/* Return value */
/* 2172 */ NdrFcShort( 0x70 ), /* Flags: out, return, base type, */
/* 2174 */ NdrFcShort( 0x10 ), /* x86 Stack size/offset = 16 */
/* 2176 */ 0x8, /* FC_LONG */
/* 2178 */ NdrFcShort( 0x70 ), /* Flags: out, return, base type, */
/* 2180 */ NdrFcShort( 0x10 ), /* x86 Stack size/offset = 16 */
/* 2182 */ 0x8, /* FC_LONG */
0x0, /* 0 */
0x0
......@@ -3146,7 +3153,7 @@ static const unsigned short IRobotEvent_FormatStringOffsetTable[] =
(unsigned short) -1,
(unsigned short) -1,
2076,
2130
2136
};
static const MIDL_STUBLESS_PROXY_INFO IRobotEvent_ProxyInfo =
......
#pragma once
#include <map>
#include <set>
#include "utils.h"
/**
* 微信PID与客户端事件ConnectionPoint的cookie的映射,客户端使用自己关心的微信PID和cookie进行注册,
......@@ -8,33 +9,37 @@
*/
map<DWORD, set<DWORD>> WxPidToEventCookie;
template<class T>
class CProxy_IRobotEventEvents :
public ATL::IConnectionPointImpl<T, &__uuidof(_IRobotEventEvents)>
template <class T>
class CProxy_IRobotEventEvents : public ATL::IConnectionPointImpl<T, &__uuidof(_IRobotEventEvents)>
{
public:
HRESULT Fire_OnGetMessageEvent(DWORD pid, VARIANT* msg)
HRESULT Fire_OnGetMessageEvent(DWORD pid, unsigned long long msgid, VARIANT *msg)
{
HRESULT hr = S_OK;
T* pThis = static_cast<T*>(this);
if (WxPidToEventCookie.count(pid)==0)
static ExpireSet es(2000);
if (!es.CheckIfDuplicatedAndAdd(msgid))
{
return hr;
}
T *pThis = dynamic_cast<T *>(this);
if (WxPidToEventCookie.count(pid) == 0)
{
return hr;
}
const set<DWORD> cookies = WxPidToEventCookie[pid];
for (DWORD cookie:cookies)
for (DWORD cookie : cookies)
{
pThis->Lock();
ATL::CComPtr<IUnknown> punkConnection=this->m_vec.GetUnknown(cookie);
ATL::CComPtr<IUnknown> punkConnection = this->m_vec.GetUnknown(cookie);
pThis->Unlock();
if (punkConnection)
{
IDispatch* pConnection = static_cast<IDispatch*>(punkConnection.p);
IDispatch *pConnection = static_cast<IDispatch *>(punkConnection.p);
if (pConnection)
{
ATL::CComVariant varResult;
DISPPARAMS params = { msg, nullptr, 1, 0 };
DISPPARAMS params = {msg, nullptr, 1, 0};
hr = pConnection->Invoke(1, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &params, &varResult, nullptr, nullptr);
}
else
......
#pragma once
#include <set>
#include <chrono>
#define CHRONO std::chrono
typedef unsigned long long ull;
/*
* 一个简单的带过期时间检查和清理的集合,interval为毫秒
* ExpireSet es(1000); // 过期时间1秒
* es.CheckIfDuplicatedAndAdd(1); true, 未重复
* es.CheckIfDuplicatedAndAdd(1); false, 重复
* After 1s;
* es.CheckIfDuplicatedAndAdd(2); 添加<2>并清理过期的元素<1>
*/
class ExpireSet
{
public:
ull interval; // 毫秒
ExpireSet(ull interval)
{
this->interval = interval;
this->expires_at = 0;
}
bool CheckIfDuplicatedAndAdd(ull id)
{
bool ok = true;
if (ids.count(id) != 0)
{
ok = false;
}
Add(id);
return ok;
}
private:
std::set<ull> ids;
ull expires_at;
void Add(ull id)
{
// 毫秒
auto now_ts = CHRONO::time_point_cast<CHRONO::milliseconds>(CHRONO::system_clock::now()).time_since_epoch().count();
#pragma warning(disable : 4018)
if (expires_at < now_ts)
{
ids.clear();
expires_at = now_ts + interval;
}
#pragma warning(default : 4018)
ids.insert(id);
}
};
......@@ -200,7 +200,7 @@ static void dealMessage(DWORD messageAddr)
VARIANT vsaValue;
vsaValue.vt = VT_ARRAY | VT_VARIANT;
V_ARRAY(&vsaValue) = psaValue;
PostComMessage(message->pid, WX_MESSAGE, &vsaValue);
PostComMessage(message->pid, WX_MESSAGE, message->msgid, &vsaValue);
#endif
HANDLE hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)SendSocketMessage, message, NULL, 0);
if (hThread)
......@@ -210,10 +210,10 @@ static void dealMessage(DWORD messageAddr)
}
/*
* 消息处理函数,根据消息缓冲区组装结构并存入容器
* messageAddr:保存消息的缓冲区地址
* return:void
*/
* 消息处理函数,根据消息缓冲区组装结构并存入容器
* messageAddr:保存消息的缓冲区地址
* return:void
*/
VOID ReceiveMessage(DWORD messagesAddr)
{
// 此处用于区别是发送的还是接收的消息
......@@ -225,8 +225,8 @@ VOID ReceiveMessage(DWORD messagesAddr)
}
/*
* HOOK的具体实现,接收到消息后调用处理函数
*/
* HOOK的具体实现,接收到消息后调用处理函数
*/
_declspec(naked) void dealReceiveMessage()
{
__asm {
......@@ -244,8 +244,8 @@ _declspec(naked) void dealReceiveMessage()
}
/*
* HOOK的具体实现,发送消息后调用处理函数
*/
* HOOK的具体实现,发送消息后调用处理函数
*/
_declspec(naked) void dealSendMessage()
{
__asm {
......@@ -262,9 +262,9 @@ _declspec(naked) void dealSendMessage()
}
/*
* 开始接收消息HOOK
* return:void
*/
* 开始接收消息HOOK
* return:void
*/
VOID HookReceiveMessage(int port)
{
SRVPORT = port;
......@@ -283,9 +283,9 @@ VOID HookReceiveMessage(int port)
}
/*
* 停止接收消息HOOK
* return:void
*/
* 停止接收消息HOOK
* return:void
*/
VOID UnHookReceiveMessage()
{
SRVPORT = 0;
......
......@@ -10,21 +10,20 @@
// CComModule m_commodule;
class CSink :
public CComObjectRoot,
public _IRobotEventEvents
class CSink : public CComObjectRoot,
public _IRobotEventEvents
{
BEGIN_COM_MAP(CSink)
COM_INTERFACE_ENTRY(IDispatch)
COM_INTERFACE_ENTRY(_IRobotEventEvents)
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)
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);
......@@ -33,16 +32,18 @@ public:
}
};
BOOL PostComMessage(DWORD pid, int msgtype, VARIANT* msg) {
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)) {
hr = ::CoCreateInstance(CLSID_RobotEvent, NULL, CLSCTX_ALL, IID_IRobotEvent, (LPVOID *)&spRobotEvent);
if (SUCCEEDED(hr))
{
/*
// 这段逻辑用于回调到微信
CComObject<CSink>* sinkptr = nullptr;
......@@ -51,12 +52,13 @@ BOOL PostComMessage(DWORD pid, int msgtype, VARIANT* msg) {
AtlAdvise(spRobotEvent, sinkptr, __uuidof(_IRobotEventEvents), &cookies);
*/
int __result = 0;
spRobotEvent->CPostMessage(pid, msgtype, msg, &__result);
spRobotEvent->CPostMessage(pid, msgtype, msgid, msg, &__result);
}
else {
else
{
return false;
}
CoUninitialize();
return true;
}
#endif // !USE_COM
\ No newline at end of file
#endif // !USE_COM
#pragma once
#include<windows.h>
#include <windows.h>
#define USE_COM
#include<comutil.h>
#include <comutil.h>
#pragma comment(lib, "comsuppw.lib")
#define WX_MESSAGE 1
#define WX_LOG_MESSAGE 2
BOOL PostComMessage(DWORD pid, int msgtype,VARIANT* msg);
\ No newline at end of file
BOOL PostComMessage(DWORD pid, int msgtype, unsigned long long msgid, VARIANT *msg);
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册