PDA

Click to See Complete Forum and Search --> : Too many parameters in a function?


dvoeller
Nov 28th, 2000, 11:03 AM
I have a C++ COM DLL Server and a VB client.
The VB client tries to access a method in an interface
implemented in the DLL Server but as best I can tell it
will not work because the method has more than 1 parameter.

Any ideas?

Partial VB listing


'C++ COM DLL Server
Dim WithEvents AcqMgr As HunterAcqMgrLib.HComSensorAcqMgr

Private Sub Form_Load()
Dim iResult As Integer
Set AcqMgr = New HComSensorAcqMgr

Dim s As HESamExecuteFreq
' Intellisense brings up possible selections
s = KSamExecRepeat6Hz

Dim t As HESamSeqType
' Intellisense brings up possible selections
t = KSamSeqTypeAlign

Dim u As HESamMode
' Intellisense brings up possible selections
u = KSamModeAlignSummary

' If I change AddMessageToQ in the C++ COM DLL Server so
' that it only takes 1 parameter, it will compile. Any
' method that takes more than 1 parameter does not work.

'Does not work
AcqMgr.AddMessageToQ(KSamSeqTypeAlign,KSamExecRepeat6Hz,bActive,KSamModeAlignSummary)
'Does not work
AcqMgr.AddMessageToQ(t,s,False,u)
'Does not work
AcqMgr.AddMessageToQ(0, 4, False, 1)
'Works
AcqMgr.ChangeSamMode (KSamModeIdle)

End Sub







The C++ idl looks like

[
object,
uuid(2C22FAE4-2C04-11D4-AD0E-00C04F8DD0AC),
dual,
pointer_default (Unique)
]
interface IHComSensorAcqMgr: IDispatch
{
.
.
.
HRESULT ChangeSamMode(
[in] HESamMode eMode);

HRESULT AddMessageToQ(
[in] HESamSeqType eSeqType,
[in] HESamExecuteFreq eFreq,
[in] VARIANT_BOOL vbActive,
[in] HESamMode eMode
);
.
.
.
}

tumblingdown
Nov 28th, 2000, 12:20 PM
Your idl is fine, and it makes no difference on a com call how many args it has ;-)

What makes you say it's failing because of that?


td.

tumblingdown
Nov 28th, 2000, 12:27 PM
According to your theory

AcqMgr.ChangeSamMode u

should work. Does it?


td.

dvoeller
Nov 28th, 2000, 01:34 PM
ChangeSamMode method does work.

If I change the number of arguments the AddMessageToQ method uses from 4 to 1, it also will work.

When the AddMessageToQ has 4 arguments, I get a syntax error.

tumblingdown
Nov 28th, 2000, 03:07 PM
but what is the syntax error?


td.

dvoeller
Nov 28th, 2000, 03:07 PM
My biggest thank you goes to Roger Butler from Anderson BDG who knew the answer immediately. His response was:



My initial examination of the syntax indicates that you should remove all parentheses as in:

AcqMgr.AddMessageToQ
KSamSeqTypeAlign,KSamExecRepeat6Hz,bActive,KSamModeAlignSummary

Parameters lists in VB only contain parentheses when a function returns a value as in :
retVal = AcqMgr.AddMessageToQ
(KSamSeqTypeAlign,KSamExecRepeat6Hz,bActive,KSamModeAlignSummary)

VB makes a distinction between void retVal functions (it calls them Subroutines) and retVal functions (it calls them Functions). Hence,
retval = MyCode (A,B,C) and MyCode A,B,C is the correct syntax depending on a retVal or not.

If you have become acustom to using parentheses to surround your parameter lists you can use the VB verb CALL as in:
CALL AcqMgr.AddMessageToQ
(KSamSeqTypeAlign,KSamExecRepeat6Hz,bActive,KSamModeAlignSummary)

Placing the verb CALL in front informs the VB compiler that you KNOW it's a Subroutine but you like to use parentheses and treat it as a Void Function.

This is not a standard practice. Go figure.

Hope this helps.

tumblingdown
Nov 29th, 2000, 01:35 AM
nice.


td.