Pass struct to C++ DLL library with strings
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have a simple C++ program, where I pass a c_struct by reference and am able to update the values for the doubles. Now I would like to also pass back a string. But it fails on the construction:
---
>> sc = libstruct('c_struct', sm)
Error using feval
Cannot convert data value for field p3 due to error:
Parameter can not be converted to a character vector
Error in libstruct (line 16)
ptr=feval(['lib.' structtype],initialvalue);
----
How do I pass back a string in the struct. Here is the Header and the Code:
#pragma once
#include "helper.hpp"
struct c_struct {
double p1;
double p2;
char* p3;
};
#ifdef __cplusplus
extern "C" {
#endif
EXPORTED_FUNCTION int sq(int x);
EXPORTED_FUNCTION void lmb(struct c_struct *st);
#ifdef __cplusplus
}
#endif
----
#include "stdafx.h"
#include "helper.hpp"
#include "simple.hpp"
int sq(int x)
{
return (x*x);
}
void lmb(struct c_struct *st) {
st->p1 = 3.0;
st->p2 = 4.0;
st->p3 = "goodbye";
}
1 commentaire
Réponses (1)
Voir également
Catégories
En savoir plus sur Structures dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!