Click here to Skip to main content
15,499,430 members
Home / Discussions / COM
   

COM

 
AnswerRe: Problem with IpublishingWizard Pin
DeniseMak29-Dec-05 13:25
MemberDeniseMak29-Dec-05 13:25 
GeneralRe: Problem with IpublishingWizard Pin
devcdd2-Jan-06 23:57
Memberdevcdd2-Jan-06 23:57 
QuestionImplementing Lua Debugger using COM Pin
Prince0fPersia15-Dec-05 21:44
MemberPrince0fPersia15-Dec-05 21:44 
AnswerRe: Implementing Lua Debugger using COM Pin
Brian C Hart31-Dec-05 0:28
professionalBrian C Hart31-Dec-05 0:28 
Questionword add-in Pin
dogogbird14-Dec-05 22:49
Memberdogogbird14-Dec-05 22:49 
QuestionExtensible Storage Engine Pin
M Tauheed13-Dec-05 22:20
MemberM Tauheed13-Dec-05 22:20 
QuestionHow to restrict client application to create COM object Pin
lvantin13-Dec-05 16:26
Memberlvantin13-Dec-05 16:26 
AnswerRe: How to restrict client application to create COM object Pin
Per Nilsson13-Dec-05 22:44
MemberPer Nilsson13-Dec-05 22:44 
As I've been curious about the same thing, I took this as an exercise, and
if you use ATL for your COM server, I have the solution for you.

ATL includes an object map in its implementation file that includes entries for each class the server implements. The map is located in the COM servers implementation file (named <project name="">.cpp) and looks like this

BEGIN_OBJECT_MAP(ObjectMap)
  OBJECT_ENTRY(CLSID_Creatable, CCreatable)
  OBJECT_ENTRY(CLSID_IsNotCreatable, CIsNotCreatable)
END_OBJECT_MAP()


Change the object entry to OBJECT_ENTRY_NON_CREATEABLE of your non, creatable class.

BEGIN_OBJECT_MAP(ObjectMap)
  OBJECT_ENTRY(CLSID_Creatable, CCreatable)
  OBJECT_ENTRY_NON_CREATEABLE(CIsNotCreatable)
END_OBJECT_MAP()


After this, the CIsNotCreatable coclass cannot be created by CoCreateInstance. (Take a look at the documentation of OBJECT_ENTRY_NON_CREATEABLE in MSDN).



To let the creatable class create an instance of the non creatable and return a COM pointer ot it, you can do like this

STDMETHODIMP CCreatable::CreateNotCreatableObject(IIsNotCreatable **obj)
{
  AFX_MANAGE_STATE(AfxGetStaticModuleState())

  HRESULT hr;

  //
  // CComObject template class is the root of all ATL COM objects
  // The CComObject implements the IUnknown defined methods.
  //
  // We set up a pointer to a COM object of class CIsNotCreatable
  //(that inherits from IIsNotCreatable)
  //
  CComObject<CIsNotCreatable>* instanceOfNotCreatableClass;

  //
  // Then we can use the CreateInstance static method olf CComObject to
  // create an instance of the object. (Otherwise we could have used new)
  //
  hr = CComObject<CIsNotCreatable>::CreateInstance(&instanceOfNotCreatableClass);


  if (SUCCEEDED (hr)) {
    // 
    // As we will return an COM pointer from our method, we must remember
    // to call AddRef on it.
    //
    instanceOfNotCreatableClass->AddRef ();

    //
    // Assign the return value
    //
    *obj = instanceOfNotCreatableClass;
  }

  return hr;
}

AnswerRe: How to restrict client application to create COM object Pin
User 21559714-Dec-05 10:05
MemberUser 21559714-Dec-05 10:05 
QuestionCOM Wrapper for C++ DLL Pin
James Smith13-Dec-05 6:37
MemberJames Smith13-Dec-05 6:37 
AnswerRe: COM Wrapper for C++ DLL Pin
lemur211-Jan-06 11:02
Memberlemur211-Jan-06 11:02 
QuestionHow to create COM objects in different processes Pin
Per Nilsson12-Dec-05 23:28
MemberPer Nilsson12-Dec-05 23:28 
QuestionCoCreateInstace Working Differently then createobject Pin
ky_rerun12-Dec-05 7:06
Memberky_rerun12-Dec-05 7:06 
QuestionATL COM Server throws Exception. Pin
Diana Fernandez12-Dec-05 1:36
MemberDiana Fernandez12-Dec-05 1:36 
AnswerRe: ATL COM Server throws Exception. Pin
Diana Fernandez13-Dec-05 0:29
MemberDiana Fernandez13-Dec-05 0:29 
QuestionWQL Queries for Win32_Directory Events Pin
ragavan11-Dec-05 20:14
Memberragavan11-Dec-05 20:14 
QuestionDisabling right click on flash OCX Pin
Xeronith10-Dec-05 20:03
MemberXeronith10-Dec-05 20:03 
Questioni cannt insert the values from an asp page to ms-acess database Pin
jibybabu9-Dec-05 3:44
Memberjibybabu9-Dec-05 3:44 
QuestionCOM(WebBrowser Problem) Pin
Arun Appukuttan8-Dec-05 18:20
MemberArun Appukuttan8-Dec-05 18:20 
AnswerRe: COM(WebBrowser Problem) Pin
Sufyan_shani7-Jan-06 3:46
MemberSufyan_shani7-Jan-06 3:46 
GeneralRe: COM(WebBrowser Problem) Pin
Arun Appukuttan11-Jan-06 1:21
MemberArun Appukuttan11-Jan-06 1:21 
QuestionHow to call a C# com component from VC++ Pin
meesho8-Dec-05 11:34
Membermeesho8-Dec-05 11:34 
AnswerRe: How to call a C# com component from VC++ Pin
Lim Bio Liong8-Dec-05 19:49
MemberLim Bio Liong8-Dec-05 19:49 
Questionhow to drag and drop xml element from treeview to web browser control Pin
fadi moon8-Dec-05 2:02
Memberfadi moon8-Dec-05 2:02 
QuestionE-Book for ActiveX Programming Pin
Rajkamal_dfine6-Dec-05 19:08
MemberRajkamal_dfine6-Dec-05 19:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.