TA_PDetsFromByteArray in C++

Hi Wyatt,

I'd like to avoid the explicit usage of Turboactivate.dat in the folder of my application by adding this file in my application's resource file. From what I've realized I can do this replacing all the calls to TA_PDetsFromPath with TA_PDetsFromByteArray(pointer to the content of Turboactivate.dat, size of the content). Is there an example to show how the code should work in C/C++? I'm trying all the possible casts to uint8_t* but I'm getting always TA_E_PDETS.

Thanks in advance,

Alessandro

Hey Allesandro,

You need to put the full contents of the TurboActivate.dat file in memory in a "unsigned char *" array, and you must pass the pointer to the first element of the array and the full length of the array to the TA_PDetsFromByteArray() function.

If you show me a piece of code that's failing I'll be able to tell you why.

Hi Wyatt,I've simplied a lot, but this is still failing. I'm using Qt4 to get the file content

QFile f(":/resources/TurboActivate.dat");if (!f.open(QIODevice::ReadOnly)) { // "Cannot open resource file!"; return false;}QTextStream fStream(&f);QString content = fStream.readAll();size_t siz = static_cast<size_t>(content.size());std::string s = content.toStdString();unsigned char *byteArr = new unsigned char[siz * sizeof(unsigned char)];std::copy(s.begin(), s.end(), byteArr);hr = TA_PDetsFromByteArray(&byteArr[0], siz);delete[] byteArr;

Thanks in advance,

Alessandro

I do exactly that, here's the code I use.

/*...........................................*/static BOOL DatPathSet;


static HRESULTSetDatFilePath(void){   if (!DatPathSet) {      HRESULT rslt;      HRSRC hRsrc = FindResourceEx(hInstApp,RT_RCDATA,MAKEINTRESOURCE(ID_RCDATA_TURBOACTIVATE),0);      HGLOBAL hData;      UINT dwSize;      BYTE *pData;


      if (!hRsrc) return TA_E_PDETS;      hData = LoadResource(hInstApp,hRsrc);      dwSize = SizeofResource(hInstApp,hRsrc);      pData = LockResource(hData);      rslt = TA_PDetsFromByteArray(pData,dwSize);      if (rslt!=TA_OK) return rslt;      DatPathSet = TRUE;   }   return TA_OK;}


/*....................................................*/

Hi Alessandro,

I'm using the TA_PDetsFromByteArray function in my applications. To include the data I just convert the TurboActivate.dat into a C-header using the Linux command xxd:

xxd -i TurboActivate.dat > pdets.h

This defines an array and size variable:uint8_t TurboActivate_dat[] = { 0xDE, 0xAD, 0xBE, 0xEF,...

unsigned int TurboActivate_dat_len = 4054;

Then I pass these parameters to the PDets function:

hr = TA_PDetsFromByteArray( TurboActivate_dat, TurboActivate_dat_len );

I can't say why your approach is failing, but I suppose the QTextStream reader might be doing something unexpected since the file is not text.

Hope that helps!

Thanks to all for the suggestions.We have adopted the last one: our deployment system is generating a header file which is included in the source file system before the compilation. In this way we have also the advantage to avoid C++ functions to read from the resource file.

Those "C++ functions to read from the resource file" are standard Win32/Win64 API functions. You don't need to implement them yourself.

Embedding a data file as a custom (rcdata) resource is a quite common practice. It has the advantage that the dat file itself can be included directly in your build. You don't have to preprocess it to produce a header file. And of course, like the header file idea, it ensures that the correct version of the data file can't become separated from the matching exe.