Prev: Help needed with fminsearch
Next: Can a mex file share same memory as Simulink variables by accident?
From: Kevin on 13 Jul 2010 05:53 Hello, I have a problem with a compiled script I wrote in matlab that is using functions from a dll file written in delphi. At the beginning before I compiled the script I loaded the dll by using a header file and it worked out fine. But when I wanted to compile it I read that compiled matlab application doesn't support loading library with H-file header. The article here : http://www.mathworks.com/support/solutions/en/data/1-1AJI4/?solution=1-1AJI4 suggested that I should create MATLAB file prototypes to load the library. So I generated the prototype file : loadlibrary('Drivers\SCANNER.dll', 'Drivers\SCANNERDLL.h', 'mfilename', 'mHeader'); and used it by calling this : loadlibrary('Drivers\SCANNER.dll', @mHeader, 'alias', 'SCANNERLIB'); calllib('SCANNERLIB', 'ScannerOpenDevice'); which again works only as a matlab script matlab but not as a compiled application. As a compiled application I kept getting the segmentation fault message on certain dll function. The h-file header looked like this : ++++++++++++++++++++++++++++++++++++++++++++++++++++ #if defined DLL_EXPORT #define DECLDIR __declspec(dllexport) #else #define DECLDIR __declspec(dllimport) #endif DECLDIR int __stdcall SetStepperMode(int Mode);//21 DECLDIR bool __stdcall ScannerOpenDevice();//18 ============================================== and the generated prototype file : ++++++++++++++++++++++++++++++++++++++++++++++++++++ function [methodinfo,structs,enuminfo,ThunkLibName]=mHeader % bool _stdcall ScannerOpenDevice (); fcns.name{fcnNum}='ScannerOpenDevice'; fcns.calltype{fcnNum}='stdcall'; fcns.LHS{fcnNum}='bool'; fcns.RHS{fcnNum}=[];fcnNum=fcnNum+1; % int _stdcall SetStepperMode ( int Mode ); fcns.name{fcnNum}='SetStepperMode'; fcns.calltype{fcnNum}='stdcall'; fcns.LHS{fcnNum}='int32'; fcns.RHS{fcnNum}={'int32'};fcnNum=fcnNum+1; ============================================= The segmentation fault seems to appear when I call the ScannerOpenDevice function but not SetStepperMode. Does anybody know where the problem is ?
From: Kevin on 13 Jul 2010 06:25 Sorry I meant segmentation violation of course MATLAB crash file:C:\DOCUME~1\keang\LOCALS~1\Temp\matlab_crash_dump.1292 ------------------------------------------------------------------------ Segmentation violation detected at Tue Jul 13 12:19:21 2010 ------------------------------------------------------------------------ Configuration: MATLAB Version: 7.8.0.347 (R2009a) MATLAB License: 583182 Operating System: Microsoft Windows XP Window System: Version 5.1 (Build 2600: Service Pack 3) Processor ID: x86 Family 6 Model 7 Stepping 10, GenuineIntel Virtual Machine: Java 1.6.0_04-b12 with Sun Microsystems Inc. Java HotSpot(TM) Client VM mixed mode Default Encoding: windows-1252 Fault Count: 1 Register State: EAX = 00c2dabc EBX = fffff829 ECX = 00000000 EDX = 054712a5 ESI = 00c2db40 EDI = 00000013 EBP = 00c2db0c ESP = 00c2dab8 EIP = 7c812afb FLG = 00000202 Stack Trace: [0] kernel32.dll:0x7c812afb(0x0eedfade, 1, 7, 0x00c2db24) bc) + 594 bytes
From: Kevin on 14 Jul 2010 09:21 I need to add that this error message only comes up when I call the particular function OpenScanner. This really confuses me because another function called CloseScanner with the same format doesn't seem to have any problem. Could this be a problem in the compiler ??
From: Kevin on 15 Jul 2010 08:59
Problem solved. I mistakenly added an extra dll file in the deploy tool that wasn't needed. |