Click here to Skip to main content
Click here to Skip to main content

MATLAB Generic DLL

By , 18 Nov 2003
Rate this:
Please Sign up or sign in to vote.

Note: This article requires the MATLAB Interface to Generic Dlls. No link is available, but if you know of one please let us know.

Sample Image - MatlabGenericDll_1.jpg

Introduction

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 loadlibrary is:

loadlibrary('your_dll', 'header_file')

where 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:

loadlibrary('MatlabGenericDll', 'GenericDll.h')

Unloading the Library

To unload the library and free up the memory that it occupied, use the unloadlibrary function. For example:

unloadlibrary MatlabGenericDll

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:

libmethods('libname')
libmethodsview('libname')

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.

libmethods MatlabGenericDll

LibMethodsView Window for displaying exported functions in a Dll

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):

loadlibrary('MatlabGenericDll','GenericDll.h')
calllib('MatlabGenericDll', 'FormatDrive')
unloadlibrary MatlabGenericDll

For more information and instruction to setup this interface, refer to mathworks site or click here.

Enjoy!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

A. Riazi
CEO Misbah3Com
Iran (Islamic Republic Of) Iran (Islamic Republic Of)
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 Acqusition 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 competetion, my articles are:

You can see list of my articles, by clicking here


Comments and Discussions

 
GeneralMy vote of 5 Pinmembermanoj kumar choubey26-Feb-12 19:54 
QuestionCreating a dll file for a function of matlab Pinmemberns_v_civil15-Nov-11 23:35 
Questionabout MatlabGenericDll Pinmemberdawn.li@luminageo.com23-Jun-11 13:46 
GeneralMy vote of 5 PinmemberHeaven202019-Jun-11 5:30 
QuestionOutput param = array of double? Pinmemberdevvvy29-Jul-09 1:31 
QuestionA question on .Net and matlab interface PinmemberBaba Deep13-May-09 16:06 
QuestionHow to Use Matlab functions in Delphi7 Pinmemberreddy mopuru28-Jan-09 22:15 
Generalinvoke C-DLL in Matlab PinmemberJenser764-Jan-09 22:45 
GeneralWarning: Message from C preprocessor (loadlibrary) PinmemberSergay4-Aug-08 2:58 
GeneralRe: Warning: Message from C preprocessor (loadlibrary) PinmemberSergay4-Aug-08 3:03 
GeneralError using ==> loaddefinedlibrary PinmemberFrito28-May-08 12:46 
Generalmatlabdll Pinmemberaammiinn5-May-08 20:13 
QuestionError using ==> calllib [modified] Pinmembergbm_online1-Apr-08 6:29 
GeneralRe: Error using ==> calllib Pinmembergbm_online2-Apr-08 3:43 
AnswerRe: Error using ==> calllib Pinmemberbjtu_wsc14-Apr-11 16:21 
GeneralDownload Generic DLL... PinmemberA. Riazi10-Dec-07 17:06 
Generalintegrate matlab with c# PinmemberMember 39915056-Dec-07 16:59 
GeneralMethod was not found Pinmembertorand13-Nov-07 23:47 
GeneralCalling a Matlab dll from Matlab Pinmemberbonoman14-Apr-07 2:06 
GeneralRe: Calling a Matlab dll from Matlab Pinmembercat_e023-Aug-07 20:34 
Generaldll don't register in window PinmemberReinaldo Teixeira18-Dec-06 7:10 
GeneralMultiple DLLs Pinmemberhendrylibra6-Dec-06 11:26 
GeneralUsing MATLAB generated shared libraries in external C++ apps Pinmembermario6215-Nov-06 7:59 
GeneralRe: Using MATLAB generated shared libraries in external C++ apps PinmemberAKG19-Dec-06 20:44 
Generalc-mex and generic dll Pinmemberburstain15-Oct-06 21:52 
Questionplz!! HELP!!! call DLL from MATLAB [modified] Pinmembervnc_cp29-Aug-06 22:49 
QuestionRe: plz!! HELP!!! call DLL from MATLAB PinmemberRadDeveloper26-Feb-07 6:23 
QuestionCan I take "Ogre" into MATLAB? Pinmemberkbigdelysh12-Aug-06 4:03 
AnswerRe: Can I take "Ogre" into MATLAB? PinmemberA. Riazi12-Aug-06 5:52 
GeneralLCC preprocessor error [modified] PinmemberA.S.Nandagopalan12-Jul-06 11:21 
QuestionI am confused :( [modified] Pinmemberareddy20067-Jul-06 5:20 
GeneralTo Mr Riazi, thanks a lot PinmemberSylvianne30-Jun-06 2:56 
AnswerRe: To Mr Riazi, thanks a lot PinmemberA. Riazi30-Jun-06 3:35 
QuestionCan i use these header files with loadlibrary? PinmemberSylvianne23-Jun-06 2:31 
Generalmbuild -setup PinmemberSylvianne20-Jun-06 21:31 
GeneralRe: mbuild -setup PinmemberSylvianne20-Jun-06 21:33 
AnswerRe: mbuild -setup PinmemberA. Riazi23-Jun-06 0:20 
GeneralRe: mbuild -setup PinmemberSylvianne23-Jun-06 2:33 
GeneralWrapper DLL to load DLL in Matlab PinmemberSylvianne19-Jun-06 1:35 
AnswerRe: Wrapper DLL to load DLL in Matlab PinmemberA. Riazi19-Jun-06 21:45 
GeneralRe: Wrapper DLL to load DLL in Matlab PinmemberSylvianne19-Jun-06 21:52 
AnswerRe: Wrapper DLL to load DLL in Matlab PinmemberA. Riazi19-Jun-06 23:41 
GeneralRe: Wrapper DLL to load DLL in Matlab PinmemberSylvianne20-Jun-06 4:14 
GeneralRe: Wrapper DLL to load DLL in Matlab PinmemberSylvianne19-Jun-06 21:57 
GeneralRe: Wrapper DLL to load DLL in Matlab PinmemberSylvianne19-Jun-06 22:25 
GeneralProblem with addheader (load DLL) PinmemberSylvianne16-Jun-06 3:29 
GeneralDoes Not Compile PinmemberGuillochon25-Apr-06 9:22 
GeneralCalling MFC Dll in Matlab PinmemberWahaj Khan14-Apr-06 23:57 
AnswerRe: Calling MFC Dll in Matlab PinmemberA. Riazi15-Apr-06 0:44 
GeneralRe: Calling MFC Dll in Matlab PinmemberWahaj Khan17-Apr-06 0:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web02 | 2.8.140415.2 | Last Updated 19 Nov 2003
Article Copyright 2003 by A. Riazi
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid