// PtrToDouble.cpp : Implementation of CPtrToDouble #include "stdafx.h" #include "A4.h" #include "PtrToDouble.h" #include using namespace std; ///////////////////////////////////////////////////////////////////////////// // CPtrToDouble STDMETHODIMP CPtrToDouble::myFunction(DOUBLE *pDouble) { cout << "\n\nInside myFunction:" << "\n value passed in = " << (*pDouble); *pDouble = (*pDouble) * (*pDouble); cout << "\n squared value of input = " << *pDouble; cout << "\n address of double variable = " << pDouble << endl; // The next statement doesn't make sense. I've put this here // simply to demonstrate that while we can change the memory // location pointed to inside this function, we can't change the // memory pointed to by pDouble outside this function. To do // that we would need to use another level of indirection, e.g., // DOUBLE **ppDouble. pDouble = (DOUBLE*)CoTaskMemAlloc(sizeof(DOUBLE)); *pDouble = 0.33333; cout << "\n changing location pointed to in component " << "\n won't change location pointed to in client" << "\n new address of double variable = " << pDouble << "\nLeaving myFunction:" << endl; return S_OK; }