Strings are immutable, you cannot pass it directly, even if you pin it. More seriously, you will have to deal with the possibility that the function returns a larger string. The function is unsafe by design since you cannot prevent it from returning a path string that's too large. Not much you can do about that I suppose, but you will have to use a buffer that's at least large enough for common path strings. This code will get the job done:
#include <vcclr.h>
...
String^ file = "blah.txt";
wchar_t path[_MAX_PATH];
{
pin_ptr<const wchar_t> wch = PtrToStringChars(file);
wcscpy_s(path, _MAX_PATH, wch);
}
BOOL ok = PathFindOnPath(path, something);
The curly braces look odd perhaps, it ensures that the managed string doesn't stay pinned for too long.