这是我用Matlab生成的dll文件的代码!
(生成时所应用的Matlab函数为"mcc -B csharedlib:myDLL myfunc.m")
我的Matlab代码为:
function b=myFunc(a)
b=a.*a;
生成的dll代码(我看不懂)
#include <stdio.h>
#define EXPORTING_myDLL 1
#include "myDLL.h"
#ifdef __cplusplus
extern "C" {
#endif
extern const unsigned char __MCC_myDLL_public_data[];
extern const char *__MCC_myDLL_name_data;
extern const char *__MCC_myDLL_root_data;
extern const unsigned char __MCC_myDLL_session_data[];
extern const char *__MCC_myDLL_matlabpath_data[];
extern const int __MCC_myDLL_matlabpath_data_count;
extern const char *__MCC_myDLL_classpath_data[];
extern const int __MCC_myDLL_classpath_data_count;
extern const char *__MCC_myDLL_lib_path_data[];
extern const int __MCC_myDLL_lib_path_data_count;
extern const char *__MCC_myDLL_mcr_runtime_options[];
extern const int __MCC_myDLL_mcr_runtime_option_count;
extern const char *__MCC_myDLL_mcr_application_options[];
extern const int __MCC_myDLL_mcr_application_option_count;
#ifdef __cplusplus
}
#endif
static HMCRINSTANCE _mcr_inst = NULL;
#if defined( _MSC_VER) || defined(__BORLANDC__) || defined(__WATCOMC__) || defined(__LCC__)
#include <windows.h>
static char path_to_dll[_MAX_PATH];
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, void *pv)
{
if (dwReason == DLL_PROCESS_ATTACH)
{
char szDllPath[_MAX_PATH];
char szDir[_MAX_DIR];
if (GetModuleFileName(hInstance, szDllPath, _MAX_PATH) > 0)
{
_splitpath(szDllPath, path_to_dll, szDir, NULL, NULL);
strcat(path_to_dll, szDir);
}
else return FALSE;
}
else if (dwReason == DLL_PROCESS_DETACH)
{
}
return TRUE;
}
#endif
static int mclDefaultPrintHandler(const char *s)
{
return fwrite(s, sizeof(char), strlen(s), stdout);
}
static int mclDefaultErrorHandler(const char *s)
{
int written = 0, len = 0;
len = strlen(s);
written = fwrite(s, sizeof(char), len, stderr);
if (len > 0 && s[ len-1 ] != '\n')
written += fwrite("\n", sizeof(char), 1, stderr);
return written;
}
/* This symbol is defined in shared libraries. Define it here
* (to nothing) in case this isn't a shared library.
*/
#ifndef LIB_myDLL_C_API
#define LIB_myDLL_C_API /* No special import/export declaration */
#endif
LIB_myDLL_C_API
bool myDLLInitializeWithHandlers(
mclOutputHandlerFcn error_handler,
mclOutputHandlerFcn print_handler
)
{
if (_mcr_inst != NULL)
return true;
if (!mclmcrInitialize())
return false;
if (!mclInitializeComponentInstance(&_mcr_inst, __MCC_myDLL_public_data,
__MCC_myDLL_name_data,
__MCC_myDLL_root_data,
__MCC_myDLL_session_data,
__MCC_myDLL_matlabpath_data,
__MCC_myDLL_matlabpath_data_count,
__MCC_myDLL_classpath_data,
__MCC_myDLL_classpath_data_count,
__MCC_myDLL_lib_path_data,
__MCC_myDLL_lib_path_data_count,
__MCC_myDLL_mcr_runtime_options,
__MCC_myDLL_mcr_runtime_option_count,
true, NoObjectType, LibTarget,
path_to_dll, error_handler,
print_handler))
return false;
return true;
}
LIB_myDLL_C_API
bool myDLLInitialize(void)
{
return myDLLInitializeWithHandlers(mclDefaultErrorHandler,
mclDefaultPrintHandler);
}
LIB_myDLL_C_API
void myDLLTerminate(void)
{
if (_mcr_inst != NULL)
mclTerminateInstance(&_mcr_inst);
}
LIB_myDLL_C_API
void mlxMyfunc(int nlhs, mxArray *plhs[], int nrhs, mxArray *prhs[])
{
mclFeval(_mcr_inst, "myfunc", nlhs, plhs, nrhs, prhs);
}
LIB_myDLL_C_API
void mlfMyfunc(int nargout, mxArray** b, mxArray* a)
{
mclMlfFeval(_mcr_inst, "myfunc", nargout, 1, 1, b, a);
}
我不明白“nargout”的意思是什么!请各位高手指教。
我在VB6.0中的模块申明即程序为
Public a As Long
Public Declare Function mlfMyFunc Lib "myDLL.dll" (ByVal c As Long, ByVal b As Long, ByVal a As Long) As Long
Public Declare Function myDLLInitialize Lib "myDLL.dll" () As Long
程序
Option Explicit
Dim b As Long
Dim c As Long
Private Sub Command1_Click()
a = Text1
Call mlfMyFunc(c, b, a)
Text2 = b
End Sub
Private Sub Form_Load()
Call myDLLInitialize
End Sub
先谢过各位!
2 个解决方案
#1
#2
好像vb只支持两种dll,一种是activex,一种是标准的dll,将你导出的函数都加入__stdcall函数。
#1
#2
好像vb只支持两种dll,一种是activex,一种是标准的dll,将你导出的函数都加入__stdcall函数。