-- | @getMemberID memberName obj@ translates the @memberName@ string
-- into the unique 'DISPID' representing that method/property. If unknown,
-- a COM exception is raised.
getMemberID :: Member -> IDispatch a -> IO DISPID
getMemberID name obj = do 
   bstr        <- allocBSTR name
   (dispid,hr) <- dispatchGetMemberID (castIface obj) bstr lcidNeutral
                       `always` freeBSTR bstr
   checkHR hr  `catchComException` (handleErr hr)
   return dispid
 where
  handleErr hr err
    | hr == dISP_E_UNKNOWNNAME = coFail ("method '" ++ name ++ "' called but not supported by object")
    | otherwise               = errorMember name err

{-
Type definitions for the marshalling functions. Variants are represented
as functions that can read or write a value from or to a variant structure.
-}

-- | @VarIn@ is the marshaller for 'Variant' arguments; a function that
-- takes (a pointer to) a VARIANT structure and fills it in with value
-- it encodes.
getMemberID :: Member -> IDispatch a -> IO DISPID
getMemberID name obj = do 
   bstr        <- allocBSTR name
   (dispid,hr) <- dispatchGetMemberID (castIface obj) bstr lcidNeutral
                       `always` freeBSTR bstr
   checkHR hr  `catchComException` (handleErr hr)
   return dispid
 where
  handleErr hr err
    | hr == dISP_E_UNKNOWNNAME = coFail ("method '" ++ name ++ "' called but not supported by object")
    | otherwise               = errorMember name err

{-
Type definitions for the marshalling functions. Variants are represented
as functions that can read or write a value from or to a variant structure.
-}

-- | @VarIn@ is the marshaller for 'Variant' arguments; a function that
-- takes (a pointer to) a VARIANT structure and fills it in with value
-- it encodes.
getMemberID name obj = do 
   bstr        <- allocBSTR name
   (dispid,hr) <- dispatchGetMemberID (castIface obj) bstr lcidNeutral
                       `always` freeBSTR bstr
   checkHR hr  `catchComException` (handleErr hr)
   return dispid
 where
  handleErr hr err
    | hr == dISP_E_UNKNOWNNAME = coFail ("method '" ++ name ++ "' called but not supported by object")
    | otherwise               = errorMember name err

{-
Type definitions for the marshalling functions. Variants are represented
as functions that can read or write a value from or to a variant structure.
-}

-- | @VarIn@ is the marshaller for 'Variant' arguments; a function that
-- takes (a pointer to) a VARIANT structure and fills it in with value
-- it encodes.