Com-Callback for pointer to SafeArray
조회 수: 4 (최근 30일)
이전 댓글 표시
Hi,
i have build a COM-Server which has a connection point implemented.
The Callback-Interface is defined linke this in COM:
// Interface IFxcmCallback
[
object, /// (D)COM OBjekt
uuid(F9394ABF-D988-40BB-A684-5D6E3BC91BF7), /// IID
helpstring("IFxcmCallback Interface"),
oleautomation,
dual
]
interface IFxcmCallback : IDispatch
{
[id(1)] HRESULT GetCallbackConfig([out] SAFEARRAY(s_CallbackConfig_t) * );
[id(2)] HRESULT TicksCallback([in] SAFEARRAY(s_FxcmOffers_t) );
};
The Callbacks in Matlab are defined like this:
function MyGetCallbackConfig ( varargin )
varargin{1} = 1;
msgbox("OK");
end
and this:
function MyTicksCallback (varargin)
msgbox("OK");
end
I think that this functions are not defined the correct way. Because after setting up the Connection;
c = actxserver('Backtester.IFxcmOrder')
registerevent(c,{'GetCallbackConfig' '@MyGetCallbackConfig'; 'TicksCallback' '@MyTicksCallback'})
as soon as the server trys to call the "MyGetCallbackCOnfig" Callback-function the follwing error orrures:

The Call:
events(c)
has the Result:

I think that the callback for the "GetCallbackConfig" is not defined the right way by me. But i Do not know how i have to define it.
댓글 수: 0
답변 (1개)
Meet
2025년 6월 19일
Hi Alexander,
The "GetCallbackConfig" callback needs to return the "[out] SAFEARRAY" expected by your COM interface, and use a column 1D array structure. You could try the below code snippet:
% Enable single-dimensional SAFEARRAY export once at startup:
feature('COM_SafeArraySingleDim', 1);
function configs = MyGetCallbackConfig(~, ~)
% Construct a struct array matching s_CallbackConfig_t
configs(1).FieldA = 123;
configs(1).FieldB = 'Example';
end
For more information on handling COM Data in MATLAB, you could refer to the below MathWorks Documentation:
참고 항목
카테고리
Help Center 및 File Exchange에서 COM Component Integration에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!