Possible to cast void* (Handle) to string?

I have a external generic function that sets a void* 'returnData':

1
2
3
4
SPErr PIUGetInfo(ClassID desiredClass,  KeyID desiredKey,  void * returnData, void * returnExtraData)
{
...
}


Currently I am passing it a Handle:
1
2
Handle alias;
PIUGetInfo(classDocument, keyFile, &alias, NULL);


But if there is no Document, alias is not assigned and I get an exception. Is it possible to cast alias to a string or is there a function to return if it's a un-assigned value?

alias == nullptr does not work.
Last edited on
yes, you can cast a void* to any other *.

so

string * sp = (string*)returndata;
or

string s( (char*)returndata ); //cast to c-string and drop into normal string, if the type is char*

I can't recall, is Handle just a void* abstraction?


Bah, I forgot the pointer in the cast.

But yes, from what I understand handle is a void abstraction, so it seems the cast will not work in my case. Do you have a suggestion on how to check if returndata has been assigned with something?
Make sure you assign an initial value (nullptr) before calling the function. Then if it is still nullptr after the function call, you know nothing was assigned.
Make sure you assign an initial value (nullptr) before calling the function. Then if it is still nullptr after the function call, you know nothing was assigned.


I... Did not think of that... Thank you!... +1
Last edited on
What is that SPErr in SPErr PIUGetInfo(...?
What value does that function return?
What is that SPErr in SPErr PIUGetInfo(...?
What value does that function return?


Returns an int, but it always returns 0, unless a document is not open (I have documents open but I need to check if they have files attached to them and not a "new" document).

So I am unable to use it in this case. Setting the handle to nullptr and checking if it's been assigned after works in my case.
Topic archived. No new replies allowed.