Home > Software engineering >  For an adjustable through the c # COM win32 demo
For an adjustable through the c # COM win32 demo

Time:11-18

 
using System;
Using System. The Runtime. InteropServices;
The namespace EventSource
{
Public delegate void ClickDelegate (int x, int y);
Public delegate void ResizeDelegate ();
Public delegate void PulseDelegate ();

//Step 1: Defines an event sink interface (ButtonEvents) to be
//implemented by the COM sink.
[GuidAttribute (" 1 a585c4d - 3371-48 dc - AF8A - AFFECC1B0967 ")]
[InterfaceTypeAttribute (ComInterfaceType. InterfaceIsIDispatch)]
Public interface IButtonEvents
{
Void the Click (int x, int y);
Void the Resize ();
Void Pulse ();
}


[Guid (b70 "51917 a2 e6c - 87-4 - B1A8-47 c47f8007e4")]
Public interface MyCom_Interface
{
[DispId (1)]
Int the Add (int param11, int param12);
}


//Step 2: Connects the event sink interface to a class
//by passing the namespace and the event sink interface
//(" EventSource. ButtonEvents, EventSrc ").
[Guid (" FE6A8C43 - D4B6-4100 - f95a57f BC6B - 06333 "), ClassInterface (ClassInterfaceType. None), ComSourceInterfaces (typeof (IButtonEvents)]
Public class Button: MyCom_Interface
{
The public event ClickDelegate Click;
The public event ResizeDelegate Resize;
The public event PulseDelegate Pulse;

Public Button ()
{
}
Public void CauseClickEvent (int x, int y)
{
Click (x, y);
}
Public void CauseResizeEvent ()
{
The Resize ();
}
Public void CausePulse ()
{
Pulse ();
}

Public int the Add (int param11, int param12)
{

The Resize ();
Return param11 + param12;
}
}
}

CodePudding user response:

Come and help

CodePudding user response:

# import "XXX. TLB" no_namespace named_guids

//naming rules: interface Ptr p ((__uuidof (class)))
MyCom_InterfacePtr p (__uuidof (Button));

P - & gt; Add (XXX, XXX);

CodePudding user response:

refer to the second floor of solitary guest tianya response:
# import "XXX. TLB no_namespace named_guids

//naming rules: interface Ptr p ((__uuidof (class)))
MyCom_InterfacePtr p (__uuidof (Button));

P - & gt; Add (XXX, XXX);




Now you need to use the connection point to receive these, how to write

CodePudding user response:

 
# include "stdafx. H"
#include
#include




# include "the Debug/classlibrary1 TLH"
# include "SinkButtonEvent. H"


CComModule _Module;

Int main ()
{
CoInitialize (NULL);
IConnectionPoint * pEvent1=NULL;
PEvent ButtonEventListener *=new ButtonEventListener;
IConnectionPointContainer * pContainer;
IUnknownPtr pUnk=NULL;
Retrieves the hr;
MyCom_InterfacePtr pFirst=NULL;
ULONG dwAdvise;
IUnknown * SinkUnk;
Hr=CoCreateInstance (CLSID_Button, NULL, CLSCTX_INPROC_SERVER, IID_MyCom_Interface, (void * *) & amp; PUnk);
Hr=pUnk - & gt; QueryInterface (__uuidof (MyCom_Interface), (void * *) & amp; PFirst);
Hr=pFirst - & gt; QueryInterface (IID_IConnectionPointContainer, (void * *) & amp; PContainer);
Hr=pContainer - & gt; FindConnectionPoint (DIID_IButtonEvents, & amp; PEvent1);
Hr=pEvent - & gt; QueryInterface (__uuidof (IButtonEvents), (VOID * *) & amp; SinkUnk);
Hr=pEvent1 - & gt; Advise (SinkUnk, & amp; DwAdvise);


Int I=pFirst - & gt; Add (1, 2);
Hr=pEvent1 - & gt; Unadvise (dwAdvise);
PFirst - & gt; Release ();
PUnk - & gt; Release ();

CoUninitialize ();

return 0;
}

# pragma once

# include "stdafx. H"

# include "the Debug/classlibrary1 TLH"



The class SinkButtonEvent: public IButtonEvents
{
Private:
DWORD m_dwRefCount;

Public:
SinkButtonEvent () {m_dwRefCount=0; }
Virtual ~ SinkButtonEvent (void) {}
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)
{

Printf (" % d ", dispIdMember);

LONG * lValue=https://bbs.csdn.net/topics/pVarResult-> plVal;
Printf (" -- -- -- -- -- -- -- -- -- the dispid % d \ n ", dispIdMember);
OnReceiver (lValue);
Return S_OK.
}
STDMETHOD (QueryInterface) (REFIID iid, LPVOID * PPV)
{
If ((iid==__uuidof (IButtonEvents) | | (iid==__uuidof (IMarshal) | |
(iid==__uuidof (IDispatch) | |
(iid==__uuidof (IUnknown)))
{
M_dwRefCount + +;
* PPV=this;
}
The else
{
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related