C + + Development ActiveX control related matters

Source: Internet
Author: User

1.UUID Value:

Xxxx.idl the bottom:

Cmsgpromptctrl's class information
[
UUID (84045072-8aa6-40d2-a641-0097f7f6650f)
]
CoClass Msgprompt
{
[Default] dispinterface _dmsgprompt;
[Default, source] dispinterface _dmsgpromptevents;
};

2. Security Code:

Add in XXXCtrl.h

#include <objsafe.h>

Security Code
Declare_interface_map ()
Begin_interface_part (Objsafe, IObjectSafety)
Stdmethod_ (HRESULT, GetInterfaceSafetyOptions) (
REFIID riid,
DWORD __rpc_far *pdwsupportedoptions,
DWORD __rpc_far *pdwenabledoptions
);
Stdmethod_ (HRESULT, SetInterfaceSafetyOptions) (
REFIID riid,
DWORD Dwoptionsetmask,
DWORD dwenabledoptions
);
End_interface_part (Objsafe);

Add in XXXXCTRL.CPP:

Security Code
Begin_interface_map (Cmsgpromptctrl, COleControl)
Interface_part (Cmsgpromptctrl, iid_iobjectsafety, Objsafe)
End_interface_map ()



Security Code;
ULONG far EXPORT cmsgpromptctrl::xobjsafe::addref ()
{
Method_prologue (Cmsgpromptctrl, Objsafe)
return Pthis->externaladdref ();
}


ULONG far EXPORT cmsgpromptctrl::xobjsafe::release ()
{
Method_prologue (Cmsgpromptctrl, Objsafe)
return Pthis->externalrelease ();
}


HRESULT Far EXPORT cmsgpromptctrl::xobjsafe::queryinterface (
Refiid iid, void far* far* ppvobj)
{
Method_prologue (Cmsgpromptctrl, Objsafe)
Return (HRESULT) pthis->externalqueryinterface (&iid, ppvobj);
}




Const DWORD Dwsupportedbits =
Interfacesafe_for_untrusted_caller |
Interfacesafe_for_untrusted_data;
Const DWORD dwnotsupportedbits = ~ dwsupportedbits;


HRESULT Stdmethodcalltype cmsgpromptctrl::xobjsafe::getinterfacesafetyoptions (
REFIID riid,
DWORD __rpc_far *pdwsupportedoptions,
DWORD __rpc_far *pdwenabledoptions
)
{
Method_prologue (Cmsgpromptctrl, Objsafe)


HRESULT retval = Resultfromscode (S_OK);


Whether the interface exists
IUnknown far* Punkinterface;
retval = Pthis->externalqueryinterface (&riid, (void * *) &punkinterface);
if (retval! = e_nointerface)//interface exists
{
Punkinterface->release (); Release references
}


We support both kinds of safety and has always both set,
Regardless of interface.
*pdwsupportedoptions = *pdwenabledoptions = Dwsupportedbits;
return retval; E_nointerface If QI failed
}


//////////////////////////////////////////////////////////// /////////////////
Cxxxctrl::xobjsafe::setinterfacesafetyoptions
HRESULT Stdmethodcalltype cmsgpromptctrl::xobjsafe::setinterfacesafetyoptions (
REFIID riid,
DWORD Dwoptionsetmask,
DWORD dwenabledoptions
)
{
Method_prologue (Cmsgpromptctrl, Objsafe)


Whether the interface exists
IUnknown far* Punkinterface;
Pthis->externalqueryinterface (&AMP;RIID, (void * *) &punkinterface);
if (punkinterface)//interface exists
{
Punkinterface->release (); Release references
}
else//interface does not exist
{
Return Resultfromscode (E_NOINTERFACE);
}
Can ' t set bits we don ' t support.
if (Dwoptionsetmask & Dwnotsupportedbits)
{
Return Resultfromscode (E_FAIL);
}


Can ' t set bits we do support to zero
Dwenabledoptions &= dwsupportedbits;
(We already know there is no extra bits in mask.)
if ((Dwoptionsetmask & dwenabledoptions)! = Dwoptionsetmask)
{
Return Resultfromscode (E_FAIL);
}


Don ' t need to change anything since we ' re always safe.
Return Resultfromscode (S_OK);
}


3. Add interfaces and Events:

To add an interface:

Xxxxlib under Dxxxx Right--add--Add method

To add an event:

Xxxxctrl Right-click-add Event

C + + Development ActiveX control related matters

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.