필터 지우기
필터 지우기

loadlibrary produces invalid thunk code

조회 수: 2 (최근 30일)
Krzysztof
Krzysztof 2013년 9월 17일
Here are my sources:
an_out = fopen ('foobar.h', 'w');
fwrite (an_out, [ '#include <windows.h>', 10, 'int WINAPI foo (), bar ();', 10 ]);
fclose (an_out);
an_out = fopen ('foobar.c', 'w');
fwrite...
(an_out, ...
[ ...
'#include <windows.h>', 10, ...
'_declspec (dllexport) int WINAPI foo (), WINAPI bar ();', 10, ...
'#include "foobar.h"', 10, ...
'_declspec (dllexport) int WINAPI foo () { return 0; } _declspec (dllexport) int WINAPI bar () { return 01; }', 10 ]);
fclose (an_out);
! CL /LD foobar.c
loadlibrary foobar
MATLAB-generated thunk code causes the following compiler error:
foobar_thunk_pcwin64.c(25) : error C2143: syntax error : missing ')' before '('
Here is the relevant source:
#include "foobar.h"
/* int __stdcall foo (), bar (); */
EXPORT_EXTERN_C int32_T int32voidPtrbar(Thunk(void fcn(),const char *callstack,int stacksize)
{
void * p0;
bar ( p1;
p0=*(void * const *)callstack;
callstack+=sizeof(p0) % sizeof(size_t) ? ((sizeof(p0) / sizeof(size_t)) + 1) * sizeof(size_t):sizeof(p0);
p1=*(bar ( const *)callstack;
callstack+=sizeof(p1) % sizeof(size_t) ? ((sizeof(p1) / sizeof(size_t)) + 1) * sizeof(size_t):sizeof(p1);
return ((int32_T (*)(void * , bar ( ))fcn)(p0 , p1);
}
You may wish to observe that the generated function declaration does not make sense.

채택된 답변

Philip Borghesani
Philip Borghesani 2013년 9월 17일
Although legal c this header code is certainly bad form and I would not recommend it. Unfortunately loadlibarary only properly recognizes one function deceleration per statement. I consider this a bug in loadlibrary please file a bug report.
To work around change
int WINAPI foo (), bar ();
Make it
int WINAPI foo ();
int WINAPI bar();

추가 답변 (0개)

카테고리

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