How to pass ByRef parameter to COM dll interface ?

P

pecker

I have a com dll interface:
Public Function Hulian_Acount_all(ByVal vIndex As Variant, _
ByRef vDate As Variant, _
ByRef vCount As Variant, _
ByRef vMoney As Variant, _
ByRef vMyDetail As Variant, _
ByVal vTimeStamp As Variant, _
ByVal vSPID As Variant, _
ByVal vType As Variant, _
ByVal vResult As Variant, _
ByVal vSenderID As Variant, _
ByVal vYourCount As Variant, _
ByVal vYourMoney As Variant, _
ByVal vDetail_result As Variant, _
ByVal vSucess_count As Variant, _
ByVal vSucess_money As Variant, _
ByVal vFail_count As Variant, _
ByVal vFail_money As Variant, _
ByVal vYour_records As Variant)
I use it in C# like this:
obj.Hulian_Acount_all
(3,"","","","",TimeStamp,"","",Result,SenderID,TotalCount,TotalFee,"","","",
"","","") ;

But the compiler shows out the error: "cannot convert the string to ref
object"

How can I pass the 2 ~ 5 ByRef parameters to the dll in C# ? Thanks a lot!
 
N

Nicholas Paldino [.NET/C# MVP]

pecker,

Because they are declared as variants, you have to store your values as
type object first, and then pass them by ref. You will have to do this:

// The values. <value> are the values you want to pass.
object vDate = <value>, vCount = <value>, vMoney = <value>, vMyDetail =
<value>;

// Call the method.
myObject.Hulian_Acount_all(vIndex, ref vDate, ref vCount, ref vMoney, ref
vMyDetail, vTimeStamp, vSPID, vType, vResult, vSenderID, vYourcount,
vYourMoney, vDetail_result, vSucess_count, vSucess_money, vFail_count,
vFail_money, vYour_records);

Hope this helps.
 
P

pecker

Thank you very much! I've resolved the problem with your help!

Nicholas Paldino said:
pecker,

Because they are declared as variants, you have to store your values as
type object first, and then pass them by ref. You will have to do this:

// The values. <value> are the values you want to pass.
object vDate = <value>, vCount = <value>, vMoney = <value>, vMyDetail =
<value>;

// Call the method.
myObject.Hulian_Acount_all(vIndex, ref vDate, ref vCount, ref vMoney, ref
vMyDetail, vTimeStamp, vSPID, vType, vResult, vSenderID, vYourcount,
vYourMoney, vDetail_result, vSucess_count, vSucess_money, vFail_count,
vFail_money, vYour_records);

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

pecker said:
I have a com dll interface:
Public Function Hulian_Acount_all(ByVal vIndex As Variant, _
ByRef vDate As Variant, _
ByRef vCount As Variant, _
ByRef vMoney As Variant, _
ByRef vMyDetail As Variant, _
ByVal vTimeStamp As Variant, _
ByVal vSPID As Variant, _
ByVal vType As Variant, _
ByVal vResult As Variant, _
ByVal vSenderID As Variant, _
ByVal vYourCount As Variant, _
ByVal vYourMoney As Variant, _
ByVal vDetail_result As Variant, _
ByVal vSucess_count As Variant, _
ByVal vSucess_money As Variant, _
ByVal vFail_count As Variant, _
ByVal vFail_money As Variant, _
ByVal vYour_records As Variant)
I use it in C# like this:
obj.Hulian_Acount_all
(3,"","","","",TimeStamp,"","",Result,SenderID,TotalCount,TotalFee,"","","",
"","","") ;

But the compiler shows out the error: "cannot convert the string to ref
object"

How can I pass the 2 ~ 5 ByRef parameters to the dll in C# ? Thanks a lot!
 
Top