Pure Library, How Do You Return a String in C?

Everything else that doesn't fall into one of the other PB categories.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by wayne1.

I have no problem returning numeric variables to a pure library function in C
but a can't get a string variable to return obviously I'm coding wrong but I can't figure out what. My Pure Library .desc file is correct
Below is three test functions that are working C code but will not work as a
pure library. Any help would be appreciated.



#define PURELIBRARY
#include
#include
#include
#ifdef PURELIBRARY
extern HINSTANCE PB_Instance;
#else
HINSTANCE PB_Instance;
#endif



extern char* _stdcall PB_ReturnParam1(char source[])
{

//MessageBox(0,source,"",0);

return source;
}


extern char* _stdcall PB_ReturnParam2(char *source)
{

//MessageBox(0,source,"",0);

return source;
}


extern char* _stdcall PB_ReturnString()
{
char *returnString;
returnString="Return Value Test";

return returnString;
}


#ifndef PURELIBRARY

int main()
{
char *string;
char *stringNo2;
string=PB_ReturnParam1("Testing ReturnParam1()");
MessageBox(0,string,"",0);
string=PB_ReturnParam2("Testing ReturnParam2()");
MessageBox(0,string,"",0);
stringNo2=PB_ReturnString();
MessageBox(0,stringNo2,"",0);

return 0;
}

#endif
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by wayne1.

Thanks

I've attached a quick example. You need to return the string in
PB_StringBase and then update this pointer of the lenght of the string. You
should return the start of the PB!StringBase, before you modify it.

Good bye,

-- Fred.

extern _stdcall char *test()
{
char *ReturnValue;

ReturnValue = PB_StringBase;

strcpy(PB_StringBase, "This is a test");
PB_StringBase += strlen("This is a test");

return ReturnValue;
}
Post Reply