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!