c++ - visual studio Dll and Matlab -


i trying build dll visual studio can use in matlab ... tried thausand codes no solution !!! working on matlab 2013(32and64) , vs2010 ! tried example write code way ...

        //the header      #ifndef simpleh_h     #define simpleh_h     #ifdef  __cplusplus     extern "c" {     int sq(int x);       #endif     #ifdef  __cplusplus     }     #endif     #endif  //the func(example)  #include "simpleh.h" int sq(int x) { return (x*x); } 

visual studio build , make th dll file matlab doesn't see function ... should /* stucked :( */ in advance ...

example: take following files, , build dll in visual studio.

helper.h

#ifndef helper_h #define helper_h  #ifdef _win32 #ifdef export_fcns #define exported_function __declspec(dllexport) #else #define exported_function __declspec(dllimport) #endif #else #define exported_function #endif  #endif 

simple.h

#ifndef simpleh_h #define simpleh_h  #include "helper.h"  #ifdef  __cplusplus extern "c" { #endif  exported_function int sq(int x);  #ifdef  __cplusplus } #endif  #endif 

simple.cpp

#define export_fcns #include "helper.h" #include "simple.h"  int sq(int x) {     return (x*x); } 

copy generated simple.dll , header files simple.h , helper.h in current directory. in matlab:

>> loadlibrary('./simple.dll', './simple.h')  >> libisloaded simple ans =      1  >> libfunctions simple -full functions in library simple:  int32 sq(int32)  >> calllib('simple', 'sq',3) ans =      9 

note: if running matlab 64-bit, must build dll such. rule cannot load 32-bit library in 64-bit process.


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -