- Define the structures in MATLAB using "libstruct"
- Create pointer to those structures using "libpointer"
- Now call the function with created pointers like
Using functions from C++ in MATLAB
10 views (last 30 days)
Show older comments
Hi all,
I'll start off by showing a function that I have in C++.
int __stdcall UDP_GigE_getData(unsigned char *packetType, T_GVSP_LEADER_PACKET *leader, T_GVSP_PAYLOAD_PACKET *payloads,
T_GVSP_TRAILER_PACKET *trailer, T_GVSP_ALL_IN_PACKET *allInOne)
You should know that all variables with type T_GVSP_... are struct types defined in C. Now, I want to use the calllib function in MATLAB to call the above function. Something like,
response = calllib( 'UDP_GigE' , 'UDP_GigE_getData' , packetType, leader, payloads, trailer, allInOne)
The problem is, I do not know how put those struct pointers in the calllib function, since MATLAB's pointer functionality is not to obvious to me. Does anyone have any ideas on how to put pointers into the calllib function correctly?
Thanks
0 Comments
Answers (1)
Anjaneyulu Bairi
on 1 Nov 2024 at 16:14
Hi,
To call a C++ function from MATLAB using "calllib", you need to ensure that the data types in MATLAB match those expected by the C++ function. In your case, you need to handle pointers to structures, which requires some setup in MATLAB.
calllib('UDP_GigE' , 'UDP_GigE_getData' , packetType, leaderptr, payloadsptr, trailerptr, allInOneptr)
You can refer the below documentation links to know more information on "libstruct","libpointer" and for few examples:
0 Comments
See Also
Categories
Find more on C Shared Library Integration in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!