The pointer variable
ppSomeClass
serves as a return value. Therefore, in C/C++ you have to pass it by reference. There are two ways to do this: either you pass a variable of type reference to the original type, in this case reference to pointer:
HRESULT SomeClass::CreateInstance(HWND hVideo, HWND hEvent, SomeClass *& rpSomeClass)
, or you pass a variable of type pointer to the original type, in this case pointer to pointer.
HRESULT SomeClass::CreateInstance(HWND hVideo, HWND hEvent, SomeClass ** ppSomeClass)
If you do not do that, the calling program will never see any changes to that variable as it is passed by value only.
HRESULT SomeClass::CreateInstance(HWND hVideo, HWND hEvent, SomeClass *pSomeClass) {
}
void foo(HWND hVideo, HWND, hEvent) {
SomeClass* myptr = 0;
SomeClass::CreateInstance(hVideo, hEvent, myptr);
if (myptr == 0)
cout << "told you so!" << endl;
else {
}
}
venkatmakam tried to explain that in Solution 1, so you might want to try out the code he provided.