MSVC .OBJ and Purebasic

Just starting out? Need help? Post your questions and find answers here.
MushroomHead
User
User
Posts: 15
Joined: Wed Apr 27, 2005 2:55 pm

MSVC .OBJ and Purebasic

Post 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.
traumatic
PureBasic Expert
PureBasic Expert
Posts: 1661
Joined: Sun Apr 27, 2003 4:41 pm
Location: Germany
Contact:

Re: MSVC .OBJ and Purebasic

Post 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
}


}
Good programmers don't comment their code. It was hard to write, should be hard to read.
MushroomHead
User
User
Posts: 15
Joined: Wed Apr 27, 2005 2:55 pm

Re: MSVC .OBJ and Purebasic

Post by MushroomHead »

Hello,

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