473,320 Members | 1,978 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Pass arg by reference in C++ event?

Is it possible to pass an argument by reference through
an event in C++ managed code? For example, can I do the
following?

public __gc class MyClass : public Control
{
public:

__event void MyEvent(bool &Cancel);

};
The compiler seems happy with this, and it goes ahead and
creates a DLL fine and dandy.

However, when I reference this DLL from my VB.NET
project, and attempt to do this:

Public WithEvents MyObject as MyClass

It causes the development environment to pop up a dialog
box saying "The operation could not be completed" the
moment I press Enter after typing the above line.

If I attempt to compile or run the code, I get this
error: "Visual Basic .NET compiler is unable to recover
from the following error: System Error &Hc0000005&
(Visual Basic internal compiler error). Save your work
and restart Visual Studio .NET."

If I remove the reference (&) from the event declaration
in the C++ project, then the VB.NET project works fine
(except I need to pass that argument by reference for a
working solution). It took me two days, through trial
and error, to determine it was the argument-by-reference
in that one event that was causing this error.

I also attempted a sample VB.NET project that defines an
event, passing an argument ByRef. This time, I was able
to include that DLL wihtout any problems.

' This class, defined in VB.NET works fine
Public Class MyVBClass
Public Event MyVBEvent(ByRef Cancel As Boolean)
End Class
Any thoughts? Is this just a .NET Development studio
bug, or is it really impossible to pass an argument by
reference through an event in C++ managed code?

Microsoft Development Environment 2003, Version 7.1.3008
Microsoft .NET Framework 1.1, Version 1.1.4322

I can work around the problem (sigh), by creating another
class that holds the "Cancel" boolean argument inside
that class and pass that class as a (by val) argument
through the event, but I really don't want to kludge up
my code that way.
Jul 21 '05 #1
4 4518
__event void MyEvent(bool &Cancel);


bool __gc *Cancel

or

Boolean *Cancel

should work.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Jul 21 '05 #2
__event void MyEvent(bool &Cancel);


bool __gc *Cancel

or

Boolean *Cancel

should work.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Jul 21 '05 #3
Yes, that did it! THANK YOU!

-----Original Message-----
__event void MyEvent(bool &Cancel);


bool __gc *Cancel

or

Boolean *Cancel

should work.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
.

Jul 21 '05 #4
Yes, that did it! THANK YOU!

-----Original Message-----
__event void MyEvent(bool &Cancel);


bool __gc *Cancel

or

Boolean *Cancel

should work.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
.

Jul 21 '05 #5

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

Similar topics

2
by: Sean Dockery | last post by:
Which is the following is correct? a) <form ... onSubmit="return checkData()"> b) <form ... onSubmit="return checkData();"> c) <form ... onSubmit="checkData()"> d) <form ......
5
by: deko | last post by:
I'd like to use a bit of code in the OnOpen event of a report: =rptOpen(Me.ReportName), (Me.Tag) --this doesn't work This does work: Private Sub Report_Open(Cancel As Integer)...
9
by: Frank Rizzo | last post by:
I've got a number of user controls on the web page. How can I pass some data to it? I don't see where the user control is instantiated in the page code-behind page. Thanks.
7
by: John | last post by:
Hi I open a word document from my vb.net app. Now I want to pass reference to one of the classes in my vb.net app to word so it can access procedures in the vb.net class. How can I pass the...
2
by: Todd | last post by:
Is it possible to pass an argument by reference through an event in C++ managed code? For example, can I do the following? public __gc class MyClass : public Control { public: __event...
3
by: sloan | last post by:
How does one "pass thru" a Raised Event.... I am using the Adapter Pattern to sync up some different interfaces. http://www.dofactory.com/Patterns/PatternAdapter.aspx My Question is this:
2
by: darthghandi | last post by:
I am creating a listener class that listens for incoming connections. When I get an incoming connection, I want to signal an event to happen and pass that connected socket to a different thread...
24
by: =?Utf-8?B?U3dhcHB5?= | last post by:
Can anyone suggest me to pass more parameters other than two parameter for events like the following? Event: Onbutton_click(object sender, EventArgs e)" Event handler: button.Click += new...
12
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.