Import and C++
Ok, got it:
I'll try a bigger example and use std::string, if I succeed I'll post it here...
I have no clue what the problem with your library is Polo, sorry.Create a Win32 Project, select Static Library and unselect Precompiled Headers
Paste this code into a new .cpp file:Select Release modeCode: Select all
extern "C" { int answer() { return 42; } };
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
I'll try a bigger example and use std::string, if I succeed I'll post it here...
Windows 7 & PureBasic 4.4
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.
In PB :
I can run this code without any Problems.
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
Code: Select all
Import "LibTest.lib"
GetInt.l()
EndImport
Debug GetInt()
End
OK.
I tried the following:
It sees like there is a Problem with the Destructor!
Without the "deleteTest"-Function everything works fine !?!?
Lets test a littlebit more .
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 .