[Win32utils-devel] PathFindExtension and wide strings

Heesob Park phasis at gmail.com
Mon Nov 10 20:10:14 EST 2008


2008/11/11 Berger, Daniel <Daniel.Berger at qwest.com>:
> Hi,
>
> What's happening here?
>
> require 'windows/path'
> require 'windows/unicode'
>
> include Windows::Path
> include Windows::Unicode
>
> file_a = 'bar.txt'
> file_w = multi_to_wide(file_a)
>
> p PathFindExtensionA(file_a) # '.txt' => OK
> p PathFindExtensionW(file_w) # '.'    => WRONG
>
> Is Ruby chopping the result because of an embedding null? How do we deal
> with it?
>
The result is chopped by this code in api.c:

      case _T_STRING:
         v_return = rb_str_new2((TCHAR*)return_value);
         break;

In case of Unicode something like this would be possible:

      case _T_STRING:
         v_return = rb_str_new((TCHAR*)return_value,
wcslen((wchar_t*)return_value));
         break;


Regards,

Park Heesob


More information about the win32utils-devel mailing list