读书人

VC与matlab混合编程的有关问题

发布时间: 2012-03-23 12:06:21 作者: rapoo

VC与matlab混合编程的问题
我在使用VC与matlab编程的时候,出现了以下的问题,希望大家帮我看看,谢谢!主程序代码如下所示:

#include "iostream.h" // 输入输出头文件
#include "matrix.h"
#include "mclmcr.h" // mxArray 类型声明
#include "libsmttkn.h" // DLL 头文件
#include "ReadImg.h"//读取BMP文件

int main()
{

int result;
char *pFileName = "C:\\48802.bmp";
//unsigned char **pBuffer ;
int iWidth,iHeight ;

// 初始化程序

if( ! mclInitializeApplication(NULL,0) )
{
fprintf(stderr, "Could not initialize the application.\n");
exit(1);
}

// 初始化库

if (! libsmttknInitialize() )
{
fprintf(stderr,"Could not initialize the library.\n");
exit(1);
}

// 声明 DLL 函数输入输出 mxArray 对象

mxArray *pBuffer = NULL;//定义输入
mxArray *shibiexuliehao=NULL;
mxArray*yejingshibie =NULL;//定义输出

// 给输入 mxArray 对象分配内存
mxArray mxCreateString(const char **pBuffer);

//读取图像,给pBuffer赋值
result = fnReadImg(pFileName, &pBuffer,&iWidth,&iHeight);


// 调用 DLL 函数,注意输入与输出的接口是不同的
mlfSmttkn(2,&shibiexuliehao,&yejingshibie,pBuffer) ;

// 显示 mxArray 对象

display(shibiexuliehao,"shibiexuliehao");
display(yejingshibie,"yejingshibie");

// 释放输入输出 mxArray 对象所占用的内存
// 注意输出对象的内存是在调用 DLL 函数过程中分配的
mxDestroyArray(pBuffer);
mxDestroyArray(shibiexuliehao);
mxDestroyArray(yejingshibie);

// 关闭库和程序
libsmttknTerminate() ;
mclTerminateApplication() ;

return 0;
}
这个函数的主要功能就是读取一个bmp图像到程序里面去,然后传到matlab里面使用matlab对图像进行处理。处理完成以后返回两个字符串.函数在VC6.0环境下运行的时候出现了以下的错误:C:\Program Files\Microsoft Visual Studio\MyProjects\test\test.cpp(71) : error C2664: 'fnReadImg' : cannot convert parameter 2 from 'struct mxArray_tag ** ' to 'unsigned char ** '
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
也就是在读取图像的时候出现了错误,希望大家能够帮我看下。读取bmp图像的函数接口是:int fnReadImg(char *pFileName,unsigned char ** pBuffer,int *iWidth,int *iHeight),具体函数内容因为篇幅问题就不展示了。

[解决办法]
明显的参数类型不匹配啊
传进去的是mxArray_tag **
但是要求的是unsigned char **

读书人网 >C++

热点推荐