Library SDK C example

Everything else that doesn't fall into one of the other PB categories.
Max.
Enthusiast
Enthusiast
Posts: 225
Joined: Fri Apr 25, 2003 8:39 pm

Library SDK C example

Post 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". :?
Athlon64 3800+ · 1 GB RAM · Radeon X800 XL · Win XP Prof/SP1+IE6.0/Firefox · PB 3.94/4.0
Intel Centrino 1.4 MHz · 1.5 GB RAM · Radeon 9000 Mobility · Win XP Prof/SP2+IE6.0/Firefox · PB 3.94/4.0
KarLKoX
Enthusiast
Enthusiast
Posts: 681
Joined: Mon Oct 06, 2003 7:13 pm
Location: France
Contact:

Post by KarLKoX »

2 - There are no majors differences between a call to a C function from C/C++ or from PureBasic.
"Qui baise trop bouffe un poil." P. Desproges

http://karlkox.blogspot.com/
Max.
Enthusiast
Enthusiast
Posts: 225
Joined: Fri Apr 25, 2003 8:39 pm

Post by Max. »

Thanks, guys.
Athlon64 3800+ · 1 GB RAM · Radeon X800 XL · Win XP Prof/SP1+IE6.0/Firefox · PB 3.94/4.0
Intel Centrino 1.4 MHz · 1.5 GB RAM · Radeon 9000 Mobility · Win XP Prof/SP2+IE6.0/Firefox · PB 3.94/4.0
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

Post 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).
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
Max.
Enthusiast
Enthusiast
Posts: 225
Joined: Fri Apr 25, 2003 8:39 pm

Post by Max. »

Thanks! Very good pointer! :wink:
Athlon64 3800+ · 1 GB RAM · Radeon X800 XL · Win XP Prof/SP1+IE6.0/Firefox · PB 3.94/4.0
Intel Centrino 1.4 MHz · 1.5 GB RAM · Radeon 9000 Mobility · Win XP Prof/SP2+IE6.0/Firefox · PB 3.94/4.0
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post 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++
@}--`--,-- A rose by any other name ..
Max.
Enthusiast
Enthusiast
Posts: 225
Joined: Fri Apr 25, 2003 8:39 pm

Post 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!
Athlon64 3800+ · 1 GB RAM · Radeon X800 XL · Win XP Prof/SP1+IE6.0/Firefox · PB 3.94/4.0
Intel Centrino 1.4 MHz · 1.5 GB RAM · Radeon 9000 Mobility · Win XP Prof/SP2+IE6.0/Firefox · PB 3.94/4.0
Post Reply