473,796 Members | 2,707 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with event declaration - possible VS.NET bug?

Hello,

I made a post relating to this issue a while
back, but I haven't received any answer, so
here I am again.

I am writing a mixed C++ dll which uses the following
declaration:

typedef System::Byte ByteArray __gc[];

Then I have an event declared in the main class
for the dll as follows:

__event void MyEvent(ByteArr ay* ba);

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.

My suspicions are that when you have __event
declarations for events that take pointers to
managed arrays, these expand to code which has
a syntax error. I tried this for a pointer to
an array of Strings and I was getting the same
kind of errors.

Also, when I modified the event declaration to

__event void MyEvent(ByteArr ay ba);

the errors went away.

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?

TIA,

--
Akin

aknak at aksoto dot idps dot co dot uk



Nov 17 '05 #1
3 1778
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_cas t, 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(ByteArr ay 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<Sys tem::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.

--
Brandon Bray, Visual C++ Compiler http://blogs.msdn.com/branbray/
Bugs? Suggestions? Feedback? http://msdn.microsoft.com/productfeedback/
Nov 17 '05 #2

"Brandon Bray [MSFT]" <br******@onlin e.microsoft.com > wrote in message
news:O3******** ******@TK2MSFTN GP09.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_cas t, 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(ByteArr ay 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<Sys tem::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<Sys tem::Byte>^* ba);

TIA for any answers.

--
Akin

aknak at aksoto dot idps dot co dot uk
Nov 17 '05 #3
Wild Wind wrote:
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?
That's right. The array syntax is somewhat confusing in this manner. For all
other managed types, the * is required. So, you'll always see a
System::String as 'System::String *'. __gc arrays are really just a pointer
to a garbage collected array -- the syntax just obscures that fact slightly.

A quick way to observe that arrays are actually just __gc pointers being
passed around is to note the conversions between System::Object* . For
example:

Object* F(Object* o) { return o; }

int main() {
int arr1 __gc[] = { 0, 1, 2 };
int arr2 __gc[] = (int __gc[])F(arr1);
}
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<Sys tem::Byte>^* ba);


That is a native pointer to a handle. In the new Whidbey syntax, a * always
means '__nogc*' from the old syntax. The hat to the array is making it clear
that you're passing around a handle. That array declaration is how to
express in the new syntax what you were trying to do in the old syntax.

Cheerio!

--
Brandon Bray, Visual C++ Compiler http://blogs.msdn.com/branbray/
Bugs? Suggestions? Feedback? http://msdn.microsoft.com/productfeedback/
Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3414
by: Tomaz Rotovnik | last post by:
Hi I created very simple dll (vc++) which has three functions (start, stop and initialization). it starts capturing sound from soundblaster and when the buffer is filled with the data, dll calls VB calback function (passed with initialization) and passes the buffer size (integer type). First I have some problems with __stdcall declaration in VC dll, but I think I solved that problem. Callback function runs in separated thread under main...
36
3571
by: Simon Wigzell | last post by:
I have the following in my webpage: <body onresize=CenterIt(); onMouseMove=mouseCheck(event);> CenterIt and mouseCheck are my own javascript functions. Works fine for IE and Opera, doesn't even go into the function for Firefox or Netscape. Is there a different way to assign functions to events that will be understood by "all" browsers? Thanks!
2
1642
by: Alex Sheppard-Godwin | last post by:
In VS when your working on a VB code module for a web form you can see a list of object in the left hand drop down list above the code window and possible events in the right hand drop down list. In C# you only see the class name, so getting a code template for an event is more difficult. Is this just a difference between the two languages or is there something I'm missing? Cheers
2
13647
by: Eli Block | last post by:
When getting a type from a dynamically loaded assembly using Assembly.GetType, I receive the following exception: An unhandled exception of type 'System.TypeLoadException' occurred in playengine.dll Additional information: Method add_Closing in type PlayEngine.D3DVideoTask from assembly D3DVideoTask, Version=1.0.1632.5152, Culture=neutral, PublicKeyToken=null does not have an implementation.
0
1122
by: Alex Sedow | last post by:
Standart describe grammar for events as (in EBNF): event-declaration: "event" type variable-declarators ";" "event" type member-name "{" event-accessor-declarations "}" variable-declarators: variable-declarator variable-declarators "," variable-declarator
2
4990
by: Alex Sedow | last post by:
Why interface-event-declaration does not support multiple declarators like event-declaration? Grammar from C# spec: variable-declarators: variable-declarator variable-declarators "," variable-declarator variable-declarator:
7
2560
by: Fernando Barsoba | last post by:
Hi, After following the advice received in this list, I have isolated the memory leak problem I am having. I am also using MEMWATCH and I think it is working properly. The program does some calculations and stores elements in a list. After that, a sorting algorithm is used over that list. Two functions are called before the sorting process:
8
1613
by: Karsten Schramm | last post by:
Hi, when I run the following code: using System; namespace ConsoleApplication22 { class Program {
1
2926
by: stevedub | last post by:
I am having some trouble configuring my array to read from a sequential file, and then calling on that to fill an array of interests. I think I have the class set up to read the file, but when I run my program the rates array does not get the information. I think my problem is where I am actuall calling the array index, but I am not sure how to do this. Here is my code: /* * MortFrame.java * * Created on February 24, 2008, 7:28 PM */...
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10201
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9061
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7558
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6802
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5454
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5582
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4130
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2931
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.