Click here to Skip to main content
15,900,378 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Searching multiple files for text or phrases? Pin
David Crow12-Feb-08 2:21
David Crow12-Feb-08 2:21 
AnswerRe: Searching multiple files for text or phrases? Pin
Hamid_RT11-Feb-08 3:42
Hamid_RT11-Feb-08 3:42 
Generalimage file into sqldb Pin
Paulraj G11-Feb-08 1:18
Paulraj G11-Feb-08 1:18 
GeneralRe: image file into sqldb Pin
David Crow11-Feb-08 3:11
David Crow11-Feb-08 3:11 
QuestionAudio Device Enumeration Pin
~Jabeen~10-Feb-08 23:01
~Jabeen~10-Feb-08 23:01 
GeneralRe: Audio Device Enumeration Pin
Rajkumar R10-Feb-08 23:10
Rajkumar R10-Feb-08 23:10 
GeneralRe: Audio Device Enumeration [modified] Pin
Rajkumar R10-Feb-08 23:19
Rajkumar R10-Feb-08 23:19 
Generaltype safe issue Pin
George_George10-Feb-08 22:47
George_George10-Feb-08 22:47 
Hello everyone,


My question is whether my understanding of the solution to type safe issue in CoCreateInstance is correct. There is type safe issue in CoCreateInstance,

http://msdn2.microsoft.com/en-us/library/ms686615.aspx

STDAPI CoCreateInstance(
REFCLSID rclsid,
LPUNKNOWN pUnkOuter,
DWORD dwClsContext,
REFIID riid,
LPVOID * ppv
);

which means the riid and ppv may not conform to each other, for example, we have a IY* variable pIY and wants to get IZ type interface, CoCreateInstance (rclsid, pUnkOuter, dwClsContext, IID_IZ, &pIY);

To solve this issue, the solution from Inside COM is,

1. Define a template class smart pointer IComPtr<t, iid*="" iid="">, where T is type of interface to wrap, iid is its related interface IID;
2. Define a function in the template class called CreateInstance, the implementation is,

2.1 invoke Release(); // release previous held pointer
2.2 invoke CoCreateInstance (rclsid, pUnkOuter, dwClsContext, *iid, &m_pI); // m_pI the wrapped interface pointer member variable for the smart pointer template class.

I think why the solution works, is because in the creation of the template class, the interface type T and iid is matched (example, through constructor or assignment operator), so when using the internal variable *iid and m_pI to invoke CoCreateInstance, the type always match (Interface ID and Interface type).

Is my understanding correct?


thanks in advance,
George
GeneralRe: type safe issue [modified] Pin
Rajkumar R11-Feb-08 0:06
Rajkumar R11-Feb-08 0:06 
GeneralRe: type safe issue Pin
Matthew Faithfull11-Feb-08 0:10
Matthew Faithfull11-Feb-08 0:10 
GeneralRe: type safe issue Pin
Rajkumar R11-Feb-08 0:39
Rajkumar R11-Feb-08 0:39 
GeneralRe: type safe issue Pin
Matthew Faithfull11-Feb-08 0:59
Matthew Faithfull11-Feb-08 0:59 
GeneralRe: type safe issue [modified] Pin
Rajkumar R11-Feb-08 1:33
Rajkumar R11-Feb-08 1:33 
GeneralRe: type safe issue Pin
Matthew Faithfull11-Feb-08 2:53
Matthew Faithfull11-Feb-08 2:53 
GeneralRe: type safe issue Pin
Rajkumar R11-Feb-08 3:17
Rajkumar R11-Feb-08 3:17 
GeneralRe: type safe issue Pin
CPallini11-Feb-08 3:20
mveCPallini11-Feb-08 3:20 
GeneralRe: type safe issue Pin
Rajkumar R11-Feb-08 3:26
Rajkumar R11-Feb-08 3:26 
GeneralRe: type safe issue Pin
CPallini11-Feb-08 3:41
mveCPallini11-Feb-08 3:41 
GeneralRe: type safe issue Pin
Rajkumar R11-Feb-08 3:54
Rajkumar R11-Feb-08 3:54 
QuestionRe: type safe issue Pin
CPallini11-Feb-08 4:10
mveCPallini11-Feb-08 4:10 
GeneralRe: type safe issue Pin
Rajkumar R11-Feb-08 4:12
Rajkumar R11-Feb-08 4:12 
QuestionRe: type safe issue Pin
CPallini11-Feb-08 5:11
mveCPallini11-Feb-08 5:11 
GeneralRe: type safe issue [modified] Pin
Matthew Faithfull11-Feb-08 3:28
Matthew Faithfull11-Feb-08 3:28 
GeneralRe: type safe issue [modified] Pin
Rajkumar R11-Feb-08 3:52
Rajkumar R11-Feb-08 3:52 
GeneralRe: type safe issue Pin
Matthew Faithfull11-Feb-08 4:29
Matthew Faithfull11-Feb-08 4:29 

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.