Click here to Skip to main content
15,925,369 members
Home / Discussions / COM
   

COM

 
GeneralRe: why CoCreateInstance( ... IID_IShellLink, ..) failed Pin
Lim Bio Liong19-Sep-03 0:53
Lim Bio Liong19-Sep-03 0:53 
GeneralKeeping COM server active Pin
Gilrock1-Sep-03 14:00
Gilrock1-Sep-03 14:00 
GeneralRe: Keeping COM server active Pin
igor19603-Sep-03 10:43
igor19603-Sep-03 10:43 
GeneralRe: Keeping COM server active Pin
Gilrock3-Sep-03 11:20
Gilrock3-Sep-03 11:20 
GeneralRe: Keeping COM server active Pin
igor19603-Sep-03 11:36
igor19603-Sep-03 11:36 
GeneralRe: Keeping COM server active Pin
Gilrock3-Sep-03 11:50
Gilrock3-Sep-03 11:50 
GeneralRe: Keeping COM server active Pin
igor19603-Sep-03 12:01
igor19603-Sep-03 12:01 
GeneralRe: Keeping COM server active Pin
Gilrock3-Sep-03 12:13
Gilrock3-Sep-03 12:13 
GeneralRe: Keeping COM server active Pin
Gilrock3-Sep-03 13:02
Gilrock3-Sep-03 13:02 
GeneralRe: Keeping COM server active Pin
Gilrock4-Sep-03 6:20
Gilrock4-Sep-03 6:20 
GeneralRe: Keeping COM server active Pin
igor19604-Sep-03 6:50
igor19604-Sep-03 6:50 
GeneralReturn Interface Pointer Pin
Daniel Strigl1-Sep-03 4:50
Daniel Strigl1-Sep-03 4:50 
GeneralRe: Return Interface Pointer Pin
valikac1-Sep-03 6:01
valikac1-Sep-03 6:01 
GeneralRe: Return Interface Pointer Pin
Daniel Strigl1-Sep-03 20:03
Daniel Strigl1-Sep-03 20:03 
GeneralRe: Return Interface Pointer Pin
Stefan Pedersen1-Sep-03 10:20
Stefan Pedersen1-Sep-03 10:20 
GeneralRe: Return Interface Pointer Pin
Daniel Strigl1-Sep-03 20:04
Daniel Strigl1-Sep-03 20:04 
GeneralRe: Return Interface Pointer Pin
Lim Bio Liong18-Sep-03 19:28
Lim Bio Liong18-Sep-03 19:28 
Hello Daniel,

I created a sample ATL project with two simple coclass's (Test and Test2). One of them, Test2 is specifically noncreatable. This noncreatble feature can be set easily by including the "noncreatable" attribute for the coclass statement in the IDL file :

[
uuid(A6C64958-F337-4981-8F31-F35AEA02DD98),
helpstring("Test2 Class"),
noncreatable
]
coclass Test2
{
[default] interface ITest2;
[default, source] dispinterface _ITest2Events;
};

This attribute is very useful when your client apps are Visual Basic based. In VB, if a coclass is noncreatable, then when you attempt to create a new instance of it via the "New" keyword, e.g. :

Dim Test2Obj As Test2
...
...
...
Set Test2Obj = New Test2

You will get an error message that reads : "Invalid use of New keyword".

However, the "noncreatable" attribute is not sufficient for VC++ clients. In a VC++ client app, if you have the following statement :

ITest2Ptr spTest2Ptr = NULL;

spTest2Ptr.CreateInstance(__uuidof(Test2));

Surprise, surprise, you will still succeed and obtain an ITest2 smart pointer.

In order to ensure that the above CreateInstance() function call will fail, you will need to comment out the Test2 Object Entry in the ATL Object Map of your ATL project :

BEGIN_OBJECT_MAP(ObjectMap)
OBJECT_ENTRY(CLSID_Test, CTest)
//OBJECT_ENTRY(CLSID_Test2, CTest2) <-- comment out this line.
END_OBJECT_MAP()

This will ensure that when your ATL DLL is asked to create an instance of an object of coclass Test2 (this happens in the global DllGetClassObject() function), a failure code will be returned.

Note that the good thing about the "noncreatable" attribute and the commenting out of the OBJECT_ENTRY statement will not prevent you from internally creating the CTest2 object. This is, of course, required when the GetInterface() method is called. My implementation of GetInterface() is as follows :

STDMETHODIMP CTest::GetInterface(int n, ITest2 **pITest2)
{
// TODO: Add your implementation code here
CComObject<ctest2> *pTest2New = NULL;

CComObject<ctest2>::CreateInstance(&pTest2New);

if (pTest2New)
{
pTest2New -> QueryInterface (IID_ITest2, (void**)pITest2);
}

return S_OK;
}

I will email you the sample source codes plus VB and a VC++ client apps.

Hope the aboe info will help.

Best Regards,
Bio.
GeneralRe: Return Interface Pointer Pin
Lim Bio Liong18-Sep-03 19:34
Lim Bio Liong18-Sep-03 19:34 
GeneralRe: Return Interface Pointer Pin
Daniel Strigl11-Oct-03 2:27
Daniel Strigl11-Oct-03 2:27 
Question&quot;parameter not optional&quot;? Pin
Yu Zhiquan1-Sep-03 1:24
Yu Zhiquan1-Sep-03 1:24 
AnswerRe: &quot;parameter not optional&quot;? Pin
Stefan Pedersen1-Sep-03 10:21
Stefan Pedersen1-Sep-03 10:21 
AnswerRe: &quot;parameter not optional&quot;? Pin
igor19603-Sep-03 10:59
igor19603-Sep-03 10:59 
GeneralThread Id of client app Pin
In-At31-Aug-03 23:08
In-At31-Aug-03 23:08 
GeneralRe: Thread Id of client app Pin
valikac1-Sep-03 6:03
valikac1-Sep-03 6:03 
GeneralRe: Thread Id of client app Pin
In-At1-Sep-03 18:26
In-At1-Sep-03 18:26 

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.