Re: Problem with event declaration - possible VS.NET bug?
From: Wild Wind (nobody_at_blackhole.com)
Date: 09/06/04
- Next message: Jon S.: "Re: Is there an API to format the HD?"
- Previous message: ZhangZQ: "Is there an API to format the HD?"
- In reply to: Brandon Bray [MSFT]: "Re: Problem with event declaration - possible VS.NET bug?"
- Next in thread: Brandon Bray [MSFT]: "Re: Problem with event declaration - possible VS.NET bug?"
- Reply: Brandon Bray [MSFT]: "Re: Problem with event declaration - possible VS.NET bug?"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 6 Sep 2004 10:13:51 +0100
"Brandon Bray [MSFT]" <branbray@online.microsoft.com> wrote in message
news:O3HE2#7kEHA.1712@TK2MSFTNGP09.phx.gbl...
> Wild Wind wrote:
> > The problem is that with this event declaration, when
> > I compile the code, I get the following errors:
> >
> > error C2059: syntax error : ')'
> > error C2143: syntax error : missing ')' before ';'
> > error C2629: unexpected 'unsigned char ('
> >
> > Each error is shown thrice.
>
> I was able to reproduce this. With the VC2005 40901 compiler, a different
> error message is shown:
>
> t.cpp(6) : error C2697: 'i1' : must explicitly specify __gc or __nogc for
an
> array declared in a managed type
> t.cpp(6) : error C2664: 'C::__Delegate_MyEvent::Invoke' : cannot convert
> parameter 1 from 'unsigned char (*)[1]' to 'unsigned char (*) __gc[]'
> Types pointed to are unrelated; conversion requires
> reinterpret_cast, C-style cast or function-style cast
>
> Both the VC2003 and VC2005 messages are wrong. There's nothing wrong with
> this code. I rewrote it without the typedef as follows:
>
> __event void MyEvent( System::Byte (__nogc*ba)__gc[]);
>
> > Also, when I modified the event declaration to
> >
> > __event void MyEvent(ByteArray ba);
> >
> > the errors went away.
>
> That is correct. The difference is the code without errors is only passing
a
> pointer to an array, whereas the code with errors is passing a __nogc
> pointer to a __gc pointer to an array. I'm guessing that two levels of
> indirection are probably not necessary, so the code without errors is
likely
> something you can use.
>
> > Is this an MS bug? Can anyone reproduce this?
> > If it is a problem, is there anyway I can still
> > declare the event I want to?
>
> I do believe this is a bug. You can file this at the link below, but it's
> not likely to be fixed. In the new syntax, you need to write the delegate
> declaration separately from the event. For example:
>
> delegate void MyDel(array<System::Byte>^* ba);
> event MyDel^ MyEvent;
>
> I don't see anyway to workaround the errors above if you really need to
pass
> a pointer to a pointer to the array. I think the best way is to consider a
> different approach.
>
> Sorry for the inconvenience.
Hello Brandon,
Thanks for your reply. I will file the bug at the link
you mention below. You are probably right about there
not being a need to have the event delegate taking as
an argument a pointer to an array of System::Byte -
I did that because in the documentation, it speaks of
arrays being objects that must be referenced (presumably
using a pointer).
Interestingly enough, you say
"The difference is the code without errors is only
passing a pointer to an array"
Is that right? When I declare a managed array of an object,
does this mean that in passing the array, I am implicitly
passing a pointer to the array? And does this also apply
for other managed types, like System::String?
One other question - I take it that the syntax changes
you mention are planned for Whidbey, and the caret (hat)
signifies a managed pointer to an object? What is the
significance the asterisk after the caret you have in
delegate void MyDel(array<System::Byte>^* ba);
TIA for any answers.
-- Akin aknak at aksoto dot idps dot co dot uk
- Next message: Jon S.: "Re: Is there an API to format the HD?"
- Previous message: ZhangZQ: "Is there an API to format the HD?"
- In reply to: Brandon Bray [MSFT]: "Re: Problem with event declaration - possible VS.NET bug?"
- Next in thread: Brandon Bray [MSFT]: "Re: Problem with event declaration - possible VS.NET bug?"
- Reply: Brandon Bray [MSFT]: "Re: Problem with event declaration - possible VS.NET bug?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|