Page 1 of 1

Library SDK C example

Posted: Sun Jul 25, 2004 4:30 pm
by Max.
I am trying to learn more about C and am fiddling withe the very simple test.c from the \LccWin32 directory. Most of interest for me is this function at the moment:

Code: Select all

extern _stdcall char *PB_StringMultiply(char *String, int NbTimes)
{
  char *ResultString = PB_StringBase;
  int   k;

  if (String && *String)  // It's always good for safety and perfomance to exclude null or empty strings
  {
    int StringLength = strlen(String);

    for (k=0; k<NbTimes; k++)
    {
      strcpy(PB_StringBase, String);
      PB_StringBase += StringLength;  // Increase the output string buffer
    }
  }

  *PB_StringBase = 0;     // Finally write the zero ending string. PB_StringBase contains the result string

  return ResultString;    // Returns the start of the buffer, as it has been passed
}
and while I understand the code itself, I got a rough time using/calling it.

What I am trying to do is to add it to the main function

Code: Select all

int main()
	{
		PB_MessageBox(0, "Titre", "Text", 0);
		return 0;
	}
along the line "output the result in the message box" but anytime I execute it, it crashes.

Basically I got two questions:

1. Anyone knowing a good book about C, preferably online, with some nice examples on pointers and string handling?

2. Is there any special difference between a C function for use in another C source and a C function that is written for PureBasic? How would I need to call the PB_StringMultiply from C?

Thanks; I know my request is along the line "enlighten me". :?

Posted: Sun Jul 25, 2004 7:00 pm
by jack

Posted: Sun Jul 25, 2004 9:59 pm
by KarLKoX
2 - There are no majors differences between a call to a C function from C/C++ or from PureBasic.

Posted: Sun Jul 25, 2004 10:05 pm
by Max.
Thanks, guys.

Posted: Sun Jul 25, 2004 10:52 pm
by tinman
If you are testing your library examples from some C main() function then you need to make sure you have all the PB global variables initialised to something sensible for your code (e.g. the PB_StringBase in your case should point to e.g. a 64k block of memory that you have allocated, to make it similar to what woud happen in PB programs).

Posted: Sun Jul 25, 2004 11:09 pm
by Max.
Thanks! Very good pointer! :wink:

Posted: Mon Jul 26, 2004 8:46 am
by Dare2
jack wrote:a couple of downloadable books.
Thanks for those links, Jack. Just starting to wade into the DL books, and the info seems pretty useful, some aha info useful even outside c, c++

Posted: Mon Jul 26, 2004 9:16 am
by Max.
Yep, very good!

I managed to get running what I wanted to! Together with the site about strings in C, tinman's hint did it!