提交 971cd709 编写于 作者: L ljc545w

优化接收消息接口

上级 9d7462dc
......@@ -12,4 +12,6 @@
/wxRobot/bin/Debug/
/wxRobot/bin/Release/*.pdb
*/__pycache__/
packages
\ No newline at end of file
packages
mongoose.c
mongoose.h
// RobotEvent.cpp: CRobotEvent 的实现
#include "pch.h"
#include "RobotEvent.h"
// CRobotEvent
STDMETHODIMP CRobotEvent::CPostMessage(VARIANT* msg, int* __result)
{
// TODO: 在此处添加实现代码
// 将收到的消息广播给所有用户
Fire_OnGetMessageEvent(msg);
*__result = 0;
return S_OK;
}
// RobotEvent.h: CRobotEvent 的声明
#pragma once
#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>
{
public:
CRobotEvent()
{
}
DECLARE_REGISTRY_RESOURCEID(107)
DECLARE_CLASSFACTORY_SINGLETON(CRobotEvent)
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()
HRESULT FinalConstruct()
{
return S_OK;
}
void FinalRelease()
{
}
public:
STDMETHOD(CPostMessage)(VARIANT* msg, int* __result);
};
OBJECT_ENTRY_AUTO(__uuidof(RobotEvent), CRobotEvent)
HKCR
{
WeChatRobot.RobotEvent.1 = s 'RobotEvent class'
{
CLSID = s '{178001e8-5e64-4cec-8032-1de28801df55}'
}
WeChatRobot.RobotEvent = s 'RobotEvent class'
{
CurVer = s 'WeChatRobot.RobotEvent.1'
}
NoRemove CLSID
{
ForceRemove {178001e8-5e64-4cec-8032-1de28801df55} = s 'RobotEvent class'
{
ProgID = s 'WeChatRobot.RobotEvent.1'
VersionIndependentProgID = s 'WeChatRobot.RobotEvent'
ForceRemove Programmable
LocalServer32 = s '%MODULE%'
{
val ServerExecutable = s '%MODULE_RAW%'
}
TypeLib = s '{721abb35-141a-4aa2-94f2-762e2833fa6c}'
Version = s '1.0'
}
}
}
......@@ -54,6 +54,17 @@ interface IWeChatRobot : IDispatch
[id(36)] HRESULT CSendAppMsg([in] BSTR wxid, [in] BSTR appid, [out, retval] int* __result);
[id(37)] HRESULT CDeleteUser([in] BSTR wxid, [out, retval] int* __result);
};
[
object,
uuid(1a9d8d1b-d40e-4f3a-8ed4-b783e6a59830),
dual,
nonextensible,
pointer_default(unique)
]
interface IRobotEvent : IDispatch
{
[id(1), helpstring("微信主动推送消息")] HRESULT CPostMessage([in] VARIANT* msg, [out, retval] int* __result);
};
[
uuid(721abb35-141a-4aa2-94f2-762e2833fa6c),
version(1.0),
......@@ -68,6 +79,24 @@ library WeChatRobotCOMLib
{
[default] interface IWeChatRobot;
};
[
uuid(8fd26fd1-9169-4e4c-8a1d-d05093bacce5)
]
dispinterface _IRobotEventEvents
{
properties:
methods:
[id(1)] HRESULT OnGetMessageEvent(VARIANT* msg);
};
[
uuid(178001e8-5e64-4cec-8032-1de28801df55)
]
coclass RobotEvent
{
[default] interface IRobotEvent;
[default, source] dispinterface _IRobotEventEvents;
};
};
import "shobjidl.idl";
import "shobjidl.idl";
B// Microsoft Visual C++ generated resource script.
......
......@@ -225,6 +225,7 @@
<ClInclude Include="ReceiveMessage.h" />
<ClInclude Include="Resource.h" />
<ClInclude Include="robotdata.h" />
<ClInclude Include="RobotEvent.h" />
<ClInclude Include="SelfInfo.h" />
<ClInclude Include="SendAppMsg.h" />
<ClInclude Include="SendArticle.h" />
......@@ -240,6 +241,7 @@
<ClInclude Include="WeChatRobotCOM_i.h" />
<ClInclude Include="wechatver.h" />
<ClInclude Include="xdlldata.h" />
<ClInclude Include="_IRobotEventEvents_CP.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="AddBrandContact.cpp" />
......@@ -262,6 +264,7 @@
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="ReceiveMessage.cpp" />
<ClCompile Include="RobotEvent.cpp" />
<ClCompile Include="SearchContactByNet.cpp" />
<ClCompile Include="SelfInfo.cpp" />
<ClCompile Include="SendAppMsg.cpp" />
......@@ -305,6 +308,7 @@
<ResourceCompile Include="WeChatRobotCOM.rc" />
</ItemGroup>
<ItemGroup>
<None Include="RobotEvent.rgs" />
<None Include="WeChatRobot.rgs" />
<None Include="WeChatRobotCOM.rgs" />
</ItemGroup>
......
......@@ -181,6 +181,12 @@
<ClInclude Include="DeleteUser.h">
<Filter>好友相关\删除好友</Filter>
</ClInclude>
<ClInclude Include="_IRobotEventEvents_CP.h">
<Filter>头文件</Filter>
</ClInclude>
<ClInclude Include="RobotEvent.h">
<Filter>头文件</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="WeChatRobotCOM.cpp">
......@@ -276,6 +282,9 @@
<ClCompile Include="DeleteUser.cpp">
<Filter>好友相关\删除好友</Filter>
</ClCompile>
<ClCompile Include="RobotEvent.cpp">
<Filter>源文件</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="WeChatRobotCOM.rc">
......@@ -289,6 +298,9 @@
<None Include="WeChatRobot.rgs">
<Filter>资源文件</Filter>
</None>
<None Include="RobotEvent.rgs">
<Filter>资源文件</Filter>
</None>
</ItemGroup>
<ItemGroup>
<Midl Include="WeChatRobotCOM.idl">
......
......@@ -69,11 +69,20 @@ typedef IID CLSID;
MIDL_DEFINE_GUID(IID, IID_IWeChatRobot,0xa836e359,0x59b2,0x4e01,0x9b,0x0c,0x0e,0x5a,0x5a,0x2e,0xfa,0x22);
MIDL_DEFINE_GUID(IID, IID_IRobotEvent,0x1a9d8d1b,0xd40e,0x4f3a,0x8e,0xd4,0xb7,0x83,0xe6,0xa5,0x98,0x30);
MIDL_DEFINE_GUID(IID, LIBID_WeChatRobotCOMLib,0x721abb35,0x141a,0x4aa2,0x94,0xf2,0x76,0x2e,0x28,0x33,0xfa,0x6c);
MIDL_DEFINE_GUID(CLSID, CLSID_WeChatRobot,0x4ce7f5e1,0x2c93,0x4bfe,0x86,0xac,0x88,0x64,0x52,0xe4,0x74,0x75);
MIDL_DEFINE_GUID(IID, DIID__IRobotEventEvents,0x8fd26fd1,0x9169,0x4e4c,0x8a,0x1d,0xd0,0x50,0x93,0xba,0xcc,0xe5);
MIDL_DEFINE_GUID(CLSID, CLSID_RobotEvent,0x178001e8,0x5e64,0x4cec,0x80,0x32,0x1d,0xe2,0x88,0x01,0xdf,0x55);
#undef MIDL_DEFINE_GUID
#ifdef __cplusplus
......
......@@ -51,6 +51,13 @@ typedef interface IWeChatRobot IWeChatRobot;
#endif /* __IWeChatRobot_FWD_DEFINED__ */
#ifndef __IRobotEvent_FWD_DEFINED__
#define __IRobotEvent_FWD_DEFINED__
typedef interface IRobotEvent IRobotEvent;
#endif /* __IRobotEvent_FWD_DEFINED__ */
#ifndef __WeChatRobot_FWD_DEFINED__
#define __WeChatRobot_FWD_DEFINED__
......@@ -63,6 +70,25 @@ typedef struct WeChatRobot WeChatRobot;
#endif /* __WeChatRobot_FWD_DEFINED__ */
#ifndef ___IRobotEventEvents_FWD_DEFINED__
#define ___IRobotEventEvents_FWD_DEFINED__
typedef interface _IRobotEventEvents _IRobotEventEvents;
#endif /* ___IRobotEventEvents_FWD_DEFINED__ */
#ifndef __RobotEvent_FWD_DEFINED__
#define __RobotEvent_FWD_DEFINED__
#ifdef __cplusplus
typedef class RobotEvent RobotEvent;
#else
typedef struct RobotEvent RobotEvent;
#endif /* __cplusplus */
#endif /* __RobotEvent_FWD_DEFINED__ */
/* header files for imported files */
#include "oaidl.h"
#include "ocidl.h"
......@@ -643,6 +669,138 @@ EXTERN_C const IID IID_IWeChatRobot;
#endif /* __IWeChatRobot_INTERFACE_DEFINED__ */
#ifndef __IRobotEvent_INTERFACE_DEFINED__
#define __IRobotEvent_INTERFACE_DEFINED__
/* interface IRobotEvent */
/* [unique][nonextensible][dual][uuid][object] */
EXTERN_C const IID IID_IRobotEvent;
#if defined(__cplusplus) && !defined(CINTERFACE)
MIDL_INTERFACE("1a9d8d1b-d40e-4f3a-8ed4-b783e6a59830")
IRobotEvent : public IDispatch
{
public:
virtual /* [helpstring][id] */ HRESULT STDMETHODCALLTYPE CPostMessage(
/* [in] */ VARIANT *msg,
/* [retval][out] */ int *__result) = 0;
};
#else /* C style interface */
typedef struct IRobotEventVtbl
{
BEGIN_INTERFACE
HRESULT ( STDMETHODCALLTYPE *QueryInterface )(
IRobotEvent * This,
/* [in] */ REFIID riid,
/* [annotation][iid_is][out] */
_COM_Outptr_ void **ppvObject);
ULONG ( STDMETHODCALLTYPE *AddRef )(
IRobotEvent * This);
ULONG ( STDMETHODCALLTYPE *Release )(
IRobotEvent * This);
HRESULT ( STDMETHODCALLTYPE *GetTypeInfoCount )(
IRobotEvent * This,
/* [out] */ UINT *pctinfo);
HRESULT ( STDMETHODCALLTYPE *GetTypeInfo )(
IRobotEvent * This,
/* [in] */ UINT iTInfo,
/* [in] */ LCID lcid,
/* [out] */ ITypeInfo **ppTInfo);
HRESULT ( STDMETHODCALLTYPE *GetIDsOfNames )(
IRobotEvent * This,
/* [in] */ REFIID riid,
/* [size_is][in] */ LPOLESTR *rgszNames,
/* [range][in] */ UINT cNames,
/* [in] */ LCID lcid,
/* [size_is][out] */ DISPID *rgDispId);
/* [local] */ HRESULT ( STDMETHODCALLTYPE *Invoke )(
IRobotEvent * This,
/* [annotation][in] */
_In_ DISPID dispIdMember,
/* [annotation][in] */
_In_ REFIID riid,
/* [annotation][in] */
_In_ LCID lcid,
/* [annotation][in] */
_In_ WORD wFlags,
/* [annotation][out][in] */
_In_ DISPPARAMS *pDispParams,
/* [annotation][out] */
_Out_opt_ VARIANT *pVarResult,
/* [annotation][out] */
_Out_opt_ EXCEPINFO *pExcepInfo,
/* [annotation][out] */
_Out_opt_ UINT *puArgErr);
/* [helpstring][id] */ HRESULT ( STDMETHODCALLTYPE *CPostMessage )(
IRobotEvent * This,
/* [in] */ VARIANT *msg,
/* [retval][out] */ int *__result);
END_INTERFACE
} IRobotEventVtbl;
interface IRobotEvent
{
CONST_VTBL struct IRobotEventVtbl *lpVtbl;
};
#ifdef COBJMACROS
#define IRobotEvent_QueryInterface(This,riid,ppvObject) \
( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) )
#define IRobotEvent_AddRef(This) \
( (This)->lpVtbl -> AddRef(This) )
#define IRobotEvent_Release(This) \
( (This)->lpVtbl -> Release(This) )
#define IRobotEvent_GetTypeInfoCount(This,pctinfo) \
( (This)->lpVtbl -> GetTypeInfoCount(This,pctinfo) )
#define IRobotEvent_GetTypeInfo(This,iTInfo,lcid,ppTInfo) \
( (This)->lpVtbl -> GetTypeInfo(This,iTInfo,lcid,ppTInfo) )
#define IRobotEvent_GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) \
( (This)->lpVtbl -> GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) )
#define IRobotEvent_Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) \
( (This)->lpVtbl -> Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) )
#define IRobotEvent_CPostMessage(This,msg,__result) \
( (This)->lpVtbl -> CPostMessage(This,msg,__result) )
#endif /* COBJMACROS */
#endif /* C style interface */
#endif /* __IRobotEvent_INTERFACE_DEFINED__ */
#ifndef __WeChatRobotCOMLib_LIBRARY_DEFINED__
#define __WeChatRobotCOMLib_LIBRARY_DEFINED__
......@@ -660,6 +818,129 @@ EXTERN_C const CLSID CLSID_WeChatRobot;
class DECLSPEC_UUID("4ce7f5e1-2c93-4bfe-86ac-886452e47475")
WeChatRobot;
#endif
#ifndef ___IRobotEventEvents_DISPINTERFACE_DEFINED__
#define ___IRobotEventEvents_DISPINTERFACE_DEFINED__
/* dispinterface _IRobotEventEvents */
/* [uuid] */
EXTERN_C const IID DIID__IRobotEventEvents;
#if defined(__cplusplus) && !defined(CINTERFACE)
MIDL_INTERFACE("8fd26fd1-9169-4e4c-8a1d-d05093bacce5")
_IRobotEventEvents : public IDispatch
{
};
#else /* C style interface */
typedef struct _IRobotEventEventsVtbl
{
BEGIN_INTERFACE
HRESULT ( STDMETHODCALLTYPE *QueryInterface )(
_IRobotEventEvents * This,
/* [in] */ REFIID riid,
/* [annotation][iid_is][out] */
_COM_Outptr_ void **ppvObject);
ULONG ( STDMETHODCALLTYPE *AddRef )(
_IRobotEventEvents * This);
ULONG ( STDMETHODCALLTYPE *Release )(
_IRobotEventEvents * This);
HRESULT ( STDMETHODCALLTYPE *GetTypeInfoCount )(
_IRobotEventEvents * This,
/* [out] */ UINT *pctinfo);
HRESULT ( STDMETHODCALLTYPE *GetTypeInfo )(
_IRobotEventEvents * This,
/* [in] */ UINT iTInfo,
/* [in] */ LCID lcid,
/* [out] */ ITypeInfo **ppTInfo);
HRESULT ( STDMETHODCALLTYPE *GetIDsOfNames )(
_IRobotEventEvents * This,
/* [in] */ REFIID riid,
/* [size_is][in] */ LPOLESTR *rgszNames,
/* [range][in] */ UINT cNames,
/* [in] */ LCID lcid,
/* [size_is][out] */ DISPID *rgDispId);
/* [local] */ HRESULT ( STDMETHODCALLTYPE *Invoke )(
_IRobotEventEvents * This,
/* [annotation][in] */
_In_ DISPID dispIdMember,
/* [annotation][in] */
_In_ REFIID riid,
/* [annotation][in] */
_In_ LCID lcid,
/* [annotation][in] */
_In_ WORD wFlags,
/* [annotation][out][in] */
_In_ DISPPARAMS *pDispParams,
/* [annotation][out] */
_Out_opt_ VARIANT *pVarResult,
/* [annotation][out] */
_Out_opt_ EXCEPINFO *pExcepInfo,
/* [annotation][out] */
_Out_opt_ UINT *puArgErr);
END_INTERFACE
} _IRobotEventEventsVtbl;
interface _IRobotEventEvents
{
CONST_VTBL struct _IRobotEventEventsVtbl *lpVtbl;
};
#ifdef COBJMACROS
#define _IRobotEventEvents_QueryInterface(This,riid,ppvObject) \
( (This)->lpVtbl -> QueryInterface(This,riid,ppvObject) )
#define _IRobotEventEvents_AddRef(This) \
( (This)->lpVtbl -> AddRef(This) )
#define _IRobotEventEvents_Release(This) \
( (This)->lpVtbl -> Release(This) )
#define _IRobotEventEvents_GetTypeInfoCount(This,pctinfo) \
( (This)->lpVtbl -> GetTypeInfoCount(This,pctinfo) )
#define _IRobotEventEvents_GetTypeInfo(This,iTInfo,lcid,ppTInfo) \
( (This)->lpVtbl -> GetTypeInfo(This,iTInfo,lcid,ppTInfo) )
#define _IRobotEventEvents_GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) \
( (This)->lpVtbl -> GetIDsOfNames(This,riid,rgszNames,cNames,lcid,rgDispId) )
#define _IRobotEventEvents_Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) \
( (This)->lpVtbl -> Invoke(This,dispIdMember,riid,lcid,wFlags,pDispParams,pVarResult,pExcepInfo,puArgErr) )
#endif /* COBJMACROS */
#endif /* C style interface */
#endif /* ___IRobotEventEvents_DISPINTERFACE_DEFINED__ */
EXTERN_C const CLSID CLSID_RobotEvent;
#ifdef __cplusplus
class DECLSPEC_UUID("178001e8-5e64-4cec-8032-1de28801df55")
RobotEvent;
#endif
#endif /* __WeChatRobotCOMLib_LIBRARY_DEFINED__ */
/* Additional Prototypes for ALL interfaces */
......
......@@ -49,7 +49,7 @@
#include "WeChatRobotCOM_i.h"
#define TYPE_FORMAT_STRING_SIZE 1239
#define PROC_FORMAT_STRING_SIZE 1573
#define PROC_FORMAT_STRING_SIZE 1615
#define EXPR_FORMAT_STRING_SIZE 1
#define TRANSMIT_AS_TABLE_SIZE 0
#define WIRE_MARSHAL_TABLE_SIZE 2
......@@ -89,6 +89,13 @@ extern const MIDL_SERVER_INFO IWeChatRobot_ServerInfo;
extern const MIDL_STUBLESS_PROXY_INFO IWeChatRobot_ProxyInfo;
extern const MIDL_STUB_DESC Object_StubDesc;
extern const MIDL_SERVER_INFO IRobotEvent_ServerInfo;
extern const MIDL_STUBLESS_PROXY_INFO IRobotEvent_ProxyInfo;
extern const USER_MARSHAL_ROUTINE_QUADRUPLE UserMarshalRoutines[ WIRE_MARSHAL_TABLE_SIZE ];
#if !defined(__RPC_WIN32__)
......@@ -1487,6 +1494,43 @@ static const WeChatRobotCOM_MIDL_PROC_FORMAT_STRING WeChatRobotCOM__MIDL_ProcFor
/* 1570 */ 0x8, /* FC_LONG */
0x0, /* 0 */
/* Procedure CPostMessage */
/* 1572 */ 0x33, /* FC_AUTO_HANDLE */
0x6c, /* Old Flags: object, Oi2 */
/* 1574 */ NdrFcLong( 0x0 ), /* 0 */
/* 1578 */ NdrFcShort( 0x7 ), /* 7 */
/* 1580 */ NdrFcShort( 0x10 ), /* x86 Stack size/offset = 16 */
/* 1582 */ NdrFcShort( 0x0 ), /* 0 */
/* 1584 */ NdrFcShort( 0x24 ), /* 36 */
/* 1586 */ 0x46, /* Oi2 Flags: clt must size, has return, has ext, */
0x3, /* 3 */
/* 1588 */ 0x8, /* 8 */
0x45, /* Ext Flags: new corr desc, srv corr check, has range on conformance */
/* 1590 */ NdrFcShort( 0x0 ), /* 0 */
/* 1592 */ NdrFcShort( 0x1 ), /* 1 */
/* 1594 */ NdrFcShort( 0x0 ), /* 0 */
/* Parameter msg */
/* 1596 */ NdrFcShort( 0x10b ), /* Flags: must size, must free, in, simple ref, */
/* 1598 */ NdrFcShort( 0x4 ), /* x86 Stack size/offset = 4 */
/* 1600 */ NdrFcShort( 0x4cc ), /* Type Offset=1228 */
/* Parameter __result */
/* 1602 */ NdrFcShort( 0x2150 ), /* Flags: out, base type, simple ref, srv alloc size=8 */
/* 1604 */ NdrFcShort( 0x8 ), /* x86 Stack size/offset = 8 */
/* 1606 */ 0x8, /* FC_LONG */
0x0, /* 0 */
/* Return value */
/* 1608 */ NdrFcShort( 0x70 ), /* Flags: out, return, base type, */
/* 1610 */ NdrFcShort( 0xc ), /* x86 Stack size/offset = 12 */
/* 1612 */ 0x8, /* FC_LONG */
0x0, /* 0 */
0x0
}
};
......@@ -2497,6 +2541,74 @@ CInterfaceStubVtbl _IWeChatRobotStubVtbl =
CStdStubBuffer_DELEGATING_METHODS
};
/* Object interface: IRobotEvent, ver. 0.0,
GUID={0x1a9d8d1b,0xd40e,0x4f3a,{0x8e,0xd4,0xb7,0x83,0xe6,0xa5,0x98,0x30}} */
#pragma code_seg(".orpc")
static const unsigned short IRobotEvent_FormatStringOffsetTable[] =
{
(unsigned short) -1,
(unsigned short) -1,
(unsigned short) -1,
(unsigned short) -1,
1572
};
static const MIDL_STUBLESS_PROXY_INFO IRobotEvent_ProxyInfo =
{
&Object_StubDesc,
WeChatRobotCOM__MIDL_ProcFormatString.Format,
&IRobotEvent_FormatStringOffsetTable[-3],
0,
0,
0
};
static const MIDL_SERVER_INFO IRobotEvent_ServerInfo =
{
&Object_StubDesc,
0,
WeChatRobotCOM__MIDL_ProcFormatString.Format,
&IRobotEvent_FormatStringOffsetTable[-3],
0,
0,
0,
0};
CINTERFACE_PROXY_VTABLE(8) _IRobotEventProxyVtbl =
{
&IRobotEvent_ProxyInfo,
&IID_IRobotEvent,
IUnknown_QueryInterface_Proxy,
IUnknown_AddRef_Proxy,
IUnknown_Release_Proxy ,
0 /* IDispatch::GetTypeInfoCount */ ,
0 /* IDispatch::GetTypeInfo */ ,
0 /* IDispatch::GetIDsOfNames */ ,
0 /* IDispatch_Invoke_Proxy */ ,
(void *) (INT_PTR) -1 /* IRobotEvent::CPostMessage */
};
static const PRPC_STUB_FUNCTION IRobotEvent_table[] =
{
STUB_FORWARDING_FUNCTION,
STUB_FORWARDING_FUNCTION,
STUB_FORWARDING_FUNCTION,
STUB_FORWARDING_FUNCTION,
NdrStubCall2
};
CInterfaceStubVtbl _IRobotEventStubVtbl =
{
&IID_IRobotEvent,
&IRobotEvent_ServerInfo,
8,
&IRobotEvent_table[-3],
CStdStubBuffer_DELEGATING_METHODS
};
static const MIDL_STUB_DESC Object_StubDesc =
{
0,
......@@ -2523,24 +2635,28 @@ static const MIDL_STUB_DESC Object_StubDesc =
const CInterfaceProxyVtbl * const _WeChatRobotCOM_ProxyVtblList[] =
{
( CInterfaceProxyVtbl *) &_IRobotEventProxyVtbl,
( CInterfaceProxyVtbl *) &_IWeChatRobotProxyVtbl,
0
};
const CInterfaceStubVtbl * const _WeChatRobotCOM_StubVtblList[] =
{
( CInterfaceStubVtbl *) &_IRobotEventStubVtbl,
( CInterfaceStubVtbl *) &_IWeChatRobotStubVtbl,
0
};
PCInterfaceName const _WeChatRobotCOM_InterfaceNamesList[] =
{
"IRobotEvent",
"IWeChatRobot",
0
};
const IID * const _WeChatRobotCOM_BaseIIDList[] =
{
&IID_IDispatch,
&IID_IDispatch,
0
};
......@@ -2550,14 +2666,11 @@ const IID * const _WeChatRobotCOM_BaseIIDList[] =
int __stdcall _WeChatRobotCOM_IID_Lookup( const IID * pIID, int * pIndex )
{
if(!_WeChatRobotCOM_CHECK_IID(0))
{
*pIndex = 0;
return 1;
}
IID_BS_LOOKUP_SETUP
return 0;
IID_BS_LOOKUP_INITIAL_TEST( _WeChatRobotCOM, 2, 1 )
IID_BS_LOOKUP_RETURN_RESULT( _WeChatRobotCOM, 2, *pIndex )
}
const ExtendedProxyFileInfo WeChatRobotCOM_ProxyFileInfo =
......@@ -2567,7 +2680,7 @@ const ExtendedProxyFileInfo WeChatRobotCOM_ProxyFileInfo =
(const PCInterfaceName * ) & _WeChatRobotCOM_InterfaceNamesList,
(const IID ** ) & _WeChatRobotCOM_BaseIIDList,
& _WeChatRobotCOM_IID_Lookup,
1,
2,
2,
0, /* table of [async_uuid] interfaces */
0, /* Filler1 */
......
#pragma once
template<class T>
class CProxy_IRobotEventEvents :
public ATL::IConnectionPointImpl<T, &__uuidof(_IRobotEventEvents)>
{
public:
HRESULT Fire_OnGetMessageEvent(VARIANT* msg)
{
HRESULT hr = S_OK;
T* pThis = static_cast<T*>(this);
int cConnections = m_vec.GetSize();
for (int iConnection = 0; iConnection < cConnections; iConnection++)
{
pThis->Lock();
CComPtr<IUnknown> punkConnection = m_vec.GetAt(iConnection);
pThis->Unlock();
IDispatch* pConnection = static_cast<IDispatch*>(punkConnection.p);
if (pConnection)
{
/*CComVariant avarParams[1];
avarParams[0] = msg;
avarParams[0].vt = msg->vt;*/
CComVariant varResult;
DISPPARAMS params = { msg, NULL, 1, 0 };
hr = pConnection->Invoke(1, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &params, &varResult, NULL, NULL);
}
}
return hr;
}
};
......@@ -5,6 +5,7 @@
#define IDS_PROJNAME 100
#define IDR_WECHATROBOTCOM 101
#define IDR_WECHATROBOT 106
#define IDR_ROBOTEVENT 107
// Next default values for new objects
//
......@@ -13,6 +14,6 @@
#define _APS_NEXT_RESOURCE_VALUE 201
#define _APS_NEXT_COMMAND_VALUE 32768
#define _APS_NEXT_CONTROL_VALUE 201
#define _APS_NEXT_SYMED_VALUE 107
#define _APS_NEXT_SYMED_VALUE 108
#endif
#endif
......@@ -74,6 +74,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<TargetName>$(ProjectName)</TargetName>
<IncludePath>$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
......@@ -155,6 +156,7 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="AddFriend.h" />
<ClInclude Include="comclient.h" />
<ClInclude Include="CheckFriendStatus.h" />
<ClInclude Include="DbBackup.h" />
<ClInclude Include="DbExecuteSql.h" />
......@@ -178,12 +180,15 @@
<ClInclude Include="sqlite3.h" />
<ClInclude Include="VerifyFriendApply.h" />
<ClInclude Include="wechatver.h" />
<ClInclude Include="wxsocket.h" />
<ClInclude Include="wxsocketapi.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="AddFriendByV3.cpp" />
<ClCompile Include="AddFriendByWxid.cpp" />
<ClCompile Include="AddBrandContact.cpp" />
<ClCompile Include="CheckFriendStatus.cpp" />
<ClCompile Include="comclient.cpp" />
<ClCompile Include="DbBackup.cpp" />
<ClCompile Include="DbExecuteSql.cpp" />
<ClCompile Include="DeleteUser.cpp" />
......@@ -213,6 +218,7 @@
<ClCompile Include="LogMsgInfo.cpp" />
<ClCompile Include="VerifyFriendApply.cpp" />
<ClCompile Include="wechatver.cpp" />
<ClCompile Include="wxsocket.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
......
......@@ -91,6 +91,12 @@
<Filter Include="发送消息\发送小程序">
<UniqueIdentifier>{2e1bef8d-a840-4318-a728-29f1e8e68336}</UniqueIdentifier>
</Filter>
<Filter Include="wxsocket">
<UniqueIdentifier>{aa631fe9-d228-4c2b-a317-0b0914bed451}</UniqueIdentifier>
</Filter>
<Filter Include="comclient">
<UniqueIdentifier>{79c2ec41-70f9-445a-8681-5a2dbfe01eca}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="framework.h">
......@@ -165,6 +171,15 @@
<ClInclude Include="SendAppMsg.h">
<Filter>发送消息\发送小程序</Filter>
</ClInclude>
<ClInclude Include="wxsocket.h">
<Filter>wxsocket</Filter>
</ClInclude>
<ClInclude Include="comclient.h">
<Filter>comclient</Filter>
</ClInclude>
<ClInclude Include="wxsocketapi.h">
<Filter>wxsocket</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="dllmain.cpp">
......@@ -251,5 +266,11 @@
<ClCompile Include="SendAppMsg.cpp">
<Filter>发送消息\发送小程序</Filter>
</ClCompile>
<ClCompile Include="wxsocket.cpp">
<Filter>wxsocket</Filter>
</ClCompile>
<ClCompile Include="comclient.cpp">
<Filter>comclient</Filter>
</ClCompile>
</ItemGroup>
</Project>
\ No newline at end of file
......@@ -4,5 +4,6 @@
<LocalDebuggerCommandArguments>
</LocalDebuggerCommandArguments>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
<LocalDebuggerCommand>D:\Tencent\WeChat\WeChat.exe</LocalDebuggerCommand>
</PropertyGroup>
</Project>
\ No newline at end of file
......@@ -122,7 +122,7 @@ int query(void* data, int argc, char** argv, char** azColName) {
* 外部调用时使用的回调函数,将结果存入`SQLResult`中
* return:int,执行成功返回`0`,执行失败返回非0值
*/
int select(void* data, int argc, char** argv, char** azColName) {
int selectdbinfo(void* data, int argc, char** argv, char** azColName) {
executeResult* pdata = (executeResult*)data;
vector<SQLResultStruct> tempStruct;
for (int i = 0; i < argc; i++) {
......@@ -195,7 +195,7 @@ BOOL ExecuteSQL(DWORD ptrDb,const char* sql,DWORD callback,void* data) {
DWORD ExecuteSQLRemote(LPVOID lpParameter){
ClearResultArray();
executeParams* sqlparam = (executeParams*)lpParameter;
BOOL status = ExecuteSQL(sqlparam->ptrDb, (const char*)sqlparam->ptrSql, (DWORD)select, &result);
BOOL status = ExecuteSQL(sqlparam->ptrDb, (const char*)sqlparam->ptrSql, (DWORD)selectdbinfo, &result);
if (status) {
result.SQLResultAddr = (DWORD)SQLResult.data();
......
......@@ -2,7 +2,7 @@
#include<windows.h>
int GetDbInfo(void* data, int argc, char** argv, char** azColName);
int select(void* data, int argc, char** argv, char** azColName);
int selectdbinfo(void* data, int argc, char** argv, char** azColName);
int query(void* data, int argc, char** argv, char** azColName);
extern "C" __declspec(dllexport) DWORD ExecuteSQLRemote(LPVOID lpParameter);
......
#include "pch.h"
#include <vector>
#include <iostream>
// 接收消息的HOOK地址偏移
#define ReceiveMessageHookOffset 0x547C0F4C - 0x54270000
......@@ -55,6 +56,40 @@ DWORD SendMessageNextCall = GetWeChatWinBase() + SendMessageNextCallOffset;
// 发送HOOK的跳转地址
DWORD SendMessageJmpBackAddress = SendMessageHookAddress + 0x5;
// 创建广播消息数组
static SAFEARRAY* CreateMessageArray(messageStruct* ms) {
HRESULT hr = S_OK;
SAFEARRAY* psaValue;
vector<wstring> MessageInfoKey = {
L"type",
L"isSendMessage",
ms->isSendMessage ? L"sendto" : L"from",
L"wxid",
L"message",
L"filepath",
L"time"
};
SAFEARRAYBOUND rgsaBound[2] = { {MessageInfoKey.size(),0},{2,0} };
psaValue = SafeArrayCreate(VT_VARIANT, 2, rgsaBound);
long keyIndex[2] = { 0,0 };
keyIndex[0] = 0; keyIndex[1] = 0;
for (unsigned int i = 0; i < MessageInfoKey.size(); i++) {
keyIndex[0] = i; keyIndex[1] = 0;
_variant_t key = MessageInfoKey[i].c_str();
hr = SafeArrayPutElement(psaValue, keyIndex, &key);
keyIndex[0] = i; keyIndex[1] = 1;
if (i < 2) {
_variant_t value = ((DWORD*)ms)[i];
hr = SafeArrayPutElement(psaValue, keyIndex, &value);
}
else {
_variant_t value = ((wchar_t**)ms)[i * 2 - 2];
hr = SafeArrayPutElement(psaValue, keyIndex, &value);
}
}
return psaValue;
}
/*
* 消息处理函数,根据消息缓冲区组装结构并存入容器
* messageAddr:保存消息的缓冲区地址
......@@ -101,10 +136,14 @@ VOID ReceiveMessage(DWORD messageAddr) {
ZeroMemory(message.filepath, (length + 1) * 2);
memcpy(message.filepath, (wchar_t*)(*(DWORD*)(messageAddr + 0x1AC)), length * 2);
message.l_filepath = length;
#ifdef _DEBUG
wcout << message.time << endl;
#ifdef USE_COM_EVENT
// 通过连接点,将消息广播给客户端
SAFEARRAY* psaValue = CreateMessageArray(&message);
VARIANT vsaValue;
vsaValue.vt = VT_ARRAY | VT_VARIANT;
V_ARRAY(&vsaValue) = psaValue;
PostComMessage(&vsaValue);
#endif
messageVector.push_back(message);
}
......
#include "pch.h"
#include <atlbase.h>
#include <atlcom.h>
#include "../CWeChatRobot/WeChatRobotCOM_i.h"
#include "../CWeChatRobot/WeChatRobotCOM_i.c"
#include <iostream>
#include <thread>
using namespace std;
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(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);
*/
/*
CComVariant varParam;
varParam.vt = VT_BSTR;
varParam = pmsg;
*/
int __result = 0;
spRobotEvent->CPostMessage(msg, &__result);
}
else {
return false;
}
CoUninitialize();
return true;
}
\ No newline at end of file
#pragma once
#include<windows.h>
#define USE_COM_EVENT
BOOL PostComMessage(VARIANT* msg);
\ No newline at end of file
......@@ -11,6 +11,7 @@
#include "framework.h"
#include<windows.h>
#include<iostream>
#include <comutil.h>
#include "SendImage.h"
#include "SendText.h"
#include "SendFile.h"
......@@ -35,10 +36,18 @@
#include "SendAppMsg.h"
#include <vector>
#include <strstream>
#include "wxsocket.h"
#include "comclient.h"
#endif //PCH_H
#ifdef WX_SOCKET
#include "wxsocketapi.h"
#endif
using namespace std;
#pragma comment(lib,"version.lib")
#pragma comment(lib, "comsuppw.lib")
#pragma warning(disable:4731)
// 对于导出函数,需要使用此宏修饰
#define DLLEXPORT extern "C" __declspec(dllexport)
......
#include "pch.h"
#include<iostream>
using namespace std;
#ifdef WX_SOCKET
#include<thread>
static struct mg_mgr mgr;
static bool httpruning = false;
static const char* s_http_addr = "http://0.0.0.0:8000"; // HTTP port
static const char* s_root_dir = ".";
// Event handler for the listening connection.
// Simply serve static files from `s_root_dir`
static void fn(struct mg_connection* c, int ev, void* ev_data, void* fn_data) {
if (ev == MG_EV_HTTP_MSG) {
struct mg_http_message* hm = (struct mg_http_message*)ev_data, tmp = { 0 };
if (mg_http_match_uri(hm, "/api/test")) {
SendText((wchar_t*)L"filehelper", (wchar_t*)L"Ϣ");
mg_printf(c, "HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n");
mg_http_printf_chunk(c, "ID PROTO TYPE LOCAL REMOTE\n");
mg_http_printf_chunk(c, "");
}
else if (mg_http_match_uri(hm, "/api/f2/*")) {
mg_http_reply(c, 200, "", "{\"result\": \"%.*s\"}\n", (int)hm->uri.len,hm->uri.ptr);
}
else if (mg_http_match_uri(hm, "/api/quit/")) {
mg_http_reply(c, 200, "", "{\"result\": \"OK\"}\n", 0, 0);
httpruning = false;
}
else {
struct mg_http_serve_opts opts = { 0 };
opts.root_dir = s_root_dir;
mg_http_serve_dir(c, (struct mg_http_message*)ev_data, &opts);
}
}
(void)fn_data;
}
int HttpStart() {
mg_log_set("2");
mg_mgr_init(&mgr);
mg_http_listen(&mgr, s_http_addr, fn, NULL);
httpruning = true;
while (httpruning)
mg_mgr_poll(&mgr, 1000);
mg_mgr_free(&mgr);
return 0;
}
int HttpClose() {
httpruning = false;
return 0;
}
#endif
\ No newline at end of file
#pragma once
#ifdef _DEBUG
// #define WX_SOCKET
#endif
\ No newline at end of file
#pragma once
#include "wxsocket.h"
#ifdef WX_SOCKET
#include <signal.h>
#include "mongoose.h"
#pragma comment(lib,"ws2_32.lib")
int HttpStart();
int HttpClose();
#endif
\ No newline at end of file
......@@ -104,4 +104,6 @@ if __name__ == '__main__':
wx = WeChatRobot()
print([i for i in dir(wx.robot) if '_' not in i and i[0] == 'C'])
print(wx.GetWeChatVer())
print(wx.StartService())
wx.StartReceiveMsgByEvent()
wx.StopService()
\ No newline at end of file
......@@ -12,6 +12,8 @@ import ast
import os
import threading
import time
from comtypes.client import GetEvents
from comtypes.client import PumpEvents
class ChatSession():
def __init__(self,robot,wxid):
......@@ -58,12 +60,18 @@ class ChatSession():
def SendAppMsg(self,appid):
return self.robot.CSendAppMsg(self.chatwith,appid)
class WeChatEventSink():
def OnGetMessageEvent(self,msg,*args,**kwargs):
# 为了兼容原有接口,需要在接收到广播后调用此接口,否则会导致严重的内存泄漏
WeChatRobot().robot.CReceiveMessage()
print(msg)
class WeChatRobot():
def __init__(self):
self.robot = comtypes.client.CreateObject("WeChatRobot.CWeChatRobot")
self.event = comtypes.client.CreateObject("WeChatRobot.RobotEvent")
self.AddressBook = []
self.myinfo = {}
self.ReceiveMessageStarted = False
......@@ -235,6 +243,18 @@ class WeChatRobot():
self.ReceiveMessageThread.start()
return status
# 通过连接点接收消息
def StartReceiveMsgByEvent(self,EventSink = None):
self.robot.CStartReceiveMessage()
if self.event is not None:
sink = EventSink or WeChatEventSink()
self.ConnectionPoint = GetEvents(self.event,sink)
while True:
try:
PumpEvents(10)
except:
break
def GetDbHandles(self):
tablesTuple = self.robot.CGetDbHandles()
tables = [dict(i) for i in tablesTuple]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册