-
Notifications
You must be signed in to change notification settings - Fork 0
/
foo_cii.cpp
30 lines (28 loc) · 1.15 KB
/
foo_cii.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/**
* @cond
* Filename: foo_cii.cpp
* ----------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* <[email protected]> wrote this file. As long as you retain this notice you
* can do whatever you want with this stuff. If we meet some day, and you think
* this stuff is worth it, you can buy me a beer in return Daniel Giritzer
* ----------------------------------------------------------------------------
* @endcond
*/
// Compiled with GCC here we know how to handle foo objects
#include "foo_cii.h"
#include "foo.h"
#include <string>
#include <cstring>
CII_MANGLE const char* CII_CALLCONV CII_FOO_GetFoo(void * fooObj)
{
std::string str = static_cast<foo*>(fooObj)->GetFoo();
char* cstr = new char [str.length()+1];
std::strcpy (cstr, str.c_str());
return cstr; // passing str.c_str() directly is forbidden here, because std::string manages its memory
// pass char* allocated here directly to a std::string ctor to make memory managed again! Otherwise -> memleak
}
CII_MANGLE void CII_CALLCONV CII_FOO_SetFoo(void * fooObj, const char* newFoo)
{
static_cast<foo*>(fooObj)->SetFoo(newFoo);
}