Hi All,
I’m currently doing some POC testing for a new client for one of their existing applications, with the hopes of being able to migrate a lot of their existing code embedded in Excel VBA to .net C# classes. At the moment I am working at the simplest level (not getting in to Add-ins just yet) from a COM point of view. Up until now I have had no problems translating some of the tamer functions that they currently have in VBA, however (there is always one), the last method I have been “transposing” accepted a ParamArray as one of the arguments to the method and innocently I assumed that the params keyword in C# would suffice… Several hours of trying different ways of getting the function to work as expected revealed that the ParamArray in VB (or VBA) is actually passed by reference. I found this out by creating a similar COM dll in VB6 and exposing the exact same function as was represented in VBA (and its translation in C#) By looking at the IDL from both the C# dll and the VB6 dll we find the following:
C# dll:
HRESULT CallProcedure(
[in] BSTR Procedure,
[in] SAFEARRAY(VARIANT) AllArguments,
[out, retval] VARIANT* pRetVal);
VB6 dll:
HRESULT CallProcedure(
[in, out] BSTR* Procedure,
[in, out] SAFEARRAY(VARIANT)* AllArguments,
[out, retval] VARIANT* );
As can be seen, the VB6 dll treats the ParamArray as an In/Out parameter – i.e. passing by reference and the C# dll treats the params (System.ParamArrayAttribute) as an In parameter i.e. passing by value. Failed attempts at declaring the interface as follows:
object CallProcedure(string Procedure, ref params object[] AllArguments);
This has left me stranded up the feces clogged estuary without a manual propulsion device… Can someone please help me, quick!
Kind regards,
James Phillips
************************************************** ********************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...