Error using calllib Too many inputs passed to SimpleFunctionThunk.

조회 수: 5 (최근 30일)
sahil gandhi
sahil gandhi 2015년 8월 18일
답변: sahil gandhi 2018년 1월 30일
I am using the calllib function to call on my 64-bit C++ lib. I am using Matlab R2015a. The prototype used to load the library using the loadlibrary function is
ival={cell(1,1)};
fcns=struct('name',ival,'calltype',ival,'LHS',ival,'RHS',ival,'alias',ival);
structs=[];
enuminfo=[];
fcns.name{1}='MyFunc'; fcns.calltype{1}='cdecl'; fcns.LHS{1}='doublePtr'; fcns.RHS{1}={ ...
'stringPtr' , 'int32Ptr' , 'stringPtr' , ...
'int32Ptr' , 'stringPtr' , 'int32Ptr' , ...
'int32Ptr' , 'doublePtr' , 'int32Ptr'};
methodinfo=fcns;
After the loadlibrary, I have verified that its loaded using the libfunctionsview function. After the call is made, i get the following error
Error using calllib
Too many inputs passed to SimpleFunctionThunk.
Please let me know if there is any fix to this issue.
-Sahil
  댓글 수: 1
dpb
dpb 2015년 8월 18일
Have you responded to Steven's query at the identical query in the newsgroup?

댓글을 달려면 로그인하십시오.

채택된 답변

sahil gandhi
sahil gandhi 2018년 1월 30일
Its been a while, but a colleague connected with me for the same issue, and I thought to document the resolution, so here it goes..
  • Ensure that along with the dll you have the following files
  1. The header (.h) file for the function you are calling in the same location
  2. The TFLib.dll for the dll
  • When you create a prototype for the function in matlab it should look something like this
function [methodinfo,structs,enuminfo, ThunkLibName]=Prototype
ival={cell(1,1)};
fcns=struct('name',ival,'calltype',ival,'LHS',ival,'RHS',ival,'alias',ival, 'thunkname', ival);
structs=[];
enuminfo=[];
%MfilePath=fileparts(mfilename('fullpath'));
ThunkLibName='C:\Works\SampleCode\TFLib';
fcns.thunkname{1}=''; fcns.name{1}='MyFunc'; fcns.calltype{1}='Thunk'; fcns.LHS{1}='doublePtr'; fcns.RHS{1}={ ...
'stringPtr' , 'int32Ptr' , 'stringPtr' , ...
'int32Ptr' , 'stringPtr' , 'int32Ptr' , ...
'int32Ptr' , 'doublePtr' , 'int32Ptr'};
methodinfo=fcns;
Note: Compare with the prototype in the question to see the difference.
  • In the loadlibrary call, pass the header (.h) file. The dll name in this example is SampleCode.dll in the following location "C:\Works\SampleCode"
loadlibrary 'C:\Works\SampleCode\SampleCode' 'C:\Works\SampleCode\SampleCode.h';
  • C++ Compiler needs to be installed which is part of the Windows SDK 7.1. The following steps need to be followed
  1. Remove the following from if already installe
  2. Microsoft Visual Studio 2010 C++ Redistributable
  3. Anything above Microsoft .Net 4.0 Framework
  4. Install Microsoft .Net 4.0 Framework
  5. Install the Windows SDK 7.1
  6. Ensure that the C++ Compiler options is enabled
  7. Ensure that the installation is successful
  8. Run the “mex -setup c++”.
  9. Check for the following messageMEX configured to use 'Microsoft Windows SDK 7.1 (C++)' for C++ language compilation.
  10. Now install the updates to C++ Redistributables and .Net framework if desired.
Hope this works fine, and resolves the issue. Feel free to post a comment/corrections.

추가 답변 (1개)

Philip Borghesani
Philip Borghesani 2015년 8월 18일
Calltype of 'cdecl' is not supported on 64 bit systems however it does work for simple functions with a limited number of integer and pointer arguments. You will need to use a thunkfile to call this function. Try loading your file with a new loadlibrary command starting from scratch and examine the generated prototype information and thunk file.

카테고리

Help CenterFile Exchange에서 C Shared Library Integration에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by