Click here to Skip to main content
15,886,664 members
Home / Discussions / COM
   

COM

 
AnswerRe: Problem with IpublishingWizard Pin
DeniseMak29-Dec-05 12:25
DeniseMak29-Dec-05 12:25 
GeneralRe: Problem with IpublishingWizard Pin
devcdd2-Jan-06 22:57
devcdd2-Jan-06 22:57 
QuestionImplementing Lua Debugger using COM Pin
Prince0fPersia15-Dec-05 20:44
Prince0fPersia15-Dec-05 20:44 
AnswerRe: Implementing Lua Debugger using COM Pin
Brian C Hart30-Dec-05 23:28
professionalBrian C Hart30-Dec-05 23:28 
Questionword add-in Pin
dogogbird14-Dec-05 21:49
dogogbird14-Dec-05 21:49 
QuestionExtensible Storage Engine Pin
M Tauheed13-Dec-05 21:20
M Tauheed13-Dec-05 21:20 
QuestionHow to restrict client application to create COM object Pin
lvantin13-Dec-05 15:26
lvantin13-Dec-05 15:26 
AnswerRe: How to restrict client application to create COM object Pin
Per Nilsson13-Dec-05 21:44
Per Nilsson13-Dec-05 21: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 9:05
User 21559714-Dec-05 9:05 
QuestionCOM Wrapper for C++ DLL Pin
James Smith13-Dec-05 5:37
James Smith13-Dec-05 5:37 
AnswerRe: COM Wrapper for C++ DLL Pin
lemur211-Jan-06 10:02
lemur211-Jan-06 10:02 
QuestionHow to create COM objects in different processes Pin
Per Nilsson12-Dec-05 22:28
Per Nilsson12-Dec-05 22:28 
QuestionCoCreateInstace Working Differently then createobject Pin
ky_rerun12-Dec-05 6:06
ky_rerun12-Dec-05 6:06 
QuestionATL COM Server throws Exception. Pin
Diana Fernandez12-Dec-05 0:36
Diana Fernandez12-Dec-05 0:36 
AnswerRe: ATL COM Server throws Exception. Pin
Diana Fernandez12-Dec-05 23:29
Diana Fernandez12-Dec-05 23:29 
QuestionWQL Queries for Win32_Directory Events Pin
ragavan11-Dec-05 19:14
ragavan11-Dec-05 19:14 
QuestionDisabling right click on flash OCX Pin
Xeronith10-Dec-05 19:03
Xeronith10-Dec-05 19:03 
Questioni cannt insert the values from an asp page to ms-acess database Pin
jibybabu9-Dec-05 2:44
jibybabu9-Dec-05 2:44 
QuestionCOM(WebBrowser Problem) Pin
Arun Appukuttan8-Dec-05 17:20
Arun Appukuttan8-Dec-05 17:20 
AnswerRe: COM(WebBrowser Problem) Pin
Sufyan_shani7-Jan-06 2:46
Sufyan_shani7-Jan-06 2:46 
GeneralRe: COM(WebBrowser Problem) Pin
Arun Appukuttan11-Jan-06 0:21
Arun Appukuttan11-Jan-06 0:21 
QuestionHow to call a C# com component from VC++ Pin
meesho8-Dec-05 10:34
meesho8-Dec-05 10:34 
AnswerRe: How to call a C# com component from VC++ Pin
Lim Bio Liong8-Dec-05 18:49
Lim Bio Liong8-Dec-05 18:49 
Questionhow to drag and drop xml element from treeview to web browser control Pin
fadi moon8-Dec-05 1:02
fadi moon8-Dec-05 1:02 
QuestionE-Book for ActiveX Programming Pin
Rajkamal_dfine6-Dec-05 18:08
Rajkamal_dfine6-Dec-05 18: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.