Dynamic Library without a .h file

조회 수: 55 (최근 30일)
Benjamin Schwabe
Benjamin Schwabe 2012년 2월 7일
편집: Cedric 2013년 10월 4일
Hello all,
I'm trying to establish communication with a hardware tool and it's API is given by a two-level approach.
For the second level, I don't have an .h-file and loadlibrary requires one. Can I load the dll anyway? (I assume the other dll will then be able to still communicate with this dll...
Thanks!

채택된 답변

Walter Roberson
Walter Roberson 2012년 2월 7일
You will not be able to use the MATLAB loadlibrary() call without a .h file.
If you do not need to call in to the dll yourself, then ideally you should not need to loadlibrary() it, as the dll that you do call should load it using OS calls.
  댓글 수: 4
Walter Roberson
Walter Roberson 2012년 2월 7일
A loaded DLL can make callbacks to the MATLAB engine to call loadlibrary() -- provided, of course, that the .h exists.
There are operating system calls that can load libraries without needing .h files, but those calls rely on the code to "just know" what the binary calling sequence is under all conditions.
But MATLAB code doesn't use binary calling sequences, and MATLAB likes to pass around mxArray structures and kin, so there needs to be an interface layer between the way MATLAB operates and the way DLL's operate internally. MATLAB builds that interface code based upon the .h files, to navigate between the dynamically typed MATLAB and the statically typed DLL calls.
A DLL is in machine language, compiled from whatever source code language was suitable for the task (e.g., C, C++, Fortran). The DLL can make operating system calls and call statically typed routines, so the DLL can load additional libraries dynamically, as long as it knows _exactly_ how to talk to them.
MATLAB's mechanism is general, to try to talk to any DLL. Any one DLL only has to deal with the specific interfaces that the DLL needs to talk to.
Kaustubha Govind
Kaustubha Govind 2012년 2월 8일
Benjamin: The error "Cannot initialize CDALib" seems to suggest that the OS is unable to load CDALib from the DLL that interfaces with MATLAB. Perhaps you need to add the directory containing CDALib.dll to the System PATH variable. Then restart MATLAB and try again?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 C Shared Library Integration에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by