Com-Callback for pointer to SafeArray

조회 수: 4 (최근 30일)
Alexander
Alexander 2025년 6월 16일
편집: Alexander 2025년 6월 21일
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.

답변 (1개)

Meet
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:
  댓글 수: 1
Alexander
Alexander 2025년 6월 21일
편집: Alexander 2025년 6월 21일
Hi Meet,
thx 4 the feedback.
Based on your advice, I tried a few things with the COM parameters in the IDL. Primarily [out,retval]. The goal was to get a signature for Matlab according to your definition:
function configs = MyGetCallbackConfig(~, ~)
But unfortunately, that didn't work.
Nevertheless, I've made a step forward. The main mistake I made is almost embarrassing =) and I should have noticed it much earlier. (Copy-pasted code from an older project and a bug I had actually fixed long ago slipped back in.) Namely, the callbacks in Matlab for COM only need to be passed via the function name:
registerevent(c,{'GetCallbackConfig' 'MyGetCallbackConfig'; 'TicksCallback' 'MyTicksCallback'})
In a further step, I first put a primitive type into the SafeArray, because MATLAB states in its documentation that COM structures are not supported. (I'll evaluate this later, though.)
// 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(unsigned int) * );
[id(2)] HRESULT TicksCallback([in] SAFEARRAY(s_FxcmOffers_t) );
};
Through internal debugging I came up with the following function signature for the Matlab callback:
function [a,b]=MyGetCallbackConfig ( x1,x2,x3,x4,x5 )
This call works at first and then corresponds to the Matlab documentation. However, an example of the definition of the callback for COM connection points would have been really helpful. This isn't documented anywhere. It simply introduces normal COM calls and how to obtain their signatures. However, the same principle doesn't work for COM connection points.
Greetings,
Alex

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

카테고리

Help CenterFile Exchange에서 COM Component Integration에 대해 자세히 알아보기

제품


릴리스

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by