How to use a DLL which has complex optional parameters

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • GaryHartland
    New Member
    • Jun 2010
    • 2

    How to use a DLL which has complex optional parameters

    Hello

    I'm trying to use this OLE DLL interface in a C# program:
    Code:
     [id(0x60030016), helpstring("Adds a new Data Value to the recordset"), helpcontext(0x00000c1d)]
    HRESULT Add(
                    [in, out] BSTR* Tagname, 
                    [in, out] DATE* TimeStamp, 
                    [in, out, optional, defaultvalue(<unprintable IDispatch*>)] _DataValue** InValue, 
                    [out, retval] _DataValue** );
    Here is the C# code

    Code:
    iHistorian_SDK.DataRecordset MyRecordsetD;
    MyRecordsetD = MyData.NewRecordset();
    iHistorian_SDK.DataValue MyValue;
    string TestTagD = "TestTag";
    DateTime TestDate = DateTime.Parse("6/10/2010 15:30");
    MyRecordsetD.Add(ref TestTagD, ref TestDate);
    The last line generates an error "No overload for method 'Add' takes '2' arguments"

    I've scoured the internet and have tried every filling in the 3rd parameteer with every permutation of System.Reflecti on.Missing.Valu e, [DllImport("")], etc, etc, imaginable.

    DataValue does not have a constructor. The only way to instantiate a DataValue is by using DataRecordset.A dd.

    Any ideas?
  • GaryTexmo
    Recognized Expert Top Contributor
    • Jul 2009
    • 1501

    #2
    I've never encountered this before, but two thoughts occur to me...

    1. What does intellisense say you get for overloads on the Add method?

    2. Have you tried calling with 3 parameters, but just passing null as the 3rd parameter? What about an IDispatch* object?

    I'm grasping at straws here, I don't know this system but I figured I'd make a comment in an attempt to be helpful. If anything, hopefully I'll jog your brain, or someone else will have some ideas.

    Comment

    • GaryHartland
      New Member
      • Jun 2010
      • 2

      #3
      Thanks for the reply Gary. I had tried every permutation I could think of, of 2 parameters, 3 parameters, dummy 3rd parameter, IDispatch* object, etc, etc. Finally did find the answer though. Apparently this was a shortcomming of C# as version 4 now supports optional parameters and defaults. So, the solution was simply to upgrade to Developer's studio 2010. (I had been using MSDS 2005). Thanks again for your reply.

      Gary

      Comment

      Working...