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.
MSVC .OBJ and Purebasic
Re: MSVC .OBJ and Purebasic
Hi and welcome to the forums!
I just tried the following code (almost 1:1 from the sdk-example) and
everything worked as expected:
What kind of problems do you have exactly? What is it that doesn't work?MushroomHead wrote:[...] but can't get it working in MSVC.
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.
-
- User
- Posts: 15
- Joined: Wed Apr 27, 2005 2:55 pm
Re: MSVC .OBJ and Purebasic
Hello,
Looks like I missed the extern "C" bit ... thanks for clearing it up.
Looks like I missed the extern "C" bit ... thanks for clearing it up.