Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
CComQIPtr spHst; 

HRESULT hr1 = CoCreateInstance( CClsid::m_CSFTHST, NULL, CLSCTX_LOCAL_SERVER, IID_ICSFTHST, (void **)&spHst); 


Instead to debugging every time, i want to write the value of spHst to a log file. So i want to put the value of spHst into a CString variable. how do i do that?

Also is there anyway i can check if the pointer spHst is pointing to a valid location?
Posted

1 solution

Here's an example:

C++
int a;
int* p = &a;
CString s;
s.Format(L"%p", p);
 
Share this answer
 
Comments
amarasat 1-Feb-11 15:04pm    
This is what i have tried:

ICSFTHST* temp = spHst;

CString HSTPointer;

HSTPointer.Format(L"%temp", temp);

now the string HSTPointer has a value "temp".

is this correct, can you give me the solution for my code.
Nish Nishant 1-Feb-11 15:09pm    
I already have. You need to use the %p formatter.
amarasat 1-Feb-11 15:16pm    
i got it!!

is there a way to check if spHst is pointing to a valid location? Other than to chack if it hasa value or not, is there any way to see if it is a valid pointer or not?
Nish Nishant 1-Feb-11 15:19pm    
There's no safe way to determine if a pointer is valid or not. Windows has functions such as IsBadWritePtr and IsBadReadPtr but they only tell you if you have read/write access to that memory.
amarasat 1-Feb-11 15:31pm    
OK thanks a lot for your help in all the posts!! if i need anything i will post here.

thank you!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900