ParamArray and COM Interop 
Author Message
 ParamArray and COM Interop

Hi all,
    How can I make a function accept ParamArray parameter into it's
signature when COM Interop is enabled?

I have a VB.NET class that is built with COM interop but I am unable to use
a ParamArray parameter into this class.  The class is called from an ASP 3.0
page and I receive this error everytime I execute it:

--
Microsoft VBScript runtime error '800a01c2'
Wrong number of arguments or invalid property assignment: 'processSql'
--

Here is my function's signature:
Public Function ProcessSql(ByVal Procedure As String, ByVal ParamArray
sParams() As Object) As String

Thanks for your help,
--
Sylvain Audet - MCP+SB
Visitez les astuces .NET sur dotNET-fr.org
http://www.*-*-*.com/



Sun, 13 Nov 2005 01:39:41 GMT  
 ParamArray and COM Interop
Hi Sylvain,

This issue is documented in the following knowledge base article. This article
describes this same issue for VB6 and I am guessing it will apply to VB Script
too. Try changing ByVal to ByRef for ParamArray and recompile.

327084 BUG: COM Interop: Visual Basic 6 Cannot Use .NET Methods with ParamArray
http://support.microsoft.com/?id=327084

Let me know if this works or not.

Hope this helps!
Bharat Patel
Microsoft, Visual Basic .NET

This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only. Thanks.              



Sun, 13 Nov 2005 05:08:28 GMT  
 ParamArray and COM Interop
Hi Bharat,
    I am unable to find your article into the KB.  Is the path, alright?

I receive : "The article you are looking for is currently not available."

Thanks,
--
Sylvain Audet - MCP+SB
Visitez les astuces .NET sur dotNET-fr.org
http://www.dotnet-fr.org/sections.php3?op=listarticles&secid=6


Quote:
> Hi Sylvain,

> This issue is documented in the following knowledge base article. This
article
> describes this same issue for VB6 and I am guessing it will apply to VB
Script
> too. Try changing ByVal to ByRef for ParamArray and recompile.

> 327084 BUG: COM Interop: Visual Basic 6 Cannot Use .NET Methods with
ParamArray
> http://support.microsoft.com/?id=327084

> Let me know if this works or not.

> Hope this helps!
> Bharat Patel
> Microsoft, Visual Basic .NET

> This posting is provided "AS IS" with no warranties, and confers no
rights.
> Please reply to newsgroups only. Thanks.



Sun, 13 Nov 2005 20:55:47 GMT  
 ParamArray and COM Interop
Hi Sylvain,

I am sorry, I just noticed that this article is in Process and hasn't been
published yet. It should be available soon after the review process is
complete. I will send you the text via email as I do not want to post the
unfinished article text here.

Hope this helps!
Bharat Patel
Microsoft, Visual Basic .NET

This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only. Thanks.              



Sun, 13 Nov 2005 22:26:03 GMT  
 ParamArray and COM Interop
Thanks Bharat!
    I tried this solution but it is not what I am looking for.  We have a
lot of code already written in ASP 3.0 that calls our function (with the
paramarray) and we do not plan to pass everywhere to add code to assign
values first then call the function.

In the meantime, I developed a work around by declaring 60 parameters which
I then add to an array and loop through it to build my sql string.
Everytime I add a parameter to my string, I evaluate if there are remaining
parameters.  I have included a snippet of my code below for your
convenience.

----
Public Function ProcessSql1(ByVal Procedure As String, _
Optional ByVal sParam1 As Object = Nothing, _
Optional ByVal sParam2 As Object = Nothing, _
...
Optional ByVal sParam60 As Object = Nothing) as Adodb.RecordSet

...

Dim allParams() As Object = {sParam1, sParam2, sParam3, sParam4, sParam5,
..., sParam55, sParam56, sParam57, sParam58, sParam59, sParam60}

...

sSql = Procedure & " '" & sLanguage & "','" & sWhoIam & "'," & Str(iSession)

Dim i As Integer = 0

While Not noMoreParams(i, allParams)
    buildSQLString(allParams.GetValue(i), sSql)
    i += 1
End While

Function noMoreParams(ByVal iIndex As Integer, ByRef allParams() As Object)
As Boolean

    For i As Integer = iIndex To UBound(allParams)
        If allParams(i) Is Nothing Then
            'Find if at least one more parameter exists in the list of
parameters passed to the calling function
            For j As Integer = i + 1 To UBound(allParams)
                'Verify if all remaining parameters are empty
                If Not allParams(j) Is Nothing Then Return False
            Next
            Return True
        Else
            Return False
        End If
    Next

    Return False

End Function

----

Although this is not good programming practice to pass parameters this way,
in this case this will do the trick as we are planning to get rid if this
object within a year or two anyway.

Let me know if you have any other solution.

Thanks again,

--
Sylvain Audet - MCP+SB
Visitez les astuces .NET sur dotNET-fr.org
http://www.dotnet-fr.org/sections.php3?op=listarticles&secid=6



Quote:
> Hi Sylvain,

> I am sorry, I just noticed that this article is in Process and hasn't been
> published yet. It should be available soon after the review process is
> complete. I will send you the text via email as I do not want to post the
> unfinished article text here.

> Hope this helps!
> Bharat Patel
> Microsoft, Visual Basic .NET

> This posting is provided "AS IS" with no warranties, and confers no
rights.
> Please reply to newsgroups only. Thanks.



Sun, 13 Nov 2005 23:17:48 GMT  
 ParamArray and COM Interop
Hi Sylvain,

Have you tried changing ParaArray pameter in your function prototype to ByRef?
The article I sent you addresses this issue in one line and you may have missed
it. The workaround provided in the article is for Property Procedures as they
do not accept ByRef arguments. For methods and Functions, you need to change
only the ByVal to ByRef for the ParamArray Type argument. Try it out and see if
it works without changing anything in your existing ASP code.

Hope this helps!
Bharat Patel
Microsoft, Visual Basic .NET

This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only. Thanks.              



Mon, 14 Nov 2005 05:53:32 GMT  
 ParamArray and COM Interop
Hi Sylvain,

I am just checking to find out if changing the ByVal to ByRef resolved your
issue or not. Can you verify it?

Hope this helps!
Bharat Patel
Microsoft, Visual Basic .NET

This posting is provided "AS IS" with no warranties, and confers no rights.
Please reply to newsgroups only. Thanks.              



Sat, 19 Nov 2005 04:13:32 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Automation error referencing .net dll from com (com interop)

2. COM Interop question

3. Strong named COM Interop

4. COM / .NET interop

5. COM Interop

6. VB.NET COM Interop -vs- VB6 ---- The Turtle And The Hare

7. .Net browser control wrapper...will there be one?, com interop is crap

8. Com interop problem with Framework 1.1

9. COM interop registration failure

10. .NET to COM Interop with VSS - Deployment Question

11. COM interop...

12. .net interop with COM

 

 
Powered by phpBB® Forum Software