interop

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

    #1

    interop

    I created a ocx that has a method,

    [id(5), helpstring("·½· ¨Test1")] void Test1(VARIANT* a);

    the implementation is
    void Cocx030820Ctrl: :Test1(VARIANT* a)
    {
    try
    {
    //see here
    AFX_MANAGE_STAT E(AfxGetStaticM oduleState());

    ST_PRINT* m;
    //get data
    m=(ST_PRINT*)a;
    CString s;
    s.Format("%d,%d ,%s,%c",m->i,m->l,m->s,m->mSTRU1.c);
    MessageBox(s);
    }
    catch(...)
    {
    MessageBox("f") ;
    }
    }

    and the ST_PRINT definition is

    #ifndef IOPRINT
    #define IOPRINT
    typedef struct
    {
    unsigned char a[11];
    unsigned char b[9];
    char c;
    }STRU1;

    typedef struct
    {
    unsigned char Tran[11];
    unsigned char TermId[9];
    STRU1 mSTRU1;
    char c;
    int i;
    long l;
    double d;
    char s[10];
    }ST_PRINT;

    #endif

    My question is how to call the Test1 method in C#
    //ST_PRINT
    object obj=new object();
    how can I set the field value of obj.
    axocx0308201.Te st1(ref b3);




    Thank you very much!


  • Mattias Sjögren

    #2
    Re: interop

    [color=blue]
    >the implementation is
    >void Cocx030820Ctrl: :Test1(VARIANT* a)
    >{
    > try
    > {
    > //see here
    > AFX_MANAGE_STAT E(AfxGetStaticM oduleState());
    >
    > ST_PRINT* m;
    > //get data
    > m=(ST_PRINT*)a;[/color]

    These kinds of hacks might work in C++, but not in C#. Why do you make
    the parameter type a VARIANT* when it really isn't?



    Mattias

    --
    Mattias Sjögren [MVP] mattias @ mvps.org

    Please reply only to the newsgroup.

    Comment

    • ZhangZQ

      #3
      Re: interop

      Dear Mattias,

      It is necessary, because that OCX is the third party product, I have to use
      it but can not change it, is it possible to do that?

      Thank you very much!


      ZhangZQ


      "Mattias Sjögren" <mattias.dont.w ant.spam@mvps.o rg> wrote in message
      news:eZShNpkoDH A.688@TK2MSFTNG P10.phx.gbl...[color=blue]
      >[color=green]
      > >the implementation is
      > >void Cocx030820Ctrl: :Test1(VARIANT* a)
      > >{
      > > try
      > > {
      > > //see here
      > > AFX_MANAGE_STAT E(AfxGetStaticM oduleState());
      > >
      > > ST_PRINT* m;
      > > //get data
      > > m=(ST_PRINT*)a;[/color]
      >
      > These kinds of hacks might work in C++, but not in C#. Why do you make
      > the parameter type a VARIANT* when it really isn't?
      >
      >
      >
      > Mattias
      >
      > --
      > Mattias Sjögren [MVP] mattias @ mvps.org
      > http://www.msjogren.net/dotnet/
      > Please reply only to the newsgroup.[/color]


      Comment

      • Mattias Sjögren

        #4
        Re: interop

        [color=blue]
        >It is necessary, because that OCX is the third party product, I have to use
        >it but can not change it, is it possible to do that?[/color]

        Only if you change the managed definition of the method to take an
        IntPtr or a ST_PRINT& parameter instead.



        Mattias

        --
        Mattias Sjögren [MVP] mattias @ mvps.org

        Please reply only to the newsgroup.

        Comment

        Working...