PDetsFromPath fails on Windows

On Windows, PDetsFromPath always return 8 (failed to load TurboActivate.dat) even though I verified that the .dat file pathname passed to PDetsFromPath is correct.

The same .dat file loads fine under Linux (using the same code). The code compiles and links, so this is not the problem.

Any hints as to why this might be happening?

My guess is that you're not using Unicode strings (or that you're "casting" char * strings to wchar_t* strings to get rid of the error -- which doesn't actually solve the problem). Can you show me the code you're using and tell me the language you're using?

Thank you. Here is the code:

#ifdef _WIN32#include <tchar.h>#else#define _T(x) xtypedef char TCHAR;#endif

void load_datfile(STRCTYPE datfile) { HRESULT hr = PDetsFromPath(datfile); fprintf(stderr,"load datfile retcode = %d\n", hr); fprintf(stderr,"datfile = %s\n", datfile);}

So, when called, I see it prints the right file name but the retcode is 8. It happens both on 32 and 64 bit Windows 7 (on top of Virtual Box) and under 32 bit Windows 10 on a real machine. The file name looks like this: c:\Users\me\Turboactivate.dat

OK, show me the call to load_datfile(), because what that code is showing me (specifically the fact that PDetsFromPath(datfile) is failing and this is succeeding when it should fail: fprintf(stderr,"datfile = %s\n", datfile);, is that you're still passing in a char* string instead of a wchar_t* string.)

fprintf() with a wide-character string will output garbage. The fact that you're not seeing garbage means that you're using char* strings. See: https://msdn.microsoft.com/en-us/library/xkh07fe2.aspx

Does that make sense?

To put it more clearly. This will succeed:

HRESULT hr = PDetsFromPath(L"c:\\Users\\me\\Turboactivate.dat");

This will not:

HRESULT hr = PDetsFromPath("c:\\Users\\me\\Turboactivate.dat");

Do you see why? Notice the unicode string literal L that precedes the quotes?

See: https://msdn.microsoft.com/en-us/library/69ze775t.aspx

Thanks a lot! It would be good if it was made clear in TurboActivate.h that regular char-strings must be converted to wchar_t-strings on Windows. Also, a C example would have been handy.It is not just PDetsFromPath but many other functions expect wchar.

Anyway, now it works. Thanks for the hint.

Also, a C example would have been handy.

There is a C/C++ example in the API\C folder in the TurboActivate package. Open the Example.c file. It shows using the correct strings on different platforms: wchar_t* on Windows and char* on Unix.

There is a little L"...." in the comments in one place. Wide chars or wchar_t is not mentioned anywhere in the example. This is definitely not enough, since conversion to wchar is crucial to have many calls working.

It's presumed developers will see that the functions accept wide-char strings on Windows.But even if you don't see that -- if you try to pass char* strings then the compiler will throw an error. You should never "cast" to a different type and assume that will fix the problem -- the datatype matters.