[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.interop

trouble getting ref object parameters while calling COM object with C#

rocketfire97

10/29/2007 1:37:00 AM

I'm trying to call a COM object using C# but having no luck getting
values back for passed in ref objects.

I've tried the same call using VB.NET and can get data back. How would
I implement the following in C#

This is the method I am calling, which populates ref paramters with
results.

Sub Check_Customer(ByVal Customer As String, Optional ByRef oParam1 As
Object = Nothing, Optional ByRef oParam2 As Object = Nothing, Optional
ByRef oParam3 As Object = Nothing, Optional ByRef oParam4 As Object =
Nothing, Optional ByRef Return As Object = Nothing)

Here is the VB.net code, which calls the function passing

Dim customer = "123456", oParam1 = Nothing, oParam2 = Nothing, oParam3
= Nothing, oParam4 = Nothing, oReturnBlock = Nothing

comObject.Check_Customer(customer, oParam1, oParam2, oParam3, oParam4,
oReturnBlock)

Dim myDA As System.Data.OleDb.OleDbDataAdapter = New
System.Data.OleDb.OleDbDataAdapter
Dim myDS1 As DataSet = New DataSet
Dim myDS2 As DataSet = New DataSet
myDA.Fill(myDS1, oParam1, "CustomerDetails")
myDA.Fill(myDS2, oParam2, "CustomerNotes")


Any help would be greatly appreciated.

2 Answers

Som Nath Shukla

10/29/2007 5:38:00 AM

0

string a=null,b=null;
aaaa(ref a, ref b);
u should use ref key world when passing parrameter to com function and
assing null before passing it.



"rocketfire97@gmail.com" wrote:

> I'm trying to call a COM object using C# but having no luck getting
> values back for passed in ref objects.
>
> I've tried the same call using VB.NET and can get data back. How would
> I implement the following in C#
>
> This is the method I am calling, which populates ref paramters with
> results.
>
> Sub Check_Customer(ByVal Customer As String, Optional ByRef oParam1 As
> Object = Nothing, Optional ByRef oParam2 As Object = Nothing, Optional
> ByRef oParam3 As Object = Nothing, Optional ByRef oParam4 As Object =
> Nothing, Optional ByRef Return As Object = Nothing)
>
> Here is the VB.net code, which calls the function passing
>
> Dim customer = "123456", oParam1 = Nothing, oParam2 = Nothing, oParam3
> = Nothing, oParam4 = Nothing, oReturnBlock = Nothing
>
> comObject.Check_Customer(customer, oParam1, oParam2, oParam3, oParam4,
> oReturnBlock)
>
> Dim myDA As System.Data.OleDb.OleDbDataAdapter = New
> System.Data.OleDb.OleDbDataAdapter
> Dim myDS1 As DataSet = New DataSet
> Dim myDS2 As DataSet = New DataSet
> myDA.Fill(myDS1, oParam1, "CustomerDetails")
> myDA.Fill(myDS2, oParam2, "CustomerNotes")
>
>
> Any help would be greatly appreciated.
>
>

rocketfire97

10/29/2007 6:21:00 PM

0

On Oct 29, 1:38 am, Som Nath Shukla
<SomNathShu...@discussions.microsoft.com> wrote:
> string a=null,b=null;
> aaaa(ref a, ref b);
> u should use ref key world when passing parrameter to com function and
> assing null before passing it.
>
> "rocketfir...@gmail.com" wrote:
> > I'm trying to call a COM object using C# but having no luck getting
> > values back for passed in ref objects.
>
> > I've tried the same call using VB.NET and can get data back. How would
> > I implement the following in C#
>
> > This is the method I am calling, which populates ref paramters with
> > results.
>
> > Sub Check_Customer(ByVal Customer As String, Optional ByRef oParam1 As
> > Object = Nothing, Optional ByRef oParam2 As Object = Nothing, Optional
> > ByRef oParam3 As Object = Nothing, Optional ByRef oParam4 As Object =
> > Nothing, Optional ByRef Return As Object = Nothing)
>
> > Here is the VB.net code, which calls the function passing
>
> > Dim customer = "123456", oParam1 = Nothing, oParam2 = Nothing, oParam3
> > = Nothing, oParam4 = Nothing, oReturnBlock = Nothing
>
> > comObject.Check_Customer(customer, oParam1, oParam2, oParam3, oParam4,
> > oReturnBlock)
>
> > Dim myDA As System.Data.OleDb.OleDbDataAdapter = New
> > System.Data.OleDb.OleDbDataAdapter
> > Dim myDS1 As DataSet = New DataSet
> > Dim myDS2 As DataSet = New DataSet
> > myDA.Fill(myDS1, oParam1, "CustomerDetails")
> > myDA.Fill(myDS2, oParam2, "CustomerNotes")
>
> > Any help would be greatly appreciated.

There is no problem getting string values passed by reference, the
problem is with parameters of type Object passed by reference. The COM
component returns recordsets in the ref objects and vb.net handles
this automatically so values can be accessed eg. oParam1("Name") after
the call contains data or even filling a dataset. However with C# I
can't get to the data within the Object.

I have tried the InvokeMember call using the BindingFlags.GetProperty
and BindingFlags.GetField but still unable to get the recordset.