Ofer
Ofer

Reputation: 333

Proper use of GetLongPathName function

I want to use the GetLongPathName function exactly the same way I'm using the GetShortPathName:

  1. Call the function with NULL as output param for getting the size to allocate.
  2. Allocate the string dynamically.
  3. Call the function again with the allocated string.

GetShortPathName MSDN page says:

Passing NULL for lpszShortPath and zero for cchBuffer will always return the required buffer size for a specified lpszLongPath.

That note is not exists in GetLongPathName function so I'm afraid to use the function that way.

So, what is the proper use for that function?

Upvotes: 2

Views: 991

Answers (1)

Leandro Caniglia
Leandro Caniglia

Reputation: 14868

You can call GetLongPathName with either an empty or a NULL buffer and it will answer with the required buffer length.

In other words, you can pass NULL for the lpszLongPath argument and 0 for cchBuffer.

Upvotes: 3

Related Questions