[MATLAB] Appeler une structure C d'une dll avec Calllib (crash)

Appeler une structure C d'une dll avec Calllib (crash) [MATLAB] - Langages fonctionnels - Programmation

Marsh Posté le 05-12-2011 à 10:28:58    

Bonjour, j'essaye depuis un moment d'appeler une structure C (qui est dans une dll) à partir d'un programme matlab. Hélas, après de nombreuses tentatives, je n'obtiens pas de résultat et Matlab crash à chaque fois (voir rapport d'erreur ci-dessous). Il semblerait que l'erreur se situe au niveau de la fonction calllib(), lorsque je fais appel à ma fonction C info_version() via ma librairie toolboxind.dll.  
Voici mon code matlab:
 
function [st]=testC(a)
 
if ~libisloaded('toolboxind')
loadlibrary('toolboxind.dll',@mHeader);
end
 
a=int32(1);
st=libstruct('numeroversion');
[st]=calllib('toolboxind', 'info_version', a);
 
unloadlibrary('toolboxind')
end
 
Quelqu'un peut-il m'aider?
 
Merci.
 
Le rapport d'erreur quand matlab plante:
 
------------------------------------------------------------------------
       Segmentation violation detected at Mon Dec 05 10:10:14 2011
------------------------------------------------------------------------
 
Configuration:
  MATLAB Version:   7.8.0.347 (R2009a)
  MATLAB License:   311980
  Operating System: Microsoft Windows XP
  Window System:    Version 5.1 (Build 2600: Service Pack 2)
  Processor ID:     x86 Family 15 Model 4 Stepping 1, 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 = 00c2ded8  EBX = 00000001
  ECX = 00000032  EDX = 00313130
  ESI = 00c2ded8  EDI = 00000001
  EBP = 00c2df30  ESP = 00c2dec8
  EIP = 6b0c11fa  FLG = 00010246
 
Stack Trace:
  [0] toolboxind.dll:0x6b0c11fa(1, 0x6b0c027f, 0x00c2df78, 0x6be15206)
  [1] libmwcli.dll:void * __cdecl callstdfcn(void const *,void const *,int)(0x6b0c11d0, 0x0c1c97c0, 4, 0x0d3b736c) + 35 bytes
  [2] libmwcli.dll:public: void __thiscall CCallMI::CallFcn(class UDMethodSignature *,void * *)(0x0d56027f, 0x00c2dfd4, 0x0d3b7350 "(þâk", 0x00c2dfd4) + 182 bytes
  [3] libmwcli.dll:public: virtual void __thiscall CCallMI::invokeMethod(class UDMethodSignature *,int *,void * *,int,void * *)(0x0d56f480, 0x00c2dff8, 0x00c2dfd4, 1) + 299 bytes
  [4] libmwcli.dll:void __cdecl CallLibFunction(char *,char *,int,struct mxArray_tag * * const,int,struct mxArray_tag const * * const)(0x0d6187e0 "toolboxind", 0x0d617110 "info_version", 1, 0x00c2e1dc) + 544 bytes
  [5] libmwcli.dll:_mfCallLib(1, 0x00c2e1dc, 0x0d6187e0 "toolboxind", 0x00c2e23c) + 145 bytes
  [6] m_dispatcher.dll:public: virtual void __thiscall Mfh_builtin::dispatch_mf(int,struct mxArray_tag * *,int,struct mxArray_tag * *)(1, 0x00c2e1dc, 3, 0x00c2e23c) + 92 bytes
  [7] m_dispatcher.dll:public: virtual void __thiscall Mfh_MATLAB_fn::dispatch_fh(int,struct mxArray_tag * *,int,struct mxArray_tag * *)(1, 0x00c2e1dc, 3, 0x00c2e23c) + 193 bytes
  [8] m_interpreter.dll:int __cdecl inDispatchFromStack(int,char const *,int,int)(163, 0x02292764 "calllib", 1, 3) + 623 bytes
  [9] m_interpreter.dll:int __cdecl inInterp(enum inDebugCheck,int,int,enum opcodes,struct inPcodeNest_tag volatile *,int *)(1, 152, 11, 0) + 1317 bytes
  [10] m_interpreter.dll:int __cdecl protected_inInterp(enum inDebugCheck,int,int,enum opcodes,struct inPcodeNest_tag *,int *)(1, 152, 2, 0) + 39 bytes
  [11] m_interpreter.dll:int __cdecl inInterPcodeSJ(enum inDebugCheck,int,int,enum opcodes,struct inPcodeNest_tag *,int *)(1, 152, 2, 0) + 251 bytes
  [12] m_interpreter.dll:int __cdecl inExecuteMFunctionOrScript(class Mfh_mp *,bool)(0xffffff00, 0xffffffff, 0x0d540560, 0) + 935 bytes
  [13] m_interpreter.dll:void __cdecl inRunMfile(int,struct mxArray_tag * *,int,struct mxArray_tag * *,class Mfh_mp *,struct inWorkSpace_tag *)(0, 0x00c2e9d0, 0, 0x00c2e940) + 466 bytes
  [14] m_interpreter.dll:public: virtual void __thiscall Mfh_mp::dispatch_file(struct _mdUnknown_workspace *,int,struct mxArray_tag * *,int,struct mxArray_tag * *)(0, 0, 0x00c2e9d0, 0) + 23 bytes
  [15] m_interpreter.dll:public: virtual void __thiscall Mfh_mp::dispatch_file(int,struct mxArray_tag * *,int,struct mxArray_tag * *)(0, 0x00c2e9d0, 0, 0x00c2e940) + 22 bytes
  [16] m_dispatcher.dll:public: virtual void __thiscall Mfh_file::dispatch_fh(int,struct mxArray_tag * *,int,struct mxArray_tag * *)(0, 0x00c2e9d0, 0, 0x00c2e940) + 204 bytes
  [17] m_interpreter.dll:public: void __thiscall ResolverFunctionDesc::CallFunction(int,struct mxArray_tag * * const,int,struct mxArray_tag * * const)(0, 0x00c2e9d0, 0, 0x00c2f13c) + 81 bytes
  [18] m_interpreter.dll:public: bool __thiscall Resolver::CallMFunction(int,int,class _m_operand * const,union m_operand_storage *,int,class _m_operand * const,union m_operand_storage *,int *)(0x00c2ec18, 0, 1, 0x0d4df878) + 1209 bytes
  [19] m_interpreter.dll:private: bool __thiscall accelImpl::MFunctionCall(struct _accelOp * *)(0, 0xffffffff, 0x024a2220, 0x0c1a9b48) + 266 bytes
  [20] m_interpreter.dll:public: enum jitReturnFlags __thiscall accelImpl::Exec(void)(0x00c2f13c, 0xffffffff, 0xffffffff, 0x0c1a9b48) + 170 bytes
  [21] m_interpreter.dll:public: enum jitReturnFlags __thiscall accelCode::Call(enum inMarshalType *,int *)const (0x00c2f3dc, 0x0c1b8318, 0, 0) + 115 bytes
  [22] m_interpreter.dll:public: static bool __cdecl inJit::ExecuteHotSegment(struct _inJitAccelInfo *,enum opcodes *,int *,int *)(0x00c2f4b0, 0x00c2f488, 0x00c2f4ac, 0x00c2f4a8) + 2523 bytes
  [23] m_interpreter.dll:int __cdecl inExecuteMFunctionOrScript(class Mfh_mp *,bool)(0xffffff01, 0xffffffff, 0x0d569548 "4ð=zÒ!", 0) + 572 bytes
  [24] m_interpreter.dll:void __cdecl inRunMfile(int,struct mxArray_tag * *,int,struct mxArray_tag * *,class Mfh_mp *,struct inWorkSpace_tag *)(0, 0x00c2f9a0, 0, 0) + 466 bytes
  [25] m_interpreter.dll:public: virtual void __thiscall Mfh_mp::dispatch_file(struct _mdUnknown_workspace *,int,struct mxArray_tag * *,int,struct mxArray_tag * *)(0, 0, 0x00c2f9a0, 0) + 23 bytes
  [26] m_interpreter.dll:public: virtual void __thiscall Mfh_mp::dispatch_file(int,struct mxArray_tag * *,int,struct mxArray_tag * *)(0, 0x00c2f9a0, 0, 0) + 22 bytes
  [27] m_dispatcher.dll:public: virtual void __thiscall Mfh_file::dispatch_fh(int,struct mxArray_tag * *,int,struct mxArray_tag * *)(0, 0x00c2f9a0, 0, 0) + 204 bytes
  [28] m_interpreter.dll:void __cdecl inEvalPcodeHeaderToWord(struct _memory_context *,int,struct mxArray_tag * * const,struct _pcodeheader *,class Mfh_mp *,unsigned long)(0x7b319ca4, 0, 0x00c2f9a0, 0x00c2f8b0) + 73 bytes
  [29] m_interpreter.dll:enum inExecutionStatus __cdecl in_local_call_script_function(struct _memory_context *,struct _pcodeheader *,int,struct mxArray_tag * * const,unsigned long,bool)(0x7b319ca4, 0x00c2f8b0, 0, 0x00c2f9a0) + 70 bytes
  [30] m_interpreter.dll:__catch$??1inProtectHotSegment@@QAE@XZ$0(0x7b319ca4, 0x022b5038 "testC\n", 0, 0) + 946 bytes
  [31] m_interpreter.dll:enum inExecutionStatus __cdecl inEvalCmdWithLocalReturn(char const *,int *,bool,bool,bool (__cdecl*)(void *,char const *))(0x022b5038 "testC\n", 0, 0, 1) + 80 bytes
  [32] m_interpreter.dll:public: virtual enum inExecutionStatus __thiscall InterpBridge::EvalCmdWithLocalReturn(char const *,int *,bool,bool)(0x022b5038 "testC\n", 0, 0, 1) + 25 bytes
  [33] m_interpreter.dll:_inEvalCmdWithLocalReturn(0x022b5038 "testC\n", 0, 0, 1) + 27 bytes
  [34] bridge.dll:enum inExecutionStatus __cdecl evalCommandWithLongjmpSafety(char const *)(0x022b5038 "testC\n", 0, 0x048516d0, 0) + 67 bytes
  [35] bridge.dll:__catch$_mnParser$0(0x0231d338, 0x022831e8, 0x746a0e01, 0x00c2fb28 "PûÂ" ) + 300 bytes
  [36] mcr.dll:private: void __thiscall mcrInstance::mnParser_on_interpreter_thread(void)(0x04851708, 0x00c2fb3c, 0x7e39ea7e, 0x00030000 "Actx " ) + 51 bytes
  [37] mcr.dll:public: void __thiscall boost::function0<void>::operator()(void)const (0, 0x048516d0, 0, 0x048516d0) + 63 bytes
  [38] mcr.dll:public: virtual void __thiscall mcr::runtime::InterpreterThread::Impl::NoResultInvocationRequest::run(void)(0x79a92a60, 0x00c2fb70, 48, 0x00030000 "Actx " ) + 53 bytes
  [39] mcr.dll:private: static void __cdecl mcr::runtime::InterpreterThread::Impl::invocation_request_handler(int)(0x048516d0, 0, 0x00030000 "Actx ", 0x00c2fcb4) + 40 bytes
  [40] uiw.dll:bool __cdecl UIW_DispatchUserMessage(int,int)(9225, 0x048516d0, 0x00c2fcb4, 3) + 73 bytes
  [41] uiw.dll:long __stdcall HandleUserMsgHook(int,unsigned int,long)(0, 1, 0x00c2fcb4, 0x79493520) + 95 bytes
  [42] USER32.dll:0x7e3b1913(0x00030000 "Actx ", 1, 0x00c2fcb4, 0x7aba74f0)
  [43] USER32.dll:0x7e39ea7e(0x00c2fca4, 0x00c2fcb4, 0x00c2fcd0, 0)
  [44] USER32.dll:0x7e39ebd3(0x00c2fca4, 48, 0x00030000 "Actx ", 1)
  [45] ntdll.dll:0x7c91eae3(0x00c2fd20, 0, 0, 0)
  [46] uiw.dll:void __cdecl UIW_GetAndDispatchMessage(struct tagMSG *)(0x00c2fd20, 3, 3, 0x048516d0) + 20 bytes
  [47] uiw.dll:void __cdecl UIW_GetAndDispatchMessage(void)(0x02271b78, 0, 0x024b1b60, 0) + 15 bytes
  [48] uiw.dll:void __cdecl ws_ProcessPendingEventsMainLoop(int,bool)(1, 0, 0x00c2fdbc "üýÂ", 0x79a9543a) + 356 bytes
  [49] uiw.dll:void __cdecl ws_ProcessPendingEvents(int,int)(1, 0xffffffff, 0x02271b78, 0x024b1b60) + 14 bytes
  [50] mcr.dll:public: void __thiscall mcr::runtime::InterpreterThread::Impl::process_events(class boost::shared_ptr<class mcr::runtime::InterpreterThread::Impl> const & )(0x00c2fe14, 2, 0x024b1738, 0x02eedd98) + 138 bytes
  [51] mcr.dll:__catch$?run@Impl@InterpreterThread@runtime@mcr@@QAEKABV?$shared_ptr@VImpl@InterpreterThread@runtime@mcr@@@boost@@PAUinit_context@1234@@Z$0(0x00c2fe14, 0x024b42c0, 0x79a95800, 0x024b5888) + 128 bytes
  [52] mcr.dll:unsigned long __cdecl run_init_and_handle_events(void *)(0x02eedd98, 0, 0x024b16c0, 0) + 76 bytes
  [53] mcr.dll:private: void __thiscall mcr::runtime::InterpreterThreadFactory::runThreadFunction(void)(0x00c2fec8, 0x00c2fe80, 0x00c2fe84 "ðþÂ", 0x7b299c7c) + 108 bytes
  [54] MATLAB.exe:public: void __thiscall boost::function0<void>::operator()(void)const (336710, 0x004077d4, 0, 0x78131731) + 63 bytes
  [55] MATLAB.exe:int __cdecl mcrMain(int,char const * * const)(1, 0x024b4b78, 4194304, 10) + 230 bytes
  [56] MATLAB.exe:_WinMain@16(4194304, 0, 336710, 10) + 75 bytes
  [57] MATLAB.exe:___tmainCRTStartup(0, 0, 0x7ffd5000, 0x8054a6ed) + 320 bytes
  [58] kernel32.dll:0x7c816fd7(0x0040324a, 0, 0x00905a4d, 3)
 
Please follow these steps to report this problem to The MathWorks so we
have the best chance of correcting it:
 
The next time MATLAB is launched under typical usage, a dialog box will
open to help you send the error log to The MathWorks. Alternatively, you
can send an e-mail to segv@mathworks.com with the following file attached:
    C:\TEMP\matlab_crash_dump.128
 
If the problem is reproducible, please submit a Service Request via:
    http://www.mathworks.com/support/c [...] est_1.html
 
A technical support engineer might contact you with further information.
 
Thank you for your help. MATLAB may attempt to recover, but even if recovery appears successful,
we recommend that you save your workspace and restart MATLAB as soon as possible.
 
Caught MathWorks::System::FatalException


Message édité par dr-xam le 09-12-2011 à 13:59:47
Reply

Marsh Posté le 05-12-2011 à 10:28:58   

Reply

Marsh Posté le 09-12-2011 à 13:48:11    

J'ai trouvé mon problème. La dll n'était pas correcte. J'ai encore des erreurs, notamment quand je veux retourner un simple entier, matlab affiche:
ans = libpointer
 
Alors que je n'ai pas de pointeur dans ma fonction C:
 
int call test (int a){
     
    return 2*a;
}    
 
Peut-être que cela vient de mon code matlab:
 
if ~libisloaded('toolboxind')
loadlibrary('toolboxind.dll', @mHeader);
end
 
libfunctions toolboxind -full
 
calllib('toolboxind', 'test', 2)
   
unloadlibrary('toolboxind')
 
Une idée svp?  :D


Message édité par dr-xam le 09-12-2011 à 13:58:44
Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed