Page 1 of 1

MSVC .OBJ and Purebasic

Posted: Wed Apr 27, 2005 3:01 pm
by MushroomHead
Hello,

Does anyone have a "C" source function done in MSVC which passes and returns a simple string to a PureBasic application? I have had a look at the LCCWin example but can't get it working in MSVC.

Any help appreciated.

Re: MSVC .OBJ and Purebasic

Posted: Wed Apr 27, 2005 5:20 pm
by traumatic
Hi and welcome to the forums!
MushroomHead wrote:[...] but can't get it working in MSVC.
What kind of problems do you have exactly? What is it that doesn't work?

I just tried the following code (almost 1:1 from the sdk-example) and
everything worked as expected:

Code: Select all

#include <windows.h>

extern "C" {


extern char     *PB_StringBase;


// String return example ------------------------------------------------------------------

extern char* _stdcall 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
}


}

Re: MSVC .OBJ and Purebasic

Posted: Wed Apr 27, 2005 5:37 pm
by MushroomHead
Hello,

Looks like I missed the extern "C" bit ... thanks for clearing it up.