error in calling functions from a DLL file

7 views (last 30 days)
Siqi Li
Siqi Li on 10 Mar 2015
Answered: Siqi Li on 23 Mar 2015
I'm trying to control a USB device using DLL file in Matlab. The library seems to be loaded but I can't view the functions in the DLL file. Here is my code and error messages:
fullpathToDll='C:\WINDOWS\system32\D4100_usb.dll'
>> loadlibrary(fullpathToDll) Warning: Function C:\WINDOWS\system32\version.dll has the same name as a MATLAB builtin. We suggest you rename the function to avoid a potential name conflict. > In tempdir at 42 In loadlibrary at 257 Warning: Function C:\WINDOWS\system32\input.dll has the same name as a MATLAB builtin. We suggest you rename the function to avoid a potential name conflict. > In tempdir at 42 In loadlibrary at 257 Warning: Message from C preprocessor: lcc preprocessor warning: C:\WINDOWS\system32\main.h:173 C:\WINDOWS\system32\D4100_usb.h:19 EOF inside comment lcc preprocessor error: C:\WINDOWS\system32\devioctl.h:136 C:\WINDOWS\system32\D4100_usb.h:21 Macro redefinition of FILE_READ_ACCESS lcc preprocessor error: C:\WINDOWS\system32\devioctl.h:137 C:\WINDOWS\system32\D4100_usb.h:21 Macro redefinition of FILE_WRITE_ACCESS lcc preprocessor warning: C:\WINDOWS\system32\RegisterDefines.h:40 C:\WINDOWS\system32\D4100_usb.h:23 EOF inside comment lcc preprocessor warning: C:\WINDOWS\system32\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 library class 'D4100_usb' already exists. Use a classname alias. > In loadlibrary at 319 Warning: Function C:\WINDOWS\system32\version.dll has the same name as a MATLAB builtin. We suggest you rename the function to avoid a potential name conflict. > In loadlibrary at 322 Warning: Function C:\WINDOWS\system32\input.dll has the same name as a MATLAB builtin. We suggest you rename the function to avoid a potential name conflict. > In loadlibrary at 322
>> libisloaded('D4100_usb')
ans =
1
>> libfunctionsview D4100_usb ??? Error using ==> libfunctionsview No library D4100_usb can be located or no functions for library D4100_usb
I also checked that my Matlab has the lcc compiler:
>> mex -setup Please choose your compiler for building external interface (MEX) files:
Would you like mex to locate installed compilers [y]/n? y
Select a compiler: [1] Lcc C version 2.4.1 in C:\PROGRA~1\MATLAB\R2006b\sys\lcc
[0] None
Compiler: 1
Please verify your choices:
Compiler: Lcc C 2.4.1 Location: C:\PROGRA~1\MATLAB\R2006b\sys\lcc
Are these correct?([y]/n): y
Trying to update options file: C:\Documents and Settings\laser\Application Data\MathWorks\MATLAB\R2006b\mexopts.bat From template: C:\PROGRA~1\MATLAB\R2006b\bin\win32\mexopts\lccopts.bat
Done . . .
But that still doesn't work..
Please help. Thanks.
Siqi

Answers (3)

Philip Borghesani
Philip Borghesani on 11 Mar 2015
Is the windows system directory on your MATLAB path? It should not be and is causing the warnings that look like:
Warning: Function C:\WINDOWS\system32\version.dll has the same name as a MATLAB builtin. We suggest you rename the function to avoid a potential name conflict. > In tempdir at 42 In loadlibrary at 257
It looks like you put the header files needed in the windows/system32 directory? that is a really bad idea and is probably the cause of some of the problem.
It is unlikely that a header file named main.h will be useful in a loadlibrary command.
  3 Comments
Philip Borghesani
Philip Borghesani on 11 Mar 2015
Put the header files anywhere convenient. The library (dll) install tool location usually works if not I would start with your current working folder or a sub-directory of it if the code is not being shared with other people.
When you get the headers straightened out if you still do not have any functions in your library after a call to:
[notfound,warnings]=loadlibrary(...,'mfilename','myheader_proto')
with no warning or errors then examine the contents of notfound and warnings and attach any relevant information from them allong with some or all of the generated prototype file to a new question or support call.
Siqi Li
Siqi Li on 11 Mar 2015
Hi Phillip,
Using addpath I've added 'C:\WINDOWS\system32' into Matlab path, and now it shows up when I enter the 'path' command. I've also put all the header files in a different folder. The code is below:
>> fullpathToDll='C:\WINDOWS\system32\D4100_usb.dll'
>> header1='C:\D4100Headers\D4100_usb';
>> header2='C:\D4100Headers\resource.h';
>> header3='C:\D4100Headers\devioctl.h';
>> header4='C:\D4100Headers\ezusbsys.h';
>> header5='C:\D4100Headers\main.h';
>> header6='C:\D4100Headers\RegisterDefines.h';
loadlibrary(fullpathToDll,header1,'addheader',header2,'addheader',header3,'addheader',header4,'addheader',header5,'addheader',header6);
Warning: Message from C preprocessor:
lcc preprocessor warning: C:\D4100Headers\main.h:173 C:\D4100Headers\D4100_usb.h:19 EOF inside comment
lcc preprocessor error: C:\WINDOWS\system32\devioctl.h:136 C:\WINDOWS\system32\D4100_usb.h:21 Macro redefinition of FILE_READ_ACCESS
lcc preprocessor error: C:\WINDOWS\system32\devioctl.h:137 C:\WINDOWS\system32\D4100_usb.h:21 Macro redefinition of FILE_WRITE_ACCESS
lcc preprocessor warning: C:\D4100Headers\RegisterDefines.h:40 C:\D4100Headers\D4100_usb.h:23 EOF inside comment
lcc preprocessor warning: C:\D4100Headers\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: Function C:\WINDOWS\system32\version.dll has the same name as a MATLAB builtin. We suggest you rename the function to avoid a potential name conflict.
> In loadlibrary at 322 Warning: Function C:\WINDOWS\system32\input.dll has the same name as a MATLAB builtin. We suggest you rename the function to avoid a potential name conflict.
> In loadlibrary at 322 Warning: No functions found in library.
*******************************************************************
Why is it still not able to find any functions in the library?
Thank you in advance for your help!
Siqi

Sign in to comment.


Siqi Li
Siqi Li on 16 Mar 2015
I've put the DLL file and header files in a separate folder, and now it gives me errors "functions not found in the library". I've looked at the main header file which seems to be correct. It defines 'DLL_EXPORT' and extern 'C' for all the functions included. I'm using Windows XP and Matlab R2006B, with Lcc C version 2.4.1 in C:\PROGRA~1\MATLAB\R2006b\sys\lcc. What could be the problem causing "functions not found"?
Please help!
Siqi

Siqi Li
Siqi Li on 23 Mar 2015
Can someone please help out? -Siqi

Categories

Find more on C Shared Library Integration in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!