EldoS | Feel safer!

Software components for data protection, secure storage and transfer

which parameter is invalid if error -24 is throwed?

Also by EldoS: SecureBlackbox
200+ components and classes for digital security, signing, encryption and secure networking.
#20934
Posted: 07/31/2012 12:13:58
by Rafal Grasman (Basic support level)
Joined: 07/31/2012
Posts: 6

I have this code:

Code
enum filemode {
  io_read,      /*  */
  io_write,     /* creates a new file */
  io_readwrite, /*  */
  io_append,    /* opened for writing only and seek to the end */
};

enum seek_whence {
  seek_start,
  seek_current,
  seek_end,
};

char * g_sz_tmp;

static cell AMX_NATIVE_CALL n_FileOpen( AMX* amx, cell* params )
{
   PSolFSHandle File = NULL;
   amx_StrParam(amx,params[1],g_sz_tmp);
  switch (params[2] & 0x7fff) {
  case io_read:
    result = StorageCreateFile(storage,(PSolFSWideChar)g_sz_tmp,true,false,true,true,NULL,NULL,NULL,File,true,false);
    break;
  case io_write:
    result = StorageCreateFile(storage,(PSolFSWideChar)g_sz_tmp,false,true,true,true,NULL,NULL,NULL,File,true,true);
    break;
  case io_readwrite:
    result = StorageCreateFile(storage,(PSolFSWideChar)g_sz_tmp,true,true,true,true,NULL,NULL,NULL,File,true,false);
    break;
  case io_append:
    result = StorageCreateFile(storage,(PSolFSWideChar)g_sz_tmp,false,true,true,true,NULL,NULL,NULL,File,true,false);
   StorageSeekFile(File,0,soFromEnd,NULL);
    break;
  default:
    return 0;
  } /* switch */
  if(result == 0)
  {
   return (cell)File;
  }
  printf("fopen error %d(%x)",result,result);
  return 0;
}


and a -24 error is thrown which means one parameter is invalid. I tried replacing
Code
(PSolFSWideChar)g_sz_tmp

with
Code
L"test.txt"

but it still gave me the -24 error.
Which parameter is wrong here?
#20935
Posted: 07/31/2012 12:38:08
by Alexander Plas (EldoS Corp.)

Hello

Most of all you haven't initialized storage variable in one of StorageCreate or StorageOpen functions.

The g_sz_tmp parameter must be encoded in UTF-16, you can declare it as L"filename.ext" or convert with StorageAnsiToWideChar function.

Also you have to declare File variable as:
Code
SolFSHandle File = NULL;

and pass it then by reference in StorageCreateFile function
Code
StorageCreateFile(storage, ... ,&File,..);
#20936
Posted: 07/31/2012 12:52:20
by Rafal Grasman (Basic support level)
Joined: 07/31/2012
Posts: 6

Quote
plas wrote:
or convert with StorageAnsiToWideChar function


Thanks for the response, I think the Application Edition doesn't support the conversion function?

Code
SolFS\Win32\StaticLib\SolFS.lib

is linked and I get:

1>main.obj : error LNK2001: unresolved external symbol _StorageAnsiToWideChar@16

Edit:
Anyway I tried to do without the SotrageAnsiToWideChar, which resulted in the following code:
Code
/*
* Default Includes
*/
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <assert.h>
/*
* AMX Includes
*/
#include "./SDK/amx/amx.h"
#include "./SDK/plugincommon.h"
#include "StoreDecl.h"

extern void * pAMXFunctions;

using namespace std;  

PLUGIN_EXPORT unsigned int PLUGIN_CALL Supports()
{
   return SUPPORTS_VERSION | SUPPORTS_AMX_NATIVES;
}

Error result;
Handle storage;

PLUGIN_EXPORT bool PLUGIN_CALL Load( void **ppData )
{
   pAMXFunctions = ppData[PLUGIN_DATA_AMX_EXPORTS];
   cout << "    SS © 2012 by Gamer_Z | Loading SolFS...\n";

   //Solid Filesystem Storage KEY | aquire your own key for custom builds
   result = StorageSetRegistrationKey((PSolFSChar)"My License Key Here");
   //
   if (result != 0)
   {
      printf("SolFS Registration key error: %d\n", result);
      return false;
   }
   else
   {
      printf("SolFS Registration key is OK\n");
   }
   result = StorageCreate(L"SCRIPTFILES-VFS.ST", False, 512, NULL, &storage, '/', False, False);
   if (result != 0)
   {
      if(result != 80)
      {
         printf("SolFS error: %d\n", result);
         return false;
      }
      printf("SolFS accessing storage is OK\n");
   }
   else
   {
      printf("SolFS accessing storage is OK\n");
   }
   
   cout << "Loaded!\n";
   StorageCreateDirectory(storage, L"/temp");
   return true;
}

PLUGIN_EXPORT void PLUGIN_CALL Unload( )
{
   result = StorageClose(storage);
   if (result != 0)
      printf("SolFS error: %d\n", result);
   cout << "    SS © 2012 by Gamer_Z";
}

enum filemode {
  io_read,      /*  */
  io_write,     /* creates a new file */
  io_readwrite, /*  */
  io_append,    /* opened for writing only and seek to the end */
};

enum seek_whence {
  seek_start,
  seek_current,
  seek_end,
};

char * g_sz_tmp;

static cell AMX_NATIVE_CALL n_FileOpen( AMX* amx, cell* params )
{
   SolFSHandle File = NULL;
   amx_StrParam(amx,params[1],g_sz_tmp);
   PSolFSWideChar wg = (PSolFSWideChar)g_sz_tmp;
   //StorageAnsiToWideChar((PSolFSChar)g_sz_tmp,&wg,NULL,false);
   printf("strx: %s\n",wg);
   switch (params[2] & 0x7fff)
   {
      case io_read:
         result = StorageCreateFile(storage,wg,true,false,true,true,NULL,NULL,NULL,&File,true,false);
         break;
      case io_write:
         result = StorageCreateFile(storage,wg,false,true,true,true,NULL,NULL,NULL,&File,true,true);
         break;
      case io_readwrite:
         result = StorageCreateFile(storage,wg,true,true,true,true,NULL,NULL,NULL,&File,true,false);
         break;
      case io_append:
         result = StorageCreateFile(storage,wg,false,true,true,true,NULL,NULL,NULL,&File,true,false);
         StorageSeekFile(File,0,soFromEnd,NULL);
         break;
      default:
         return 0;
   } /* switch */
   if(result == 0)
   {
      return (cell)File;
   }
   printf("fopen error %d(%x)",result,result);
   return 0;
}


and still seems to give the -24 error while the printf function prints the right characters.

EDIT2:
OK I got rid of the -24 error, it works, just.. now I have a problem: the filename which is created etc is always "???" (viewed in SolFSExplorer), while printf does print the correct filename.

So how would I convert char* to PSolFSWideChar?


EDIT3:
Almost got it working, the result is now 0, but the undelying application gets an 0 file handle, can 0 be a file handle? I do not see the created file with solfsexplorer.

Code
char * g_sz_tmp;
static cell AMX_NATIVE_CALL n_FileOpen( AMX* amx, cell* params )
{
   Handle File = NULL;
   SolFSWideChar * g_sz_wtmp;
   amx_StrParam(amx,params[1],g_sz_tmp);
   wstringstream xxx;
   xxx << g_sz_tmp;
   wsprintf(g_sz_wtmp,xxx.str().c_str());
   wprintf(L"strx: <>%s<>%s<>\n",g_sz_wtmp,xxx.str().c_str());
   switch (params[2] & 0x7fff)
   {
      case io_read:
         result = StorageCreateFile(storage,g_sz_wtmp,True,False,True,True,NULL,NULL,NULL,&File,True,False);
         break;
      case io_write:
         result = StorageCreateFile(storage,g_sz_wtmp,False,True,True,True,NULL,NULL,NULL,&File,True,True);
         break;
      case io_readwrite:
         result = StorageCreateFile(storage,g_sz_wtmp,True,True,True,True,NULL,NULL,NULL,&File,True,False);
         break;
      case io_append:
         result = StorageCreateFile(storage,g_sz_wtmp,False,True,True,True,NULL,NULL,NULL,&File,True,False);
         StorageSeekFile(File,0,soFromEnd,NULL);
         break;
      default:
         return 0;
   } /* switch */
   if(result == 0)
   {
      return (cell)File;//returns null or 0 file handle, calling application sees invlid file handle
   }
   printf("fopen error %d(%x)",result,result);
   return 0;
}
#20937
Posted: 07/31/2012 14:36:50
by Alexander Plas (EldoS Corp.)

The question marks is only result of direct conversation from char* to PSolFSWideChar.

Yes, conversation functions in not implemented yet is App Edition. You can use WideCharToMultiByte function under Windows or libiconv under Linux or Mac OS.
#20938
Posted: 07/31/2012 14:42:27
by Rafal Grasman (Basic support level)
Joined: 07/31/2012
Posts: 6

The way I used is good too, i think? or is it that why the file doesn't get created in the storage?

Edit: this issue can be closed.
Also by EldoS: CallbackFilter
A component to monitor and control disk activity, track file and directory operations (create, read, write, rename etc.), alter file data, encrypt files, create virtual files.

Reply

Statistics

Topic viewed 2218 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!