Results 1 to 7 of 7

Thread: Too many parameters in a function?

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2000
    Posts
    3

    Unhappy

    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
    );
    .
    .
    .
    }

  2. #2
    Hyperactive Member tumblingdown's Avatar
    Join Date
    Mar 2000
    Posts
    362
    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.
    "One logical slip and an entire scientific edifice comes tumbling down." - Robert M. Pirsig


    [email protected]

    "but if Einstein is right and God is in the details, reality requires that we sometimes get religion." - Scott Meyers.

  3. #3
    Hyperactive Member tumblingdown's Avatar
    Join Date
    Mar 2000
    Posts
    362
    According to your theory

    AcqMgr.ChangeSamMode u

    should work. Does it?


    td.
    "One logical slip and an entire scientific edifice comes tumbling down." - Robert M. Pirsig


    [email protected]

    "but if Einstein is right and God is in the details, reality requires that we sometimes get religion." - Scott Meyers.

  4. #4

    Thread Starter
    New Member
    Join Date
    Nov 2000
    Posts
    3
    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.

  5. #5
    Hyperactive Member tumblingdown's Avatar
    Join Date
    Mar 2000
    Posts
    362
    but what is the syntax error?


    td.
    "One logical slip and an entire scientific edifice comes tumbling down." - Robert M. Pirsig


    [email protected]

    "but if Einstein is right and God is in the details, reality requires that we sometimes get religion." - Scott Meyers.

  6. #6

    Thread Starter
    New Member
    Join Date
    Nov 2000
    Posts
    3

    I have the answer

    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.

  7. #7
    Hyperactive Member tumblingdown's Avatar
    Join Date
    Mar 2000
    Posts
    362
    nice.


    td.
    "One logical slip and an entire scientific edifice comes tumbling down." - Robert M. Pirsig


    [email protected]

    "but if Einstein is right and God is in the details, reality requires that we sometimes get religion." - Scott Meyers.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width