Issues calling winapi function


#1

Hi everyone,

I’m trying to call GetFullPathNameW winapi function.
It’s supposed to do something similar to std::fs::canonicalize but canonicalize does not work on WinXP/Server 2003 so I’m improvising :slight_smile:

https://is.gd/MNQs86 (the code does not compile as rust playground is not on windows)

The issue is that I get different result every time I run the compiled code. Even the returned length is different each time :confused:, but always greater than expected.
I thought that the winapi might give wrong results so I tested in C++ and that seems to work just fine.

I tried to compile for x86_64 and i686 with both gnu and msvc (with vs2015 and vs2013). Makes no difference.

Do you see anything obviously wrong with the code?


#2

Looks like path is not NULL-terminated. Try OsStr::new(".\0").


#3

Omg, I’m so dumb.
Thanks, that was it.


#4

Not dumb at all: it’s an easy thing to forget when you’re deep in the “all strings are null-terminated” weeds of C, C++, etc. (like I had been for years up till I started learning Rust). It’s an easy thing to forget (and I fixed no few bugs in C from people forgetting!).


#5

Yeah, I guess couple of months ago, I would have spotted it, but now I’m too used to the rust way of doing things :slight_smile:
It’s unbelievable, how rust has done so many things right!