winapi - In Windows API application-defined callback functions, what is the lifetime of pointer parameter data? Does it persist after the callback returns? -


as example, let's @ enumwindowstations(), requires caller pass enumwindowstationsproc() callback function. callback function invoked once every window station in current terminal session. let's @ signature of callback function:

bool callback enumwindowstationproc(     _in_ lptstr lpszwindowstation,     _in_ lparam lparam ); 

the first parameter pointer string data. string buffer allocated explicitly callback invocation, , freed after callback returns, or perhaps before enumeration function returns? or, pointer point kind of persistent memory, such string buffer remain allocated , usable afterward?

this important point, because if not persistent, incorrect to, example, store raw pointer in global container accessed after callback , full enumeration process have finished. instead, necessary copy underlying string data buffer controlled application, before callback returns.

the official documentation not seem make clear lifetime of string data is. there's 1 line in description of parameter:

lpszwindowstation [in]

    the name of window station.

and on documentation page talk lifetime of string data. nor can recall ever finding msdn page answers question "once , all", i.e. uses of callback idiom in windows api.

at moment interested in enumwindowstations()/enumwindowstationsproc() case, best if answerers address general case, i.e. assume windows api callback functions.

generally if memory allocated system can rely on being valid duration of callback , no more. case lpszwindowstation in example. need access , copy string inside callback function , must not refer system supplied data outside callback.

you can deduce little thought experiment. if string accessed after callback returned when become invalid? when deallocated? you'd have tell system done it. since there no api indicated conclusion stated above.

things different lparam. value supplied when called enumwindowstations , manage lifetime of whatever points to, if indeed using pointer.


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -