GLBasic forum

Main forum => GLBasic - en => Topic started by: FutureCow on 2009-Nov-19

Title: Inline help
Post by: FutureCow on 2009-Nov-19
Can someone lend some inline advice?

I have a bit of inline code I'm trying to migrate to GLBasic. The first function opens a file, creates a memory buffer and dumps the contents in the file.
I know how to read a file into a string or an array, but I'm not sure then how to modify the later functions that are written to use a C memory buffer to either use the GLBasic string or array.

The C code that opens a file and dumps the contents into a memory buffer (so you know what the variables used are) :-
Code (glbasic) Select
   
  FILE *fh;

  if((fh = fopen(argv[1], "rb")))
  {
    unsigned long size;

    if(!fseek(fh,0,SEEK_END) && (size = ftell(fh)) != EOF && !fseek(fh,0,SEEK_SET))
    {
      unsigned char *mem;
      if((mem = (unsigned char *) malloc(size+3)))
      {
        if(fread(mem, size, 1, fh) == 1)


Here's one of the later bits code that uses the memory buffer. How would I change this (the "Mem" pointer) to access the contents of a GLBasic string or array please?
Code (glbasic) Select

unsigned long DoCRC32_1(const unsigned char * Mem, signed long Size)
{
  unsigned long val = 0;
  unsigned long buf[256];

[... populates the buf array...]

  while(Size--)
    val = buf[*(Mem++);

Title: Re: Inline help
Post by: Kitty Hello on 2009-Nov-19
http://www.glbasic.com/forum/index.php?topic=3841.0 (http://www.glbasic.com/forum/index.php?topic=3841.0) <-- read a file to a string.
You can use the buffer then as:
Code (glbasic) Select

((const unsigned char*)buffer_Str.c_str())


Title: Re: Inline help
Post by: FutureCow on 2009-Nov-19
Awesome! Cheers!