Passing a ref to a SafeArray to c# .net component from MFC
I have a .Net component that passes a stringArray to a client program via an out parameter.
This works fine from a .net client
and I have successfully passed a SafeArray from MFC to a .net component as an in parameter.
What seems to evade me is returning returning an array from a .net component via the CCW as an out parameter.
Can anyone help?
regards
Rob
Robert Magowan wrote: |
| I have a .Net component that passes a stringArray to a client program via an out parameter. This works fine from a .net client and I have successfully passed a SafeArray from MFC to a .net component as an in parameter. What seems to evade me is returning returning an array from a .net component via the CCW as an out parameter. Can anyone help? regards Rob |
|
Rob,
In order to do this, you would declare the parameter as a ref parameter, like this:
void DoSomething(ref string[] arr)
It will then allow you to pass a reference to a SAFEARRAY and have it populated on return.
Hope this helps.
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com
Thanks for the reply,
However, I am doing this already, and the tlb file generated from Tlbexe thus shows that the SafeArray
should be marshaled as an [In,Out] Parameter.The following definition is generated in the .tlh file of the MFC client program
for the function in question
virtual
HRESULT __stdcall raw_TranslateID_2 (
/*[in]*/ struct ID_TRANS_CTX xTransCtx,
/*[in]*/ SAFEARRAY * astrInputIdNames,
/*[in,out]*/ SAFEARRAY * * rastrOrigIdNames,
/*[in,out]*/ SAFEARRAY * * rastrTranslatedIdNames,
/*[out,retval]*/ long * pRetVal ) = 0;
where by I am successfully passing a pointer to a safearray in.but when I try to examine the results for the [OUT] safe arrays, all I get is garbage.
What am I doing wrong....