Page 3 of 3

Posted: Wed Jun 25, 2008 12:45 pm
by Polo
Maybe it is because std things and c++ is used I dont know, well I've gotta give up as I think I tried everything :?

Posted: Wed Jun 25, 2008 1:06 pm
by milan1612
Ok, got it:
Create a Win32 Project, select Static Library and unselect Precompiled Headers

Paste this code into a new .cpp file:

Code: Select all

extern "C" {
	int answer() {
		return 42;
	}
};
Select Release mode

Go to the project settings and:
Set General -> Whole Program Optimization to "No Whole Program Optimization"
Set C/C++ -> Optimization -> Optimization to "Disabled"

Compile the project

Import the library in Purebasic using ImportC

Use it :P
I have no clue what the problem with your library is Polo, sorry.
I'll try a bigger example and use std::string, if I succeed I'll post it here...

Posted: Thu Jun 26, 2008 4:54 pm
by Polo
Well just to tell it, the code has bo error when using VC++ 6 :)

Seems the problem lies with C++ and VC++8, PellesC linker maybe is not compatible.

Posted: Thu Jun 26, 2008 10:02 pm
by HotteHC
Hi Polo.
Please try to compile the following Sourcecode in VC2008 express.
Turn off the Optimation like Fred said and build as Static Lib in Release Mode.

Code: Select all

#ifdef  __cplusplus
extern "C"
{
#endif//__cplusplus

int __stdcall GetInt()
{
 return 132;
}

#ifdef  __cplusplus
}
#endif//__cplusplus
In PB :

Code: Select all

Import "LibTest.lib"
 GetInt.l()
EndImport

Debug GetInt()
End
I can run this code without any Problems.

Posted: Thu Jun 26, 2008 10:13 pm
by Polo
Yes but you're not actually using any C++ code, which is the problem :)

Here you just have C code in a CPP file ;)

Posted: Thu Jun 26, 2008 10:22 pm
by HotteHC
But wasn't that nearly the same function witch causes Errors when you importet the Lib to PB?
What other codesnippet makes Problems in youre" C++" Code?

Posted: Thu Jun 26, 2008 10:44 pm
by HotteHC
OK.
I tried the following:

Code: Select all

class CTest
{

private :
 int tInt;

 public:

 CTest(){tInt = 132;}
 ~CTest();

 int __stdcall GetInt(){return tInt;}


};

#ifdef  __cplusplus
extern "C"
{
#endif//__cplusplus

CTest* __stdcall createTest()
{
 return new CTest();
}


int __stdcall GetInt(CTest* test)
{
 if (test)
 {
  return test->GetInt();
 }
 return 0;
}


/*
void __stdcall deleteTest(CTest* test)
{
 if(test)
 {
	 delete test;
 }
 test = 0;
}
*/

#ifdef  __cplusplus
}
#endif//__cplusplus

It sees like there is a Problem with the Destructor!
Without the "deleteTest"-Function everything works fine !?!?

Lets test a littlebit more .