Note: This article requires the MATLAB Interface to Generic Dlls. No link is available, but if you know of one please let us know.
A shared library is a collection of functions that are available for use by one or more applications running on a system. On Windows operating systems, the library is compiled into a dynamic link library (.dll) file. At run-time, the library is loaded into memory and made accessible to all applications.
The MATLAB Interface to Generic DLLs enables you to interact with functions in dynamic link libraries directly from MATLAB.
Dynamic link libraries are easily accessed by MATLAB through a command line interface. This interface gives you the ability to load an external library into MATLAB memory space and then access any of the functions exported from library. Although data types differ between the two language environments, in most cases, you can pass MATLAB types to the C functions without having to do the work of conversion. MATLAB does this for you.
This interface also supports libraries containing functions programmed in languages other than C, provided that the functions have a C interface.
To give MATLAB access to external functions in a shared library, you must first load the library into memory. Once loaded, you can request information about any of the functions in the library and call them directly from MATLAB. When the library is no longer needed, you will need to unload it from memory to conserve memory usage.
Loading the Library
To load a shared library into MATLAB, use the
loadlibrary function. The syntax for
your_dll is the filename for the .dll library file, and
header_file is the filename for the header file that contains the function prototypes.
Here is an example:
Unloading the Library
To unload the library and free up the memory that it occupied, use the
unloadlibrary function. For example:
Getting Information About the Library
You can use either of these two functions to get information on the functions available in a library that you have loaded:
The main difference is that
libmethods displays the information in the MATLAB Command Window (and you can assign its output to a variable), and
libmethodsview displays the information as a graphical display in a new window (figure 2). To see what functions are available in the
MatlabGenericDll library, use
libmethods, specifying the library filename as the only argument.
Invoking Library Functions
Once a library has been loaded into MATLAB, use the
calllib function to call any of the functions from that library. Specify the library name, function name, and any arguments that get passed to the function:
calllib('libname', 'funcname', arg1, ..., argN)
Here is an example (demo project) to call Format dialog from MATLAB (See figure 1):
For more information and instruction to setup this interface, refer to mathworks site or click here.
I was born in Shiraz, a very beautiful famous city in Iran. I started programming when I was 12 years old with GWBASIC. Since now, I worked with various programming languages from Basic, Foxpro, C/C++, Visual Basic, Pascal to MATLAB and now Visual C++.
I graduated from Iran University of Science & Technology
in Communication Eng., and now work as a system programmer for a telecommunication industry.
I wrote several programs and drivers for Synthesizers, Power Amplifiers, GPIB, GPS devices, Radio cards, Data Acquisition cards and so many related devices.
I'm author of several books like Learning C (primary and advanced), Learning Visual Basic, API application for VB, Teach Yourself Object Oriented Programming (OOP) and etc.
I'm winner of January, May, August 2003 and April 2005 best article of month competition, my articles are:
You can see list of my articles, by clicking here