Does SHGetPathFromIDList () (and similar) put a 0 termination in the argument?

Actually this is a question about a huge number of winapi functions. Typical MS documentation says (from http://msdn.microsoft.com/en-us/library/bb762194(VS.85).aspx ):

BOOL SHGetPathFromIDList (      
    PCIDLIST_ABSOLUTE pidl,
    LPTSTR pszPath
);

pidl [in] The address of an item identifier list that specifies a file
or directory location relative to the root of the namespace (the desktop).

pszPath [out] The address of a buffer to receive the file system path.
This buffer must be at least MAX_PATH characters in size.

Nowhere is it said whether completion 0 is written to pszPath. Moreover, he does not say if pszPath can fill the path without leaving any room there.

Interaction with users on the distribution of users 50/50 users who allocate a buffer with MAX_PATH + 1 character and users who deal only with MAX_PATH.

Although I can, of course, do something like char buf [MAX_PATH + 1] = {0} to be safe, I would really like to know if there is a place where this material is described? Perhaps some page for all the functions related to the contour, I do not know ...

+3
source share
3 answers

To answer the title question: Yes. This is part of the LPTSTR definition - a pointer to a string. It is also displayed in the prefix: psz- "Pointer (to) String (terminates)" Zero ".

stringtype , API : UNICODE_STRING. API- .

+1

: " MAX_PATH " pszPath, MAX_PATH . , Win32, LPCTSTR/LPTSTR, .

+3

I don’t know how this function (or others) works, but I would recommend writing a few unit tests against this function ... What happens if you do not use the entire buffer? What happens if you do this? etc. These documents will not only document your assumptions, but if the function ever changes its behavior, you will receive a warning from your unit tests, and you will not receive an unpleasant error report.

+1
source

Source: https://habr.com/ru/post/1716231/


All Articles