# @cfunction with CxxWrap arguments

**URL:** <https://discourse.julialang.org/t/cfunction-with-cxxwrap-arguments/123473>\
**Category:** General Usage\
**Tags:** embedding, cxxwrap\
**Created:** [December 4, 2024, 10:34pm UTC](https://discourse.julialang.org/t/cfunction-with-cxxwrap-arguments/123473 "2024-12-04T22:34:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sergey](https://avatars.discourse-cdn.com/v4/letter/s/9fc348/32.png) [@Sergey](https://discourse.julialang.org/u/Sergey)\
**Post date:** [December 4, 2024, 10:34pm UTC](https://discourse.julialang.org/t/cfunction-with-cxxwrap-arguments/123473/1 "2024-12-04T22:34:15Z")

</div>

Hi!  
Is it possible to get pointer by `@function` if this function argument is CxxWrap binded struct?

Class binding

```cpp
types.add_type<DataBase>("Database")
   .method("GetProperty", &DataBase::getProperty);

```

and julia function with binded class argument:

```julia
function Eg(db::CppTypes.Database, mat::Cint)
    return GetProperty(db, mat)
end

```

which will be getted on c++ side with:

```julia
auto *eg = (double (*)(DataBase *, int)) jl_unbox_voidpointer(jl_eval_string("@cfunction(Eg, Cdouble, (Ptr{Cvoid}, Cint))")); 

```

Seems like i dont understand julia interface enugh.  
Should `julia` function get `Ptr{Cvoid}` as argument and convert it to desired structure via `static_cast`?

Thanks!

---

<div class="post-metadata">

**Author:** ![Sergey](https://avatars.discourse-cdn.com/v4/letter/s/9fc348/32.png) [@Sergey](https://discourse.julialang.org/u/Sergey)\
**Post date:** [December 5, 2024, 9:31am UTC](https://discourse.julialang.org/t/cfunction-with-cxxwrap-arguments/123473/2 "2024-12-05T09:31:14Z")

</div>

CxxWrtap doc stand that `add_type` create the foollowing structs:

```julia
abstract type World end

mutable struct WorldAllocated <: World
    cpp_object::Ptr{Cvoid}
end

```

and i try to create such object from void pointer

```julia
abstract type World end

mutable struct WorldAllocated <: World
    cpp_object::Ptr{Cvoid}
end

function Eg2(db::Ptr{Cvoid}, mat::Cint, T::Cdouble) :: Cdouble
    db2 = WorldAllocated(db) 

```

But it only work with manually defined class.

I cant create such object from one defined by CxxWrap.
