Prev: Fit problem
Next: Neural Network Toolbox
From: Sandy Buschmann on 1 Jul 2010 06:24 Hello, Maybe someone can help me with the following problem: This is my first time using a dynamic linked library with Matlab. This is the header: /*#ifndef _KMSECS2000DLL_H*/ #define _KMSECS2000DLL_H #define KMSECS2000DLL_API __declspec(dllimport) __stdcall typedef long USB_INI (long); typedef long USB_NUM (void); typedef long USB_IO (long, char*, long, long); /* Original Konica Minolta typedef INT (CALLBACK* USB_INI)(INT) typedef INT (CALLBACK* USB_NUM)(VOID) typedef INT (CALLBACK* USB_IO)(INT, LPSTR, INT, INT) */ extern "C" { long KMSECS2000DLL_API int_usb( long IndexDevice) { long retCode; HINSTANCE dllHandle = LoadLibrary("kmsecs200.dll"); USB_INI pint_usb; // Wenn Handle gueltig, ermittle Adresse der Funktion. if (dllHandle != NULL) { pint_usb = (USB_INI) GetProcAddress(dllHandle, "int_usb"); // Wenn Adresse gueltig, rufe die Funktion auf. if (NULL != pint_usb) { retCode = (pint_usb) ((long)IndexDevice); } // Aufraeumen FreeLibrary(dllHandle); return retCode; } long KMSECS2000DLL_API end_usb( long IndexDevice) { long retCode; HINSTANCE dllHandle = LoadLibrary("kmsecs200.dll"); USB_INI pend_usb; // Wenn Handle gueltig, ermittle Adresse der Funktion. if (dllHandle != NULL) { pend_usb = (USB_INI) GetProcAddress(dllHandle, "end_usb"); // Wenn Adresse gueltig, rufe die Funktion auf. if (NULL != pend_usb) { retCode = (pend_usb) ((long)IndexDevice); } // Aufraeumen FreeLibrary(dllHandle); return retCode; } long KMSECS2000DLL_API write64_usb ( long IndexDevice, char* Cmd, long Timeout, long WriteLen) { long retCode; HINSTANCE dllHandle = LoadLibrary("kmsecs200.dll"); USB_IO pwrite64_usb; // Wenn Handle gueltig, ermittle Adresse der Funktion. if (dllHandle != NULL) { pwrite64_usb = (USB_IO) GetProcAddress(dllHandle, "write64_usb"); // Wenn Adresse gueltig, rufe die Funktion auf. if (NULL != pwrite64_usb) { retCode = (pwrite64_usb) ((long)IndexDevice, (char*) Cmd, (long) Timeout, (long) WriteLen); } // Aufraeumen FreeLibrary(dllHandle); return retCode; } long KMSECS2000DLL_API read64_usb ( long IndexDevice, char* Cmd, long Timeout, long ReadLen) { long retCode; HINSTANCE dllHandle = LoadLibrary("kmsecs200.dll"); USB_IO pread64_usb; // Wenn Handle gueltig, ermittle Adresse der Funktion. if (dllHandle != NULL) { pread64_usb = (USB_IO) GetProcAddress(dllHandle, "read64_usb"); // Wenn Adresse gueltig, rufe die Funktion auf. if (NULL != pread64_usb) { retCode = (pread64_usb) ((long)IndexDevice, (char*) Cmd, (long) Timeout, (long) ReadLen); } // Aufraeumen FreeLibrary(dllHandle); return retCode; } } And this is my first try to load the library and call a function: clear addpath('C:\Programme\KONICAMINOLTA\CS-S10w'); if not(libisloaded('lib')) [NOTFOUND, WARNINGS] = loadlibrary('KMSECS2000','Kmsecs2000.h','alias','lib'); end libisloaded('lib') m = libfunctions('lib') [result] = calllib('lib','int_usb',0) disp(result) But Matlab is answering the following: >> open2 ans = 1 m = [] ??? Error using ==> calllib Method was not found. Error in ==> open2 at 16 [result] = calllib('lib','int_usb',0) As you can see, there seems to be no problem with loading the library but Matlab hasn't found any methods. Does anyone know what the problem is not finding functions or methods in the .dll file?Is there something wrong with the header file? Best regards, Sandy
From: Philip Borghesani on 1 Jul 2010 13:53 The header posted not a normal header file for defining functions in a library. All that is needed for Loadlibrary is something like this: /* begin header file */ #define KMSECS2000DLL_API __declspec(dllimport) __stdcall long KMSECS2000DLL_API int_usb( long IndexDevice); long KMSECS2000DLL_API end_usb( long IndexDevice) long KMSECS2000DLL_API write64_usb ( long IndexDevice, char* Cmd, long Timeout, long WriteLen) /* end untested header file */ It is possible the vendor supplied a different header file with more normal definitions. The header supplied is more like an example of how to dynamically link with the library from C. It is doing work that is normally done by the MATLAB loadlibrary function. Phil "Sandy Buschmann" <buscbfme(a)mailbox.tu-berlin.de> wrote in message news:i0hqc4$1m$1(a)fred.mathworks.com... > Hello, > > Maybe someone can help me with the following problem: > > This is my first time using a dynamic linked library with Matlab. > This is the header: > > /*#ifndef _KMSECS2000DLL_H*/ > #define _KMSECS2000DLL_H > #define KMSECS2000DLL_API __declspec(dllimport) __stdcall typedef long USB_INI (long); > typedef long USB_NUM (void); > typedef long USB_IO (long, char*, long, long); > /* Original Konica Minolta > typedef INT (CALLBACK* USB_INI)(INT) > typedef INT (CALLBACK* USB_NUM)(VOID) > typedef INT (CALLBACK* USB_IO)(INT, LPSTR, INT, INT) > */ > extern "C" > { > long KMSECS2000DLL_API int_usb( long IndexDevice) > { > long retCode; > HINSTANCE dllHandle = LoadLibrary("kmsecs200.dll"); > USB_INI pint_usb; > // Wenn Handle gueltig, ermittle Adresse der Funktion. > if (dllHandle != NULL) { > pint_usb = (USB_INI) GetProcAddress(dllHandle, "int_usb"); > // Wenn Adresse gueltig, rufe die Funktion auf. > if (NULL != pint_usb) { > retCode = (pint_usb) ((long)IndexDevice); > } > // Aufraeumen > FreeLibrary(dllHandle); > return retCode; > } > long KMSECS2000DLL_API end_usb( long IndexDevice) > { > long retCode; > HINSTANCE dllHandle = LoadLibrary("kmsecs200.dll"); > USB_INI pend_usb; > // Wenn Handle gueltig, ermittle Adresse der Funktion. > if (dllHandle != NULL) { > pend_usb = (USB_INI) GetProcAddress(dllHandle, "end_usb"); > // Wenn Adresse gueltig, rufe die Funktion auf. > if (NULL != pend_usb) { > retCode = (pend_usb) ((long)IndexDevice); > } > // Aufraeumen > FreeLibrary(dllHandle); > return retCode; > } > long KMSECS2000DLL_API write64_usb ( long IndexDevice, char* Cmd, long Timeout, long WriteLen) > { > long retCode; > HINSTANCE dllHandle = LoadLibrary("kmsecs200.dll"); > USB_IO pwrite64_usb; > // Wenn Handle gueltig, ermittle Adresse der Funktion. > if (dllHandle != NULL) { > pwrite64_usb = (USB_IO) GetProcAddress(dllHandle, "write64_usb"); > // Wenn Adresse gueltig, rufe die Funktion auf. > if (NULL != pwrite64_usb) { > retCode = (pwrite64_usb) ((long)IndexDevice, (char*) Cmd, (long) Timeout, (long) WriteLen); > } > // Aufraeumen > FreeLibrary(dllHandle); > return retCode; > } > long KMSECS2000DLL_API read64_usb ( long IndexDevice, char* Cmd, long Timeout, long ReadLen) > { > long retCode; > HINSTANCE dllHandle = LoadLibrary("kmsecs200.dll"); > USB_IO pread64_usb; > // Wenn Handle gueltig, ermittle Adresse der Funktion. > if (dllHandle != NULL) { > pread64_usb = (USB_IO) GetProcAddress(dllHandle, "read64_usb"); > // Wenn Adresse gueltig, rufe die Funktion auf. > if (NULL != pread64_usb) { > retCode = (pread64_usb) ((long)IndexDevice, (char*) Cmd, (long) Timeout, (long) ReadLen); > } > // Aufraeumen > FreeLibrary(dllHandle); > return retCode; > } > } > > > > > And this is my first try to load the library and call a function: > > clear > addpath('C:\Programme\KONICAMINOLTA\CS-S10w'); > if not(libisloaded('lib')) > [NOTFOUND, WARNINGS] = loadlibrary('KMSECS2000','Kmsecs2000.h','alias','lib'); > end > libisloaded('lib') > m = libfunctions('lib') > [result] = calllib('lib','int_usb',0) > disp(result) > > > But Matlab is answering the following: >>> open2 > > ans = > > 1 > > > m = > > [] > > ??? Error using ==> calllib > Method was not found. > > Error in ==> open2 at 16 > [result] = calllib('lib','int_usb',0) > > > As you can see, there seems to be no problem with loading the library but Matlab hasn't found any methods. > Does anyone know what the problem is not finding functions or methods in the .dll file?Is there something wrong with the header > file? > > Best regards, > > Sandy >
From: Sandy Buschmann on 5 Jul 2010 04:51 Hi, thank you very much for your help. But it doesn't work... MATLAB still doesn't find functions or methods. Maybe you have another idea? Anyway, I try to get another header file from the vendor. I'll tell you. Bye, Sandy.
|
Pages: 1 Prev: Fit problem Next: Neural Network Toolbox |