Error calling loadlibrary: "functions not found"

I'm trying to automate a device using Matlab through calling a dll file provided by the manufacturer. However, it kept returning errors saying "functions not found", even after I checked with "libisloaded" and Matlab returns 1. Here is the code and error messages:
>> fullpathToDll='C:\D4100_DLLHeaders\D4100_usb.dll'
fullpathToDll =
C:\D4100_DLLHeaders\D4100_usb.dll
>> header1='C:\D4100_DLLHeaders\D4100_usb';
>> header2='C:\D4100_DLLHeaders\resource.h';
>> header3='C:\D4100_DLLHeaders\devioctl.h';
>> header4='C:\D4100_DLLHeaders\ezusbsys.h';
>> header5='C:\D4100_DLLHeaders\main.h';
>> header6='C:\D4100_DLLHeaders\RegisterDefines.h';
[notfound,warnings]=loadlibrary(fullpathToDll,header1,'addheader',header2,'addheader',header3,'addheader',header4,'addheader',header5,'addheader',header6);
Warning: Message from C preprocessor:
lcc preprocessor warning: C:\D4100_DLLHeaders\main.h:173 C:\D4100_DLLHeaders\D4100_usb.h:19 EOF inside comment
lcc preprocessor warning: C:\D4100_DLLHeaders\RegisterDefines.h:40 C:\D4100_DLLHeaders\D4100_usb.h:23 EOF inside comment
lcc preprocessor warning: C:\D4100_DLLHeaders\D4100_usb.h:69 EOF inside comment
> In loadlibrary at 266
Warning: Warnings messages were produced while parsing. Check the functions you
intend to use for correctness. Warning text can be viewed using:
[notfound,warnings]=loadlibrary(...)
> In loadlibrary at 275
Warning: The function 'bOpenDriver' was not found in the library
> In loadlibrary at 319
Warning: The function 'ParseDeviceDescriptor' was not found in the library
> In loadlibrary at 319
Warning: The function 'ParseConfigurationDescriptor' was not found in the library
> In loadlibrary at 319
Warning: The function 'DumpBuffer' was not found in the library
> In loadlibrary at 319
Warning: No functions found in library.
> In loadlibrary at 327
The functions that give the warnings are from 'main.h'. What's causing the problems? Is there something wrong with the header files? I got those from the manufacturer and they have verified that the files work on LabView but have not tested them in Matlab.
Could someone help me solve this problem? Thanks!!
Siqi

Risposte (2)

With a second look, I suspect that this might be a compiler issue. Matlab is using lcc compiler, which is C. But in my header file, it contains "extern "C" ", which means it's for C++? Here is what my main header file looks like:
#define DLL_EXPORT
#if defined DLL_EXPORT
#define USB_DLL __declspec(dllexport)
#else
#define USB_DLL __declspec(dllimport)
#endif
#undef UNICODE
#include <windows.h>
#include <malloc.h>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include "stdarg.h"
#include "main.h"
#include "devioctl.h"
#include "ezusbsys.h"
#include "RegisterDefines.h"
extern "C"
{ ...//a bunch of functions here
}
//#############EOF##################
I also created a prototype file, using the demo from the previous answer. I ran it using loadlibrary(dllfilename,@mfilename). With "libisloaded", it returns 1, but the problem is "no functions found".
Is it really the compiler causing this issue? How should I change it?
Thanks!!
Siqi
Image Analyst
Image Analyst il 30 Mar 2015
Did you run Dependency Walker (Google it) on your DLL to see what functions it actually has in it?

5 Commenti

Yes, I see the functions from Dependency Walker consistent with the manufacturer's API manual. The problem is: the functions that Matlab is complaining about (see error message from the question) are defined in main.h, instead of the .dll file. Any idea what's wrong?
You might have to make a prototype file. See attached demo. Adapt as needed or ask the Mathworks. I'm no expert - I just did it once for a particular file and it's not something I do regularly.
I made the prototype file. After I created the file, I loaded the library again and it returns the same error. When I do "libfunctionsview" it returns that no functions found. But in the demo, the comment says we can ignore some of the error messages about parsing functions? How should I use the prototype file? Thanks!!
Hello,
With a second look, I suspect that this might be a compiler issue. Matlab is using lcc compiler, which is C. But in my header file, it contains "extern "C" ", which means it's for C++? Here is what my main header file looks like:
#define DLL_EXPORT #if defined DLL_EXPORT #define USB_DLL __declspec(dllexport) #else #define USB_DLL __declspec(dllimport) #endif #undef UNICODE #include windows.h #include malloc.h #include assert.h #include stdlib.h #include stdio.h #include "stdarg.h" #include "main.h" #include "devioctl.h" #include "ezusbsys.h" #include "RegisterDefines.h" extern "C" { ...//a bunch of functions here } //#############EOF################## I also created a prototype file, using the demo from the previous answer. I ran it using loadlibrary(dllfilename,@mfilename). With "libisloaded", it returns 1, but the problem is "no functions found".
Is it really the compiler causing this issue? How should I change it?
Thanks!!
Siqi
I don't really know - I've only had to do it once. I think you should just call them and ask them. Might as well get some support from them considering the huge amount of money you had to pay for the compiler toolbox.

Accedi per commentare.

Categorie

Prodotti

Richiesto:

il 30 Mar 2015

Commentato:

il 30 Set 2021

Community Treasure Hunt

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

Start Hunting!

Translated by