Late binding with c#

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John Clennett

    #1

    Late binding with c#

    I'm trying to write a c# command line app that runs report dll's at set
    times. The dll's are written in c# with a common interface so by passing the
    object name from the command line I can create ao instance ot the object &
    create the report.

    In VB I used code like:
    Set obj = CreateObject(ob jName)
    Call obj.Init(databa seName, fromDate, toDate)

    I've tried the c# code:
    System.Type oType = System.Type.Get TypeFromProgID( "rptName.Init") ;
    object obj = System.Activato r.CreateInstanc e(oType);
    oType.InvokeMem ber("createRepo rt",
    System.Reflecti on.BindingFlags .InvokeMethod, null,0, new object[]{})
    obj.createRepor t(dbName,fromDa te,toDate);

    but so far not been able to get it to work.

    I'm sure I'm just missing something silly but at present can't see it, Maybe
    because it's Friday!!!

    Any help/advise would be welcome.

    Thanks,
    John


  • David Anton

    #2
    RE: Late binding with c#

    objType.InvokeM ember("Init", System.Reflecti on.BindingFlags .InvokeMethod,
    null, obj, new object[] {databaseName, fromDate, toDate});

    You were passing '0' instead of 'obj'.
    --
    David Anton
    Source code converters: Convert between C#, C++, Java, and VB with the most accurate and reliable source code converters

    Instant C#: VB to C# converter
    Instant VB: C# to VB converter
    Instant C++: C# to C++ converter
    Instant C++: VB to C++ converter


    "John Clennett" wrote:
    [color=blue]
    > I'm trying to write a c# command line app that runs report dll's at set
    > times. The dll's are written in c# with a common interface so by passing the
    > object name from the command line I can create ao instance ot the object &
    > create the report.
    >
    > In VB I used code like:
    > Set obj = CreateObject(ob jName)
    > Call obj.Init(databa seName, fromDate, toDate)
    >
    > I've tried the c# code:
    > System.Type oType = System.Type.Get TypeFromProgID( "rptName.Init") ;
    > object obj = System.Activato r.CreateInstanc e(oType);
    > oType.InvokeMem ber("createRepo rt",
    > System.Reflecti on.BindingFlags .InvokeMethod, null,0, new object[]{})
    > obj.createRepor t(dbName,fromDa te,toDate);
    >
    > but so far not been able to get it to work.
    >
    > I'm sure I'm just missing something silly but at present can't see it, Maybe
    > because it's Friday!!!
    >
    > Any help/advise would be welcome.
    >
    > Thanks,
    > John
    >
    >[/color]

    Comment

    • John Clennett

      #3
      RE: Late binding with c#

      What I'm getting at present is the Type is not being created.
      After the following line is executed the Type is still <undefined value>
      System.Type oType = System.Type.Get TypeFromProgID( "rptName.Init") ;

      Documentation on GetTypeFromProg ID states that it's for compatability with
      COM objects & that it's superceded with namespaces in .NET. As the dll's are
      written in c# do I have to use another method to late bind?

      Thanks for the help,
      John

      "David Anton" wrote:
      objType.InvokeM ember("Init", System.Reflecti on.BindingFlags .InvokeMethod,
      null, obj, new object[] {databaseName, fromDate, toDate});
      >
      You were passing '0' instead of 'obj'.
      --
      David Anton
      Source code converters: Convert between C#, C++, Java, and VB with the most accurate and reliable source code converters

      Instant C#: VB to C# converter
      Instant VB: C# to VB converter
      Instant C++: C# to C++ converter
      Instant C++: VB to C++ converter
      >
      >
      "John Clennett" wrote:
      >
      I'm trying to write a c# command line app that runs report dll's at set
      times. The dll's are written in c# with a common interface so by passing the
      object name from the command line I can create ao instance ot the object &
      create the report.

      In VB I used code like:
      Set obj = CreateObject(ob jName)
      Call obj.Init(databa seName, fromDate, toDate)

      I've tried the c# code:
      System.Type oType = System.Type.Get TypeFromProgID( "rptName.Init") ;
      object obj = System.Activato r.CreateInstanc e(oType);
      oType.InvokeMem ber("createRepo rt",
      System.Reflecti on.BindingFlags .InvokeMethod, null,0, new object[]{})
      obj.createRepor t(dbName,fromDa te,toDate);

      but so far not been able to get it to work.

      I'm sure I'm just missing something silly but at present can't see it, Maybe
      because it's Friday!!!

      Any help/advise would be welcome.

      Thanks,
      John

      Comment

      Working...