Pass struct to C++ DLL library with strings
조회 수: 3 (최근 30일)
이전 댓글 표시
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개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Structures에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!