Com-Callback for pointer to SafeArray

4 vues (au cours des 30 derniers jours)
Alexander
Alexander le 16 Juin 2025
Modifié(e) : Alexander le 21 Juin 2025
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.

Réponses (1)

Meet
Meet le 19 Juin 2025
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 commentaire
Alexander
Alexander le 21 Juin 2025
Modifié(e) : Alexander le 21 Juin 2025
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

Connectez-vous pour commenter.

Catégories

En savoir plus sur COM Component Integration dans Help Center et File Exchange

Produits


Version

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by