# CPLEX.jl: how to call CPXcallbackgetinfoint?

**URL:** <https://discourse.julialang.org/t/cplex-jl-how-to-call-cpxcallbackgetinfoint/39834>\
**Category:** Optimization (Mathematical)\
**Created:** [May 20, 2020, 2:17pm UTC](https://discourse.julialang.org/t/cplex-jl-how-to-call-cpxcallbackgetinfoint/39834 "2020-05-20T14:17:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mike\_k](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mike_k/32/211864_2.png) [@mike\_k](https://discourse.julialang.org/u/mike_k)\
**Post date:** [May 20, 2020, 2:17pm UTC](https://discourse.julialang.org/t/cplex-jl-how-to-call-cpxcallbackgetinfoint/39834/1 "2020-05-20T14:17:19Z")

</div>

Dear folks,

I try to call [CPXcallbackgetinfoint](https://www.ibm.com/support/knowledgecenter/SS9UKU_12.10.0/com.ibm.cplex.zos.help/refcallablelibrary/cpxapi/callbackgetinfoint.html) within a callback but unfortunately fail to do so. From what I could extract from the source code of the CPLEX package, it should work something like this:

```julia
function myCallback( cb_data::CPLEX.CallbackContext )
    data_p = Ref{Cint}()
    ret = CPLEX.@cpx_ccall(callbackgetinfoint, Cint,
                                (Ptr{Cvoid}, Cint, Ref{Cint}),
                                 cb_data, 1, data_p) # "1" should correspond to CPXCALLBACKINFO_NODECOUNT
    mydata = data_p[]
    println("$mydata")
    
    do_something_else( cb_data )
    return 
end
MOI.set( model, MOI.UserCutCallback(), myCallback ) #"model" is a JuMP model 

```

Unfortunatly this throws an error stating `MethodError(Base.unsafe_convert, ...)`.

Any ideas how to call such functions correctly? Thank you very much in advance!

I use:  
`JuMP.jl v0.21.2`,  
`CPLEX.jl v0.6.5`  
`MathOptInterface.jl v0.9.13`  
`CPLEX 12.9`

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [May 20, 2020, 2:36pm UTC](https://discourse.julialang.org/t/cplex-jl-how-to-call-cpxcallbackgetinfoint/39834/2 "2020-05-20T14:36:41Z")

</div>

You need to pass `cb_data.context` to `cpx_ccall` instead of `cb_data`.

Note that you can access the full CPLEX generic callback if you use `CPLEX.CallbackFunction()` instead of `MOI.UserCutCallback()`.

This isn’t really documented, but you can see an example here:

> <https://github.com/jump-dev/CPLEX.jl/blob/5ae4628446470fa0a46438cdfe577155dbcfd54c/test/MathOptInterface/MOI_callbacks.jl#L304-L331>
