Okay after working on it over the weekend, I realize that I'm at the limit of my understanding of how to make things interoperable with C specifically in reference to MATLAB. My familiarity with C is passing and this involves things I've never tried to do in C.
I have a series of functions that I have made that are all bind(c) and have a specific user defined type for the return argument. I want the return argument to be flexible, as I want it to be able to return whatever it is the library wants to give it as well as be able to return the error messages/status that are returned.
Here is an example of the user defined type:
type, bind(c) :: c_return integer(c_int) :: ncolumns = 0 integer(c_int) :: nrows = 0 integer(c_int) :: lstring = 0 integer(c_int) :: status = 0 type(c_ptr) :: valueptr endtype c_return
The idea is to locally control the valueptr such that all memory gets freed after MATLAB is done with the command.
Here is an example of the function declaration that I want.
function c_bodyn(jd, is, ip) bind(c, name='c_bodyn') !DEC$ ATTRIBUTES DLLEXPORT :: c_bodyn ! ! ! Passed Parameters real(c_double), intent(in) :: jd ! Julian date real(c_double), intent(in) :: is ! satellite integer real(c_double), intent(in) :: ip ! master central body integer type(c_return) :: c_bodyn
I have hacked around trying to get a C header file that would be compatible, and haven't been successful. If someone can help me I'd really appreciate it.
Here is one of the many different header files that I have tried for these:
#define EXPORTED_FUNCTION __declspec(dllexport)
#ifdef __cplusplus
extern "C" {
#endif
typedef struct
{
int ncolumns, nrows, lstring, status;
void * valueptr;
} c_return;
extern "C" __declspec struct c_return c_bodyn(double jd, int is, int ip);
#ifdef __cplusplus
}
#endif



