virtual override

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

    #1

    virtual override

    Hi,

    In a mangaed C++ wrapper class, I have some pure virtual function
    declarations:

    public __gc __abstract class CESCSAPICommand
    {
    ......
    // Test only
    virtual bool Test(int i1, int i2) = 0;

    // SendPacket() takes address and size of a byte array buffer:
    virtual bool SendPacket(unsi gned char packetAddress __nogc[], int
    packetSize) = 0;
    .....
    }

    When trying to override these in a C# application, this works fine for a
    simple Test() method just using 2 intergers.
    However, I have no chance to override SendPacket()!

    My relevant C# code looks as follows:

    class CESCSMyAPIComma nd: CESCSAPICommand
    {
    .....
    public override bool Test(int i1, int i2) {...} // compiles
    and works fine, but....

    public override bool SendPacket(byte [] packetAddress , int
    packetSize)
    {
    .....
    socket.Send(pac ketAddress , 0, packetSize, 0);
    .....
    }

    // ... causes compiler error s:
    'ConsoleApplica tion1.CESCSMyAP ICommand' does not implement
    inherited abstract
    member 'CESCSAPIComman d.SendPacket(by te*, int)'

    'ConsoleApplica tion1.CESCSMyAP ICommand' .SendPacket(byt e[],
    int)': no suitable method found to override
    ....
    }

    What is wrong? In other words: how do I correclty declare my pure
    virtual function SendPacket(buff erAddress,buffe rSize) in managed C and
    override it in a C# application so that I cann pass the parameters to
    Socket:Send() ??

    Thanks in advance
    Urs

    PS: remove leading / trailing ns_, _ns from e-mail address

  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: virtual override

    Urs,

    I believe that you want something like this:

    virtual bool SendPacket(byte packetAddress __gc[], int packetSize) = 0;

    The __gc indicates that the array is a managed array.

    Hope this helps.


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "Urs Wigger" <ns_urs.wigger@ leica-geosystems_ns.c om> wrote in message
    news:e2HvDcmkDH A.1960@TK2MSFTN GP12.phx.gbl...[color=blue]
    > Hi,
    >
    > In a mangaed C++ wrapper class, I have some pure virtual function
    > declarations:
    >
    > public __gc __abstract class CESCSAPICommand
    > {
    > ......
    > // Test only
    > virtual bool Test(int i1, int i2) = 0;
    >
    > // SendPacket() takes address and size of a byte array buffer:
    > virtual bool SendPacket(unsi gned char packetAddress __nogc[], int
    > packetSize) = 0;
    > .....
    > }
    >
    > When trying to override these in a C# application, this works fine for a
    > simple Test() method just using 2 intergers.
    > However, I have no chance to override SendPacket()!
    >
    > My relevant C# code looks as follows:
    >
    > class CESCSMyAPIComma nd: CESCSAPICommand
    > {
    > .....
    > public override bool Test(int i1, int i2) {...} // compiles
    > and works fine, but....
    >
    > public override bool SendPacket(byte [] packetAddress , int
    > packetSize)
    > {
    > .....
    > socket.Send(pac ketAddress , 0, packetSize, 0);
    > .....
    > }
    >
    > // ... causes compiler error s:
    > 'ConsoleApplica tion1.CESCSMyAP ICommand' does not implement
    > inherited abstract
    > member 'CESCSAPIComman d.SendPacket(by te*, int)'
    >
    > 'ConsoleApplica tion1.CESCSMyAP ICommand' .SendPacket(byt e[],
    > int)': no suitable method found to override
    > ....
    > }
    >
    > What is wrong? In other words: how do I correclty declare my pure
    > virtual function SendPacket(buff erAddress,buffe rSize) in managed C and
    > override it in a C# application so that I cann pass the parameters to
    > Socket:Send() ??
    >
    > Thanks in advance
    > Urs
    >
    > PS: remove leading / trailing ns_, _ns from e-mail address
    >[/color]


    Comment

    Working...