Seeing S_FALSE in HRESULT variable with CheckAndSavePKey

So, I'm on Windows and getting a successful build with VS 2012 Express. I'm using static libraries and had to use the WinDDK to get some libraries that didn't ship with VS 2012 Express that are required for use with LimeLM. However, when I test the app's registration feature it fails. So, I placed a breakpoint at the logic gates directly after the CheckAndSavePKey() function, and when I look at the response it appears I'm getting something that says S_FALSE instead of any of the response codes that are documented in the TurboActivate.h file. I'm not sure what S_FALSE stands for, and thought I would ask on the forums. I thought it might have to do with the difference between TA_USER and TA_SYSTEM since permissions always seem to be an issue, but am not sure. Because I'm building versions of my app for Windows and OSX, I am using pre-processor directives to switch. Here is the code:

#if _WIN32 hr = CheckAndSavePKey(STRCTYPE(serial.c_str()), TA_USER);#else hr = CheckAndSavePKey(serial.c_str(), TA_USER);#endifif (hr == TA_OK){ printf("\nProduct key saved successfully.\n"); hr = Activate();

} else {

printf("\nProduct key failed to save: hr = %i\n", hr);}

Any ideas why I might be getting S_FALSE?

Turns out it was this line:

hr = CheckAndSavePKey(STRCTYPE(serial.c_str()), TA_USER);

The problem is the first parameter for CheckAndSavePKey. The variable `serial` is of type `string`, and this works on OSX, but not on Windows. My project's VS 2012's settings have the `Character Set` set to Unicode, so I'm not sure how to pass in the serial since I need it to be a `string` type. Any ideas?

Thanks,Arie

All functions in TurboActivate require unicode strings. However the type of unicode TurboActivate expects is different for Windows than for other platforms. On Windows you need to use double-byte strings (UTF-16), a.k.a. whcar_t * strings.

On other platforms UTF-8 strings are required. (char * strings).

Also "casting" a char * string to wchar_t * string won't actually convert the encoding. It will just trick the compiler and pass garbage to the TurboActivate library.

http://stackoverflow.com/questions/402283/stdwstring-vs-stdstring

Thanks for the pointer to the stackoverflow thread. I took a read through, but don't entirely understand how to solve the issue. I would rather not put a bunch of pre-processor branches just to acommodate Windows specific datatype nuances, though. Is there a best practice for strings that will work on both OSX and Windows?

Thanks,Arie

Yeah, the C/C++ example shows how to do this -- TCHAR * for variable strings and _T() for literal strings.

Of course, this requires working with string arrays directly, rather than working with convenience classes liks std::string or std::wstring.