473,388 Members | 1,405 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,388 software developers and data experts.

Firing an event that returns an array

Hello,

I'm still trying to get to grips with managed C++.

I want to raise an event RaiseEvent which has as one
of its arguments a managed array.

The event will be raised in a function Func which will
take in an instance of an unmanaged class ByteArray.

ByteArray essentially wraps an array of bytes
(or chars) which you get using a serialize method, and
whose length you find out using the size method.

Here is my attempt below:

void Func(ByteArray ba)
{

int arrLen = ba.size();

System::Byte __pin baArray __gc[] = new System::Byte[arrLen];

char* baArray2 = &baArray[0];

ba.serialize(baArray2);

RaiseEvent(baArray);
}

What I am confused about is whether I need to put the __gc
in front of the array baArray that I will be passing in
RaiseEvent, or whether I have missed it elsewhere. I'm
also not sure whether I need to pin the array - I think
I should because I will be passing it to a function of
an unmanaged class.

Any clarification would be appreciated.

--
Akin

aknak at aksoto dot idps dot co dot uk


Nov 17 '05 #1
1 1022
Wild Wind wrote:
void Func(ByteArray ba)
{

int arrLen = ba.size();

System::Byte __pin baArray __gc[] = new System::Byte[arrLen];

char* baArray2 = &baArray[0];

ba.serialize(baArray2);

RaiseEvent(baArray);
}

What I am confused about is whether I need to put the __gc
in front of the array baArray that I will be passing in
RaiseEvent, or whether I have missed it elsewhere. I'm
also not sure whether I need to pin the array - I think
I should because I will be passing it to a function of
an unmanaged class.


I believe the __gc keyword is optional in baArray's declaration, since
you used the .NET type name System::Byte instead of the C++ type name
unsigned char.

Pinning is something you do to pointer variables, not array variables -
whenever you hold a pinning pointer to some managed memory, the garbage
collector won't touch that memory. Take the __pin keyword out of
baArray's declaration, and put it in baArray2's declaration.

It might also be a good idea to unpin the array (set baArray2 to NULL)
after calling ba.serialize(), so the GC can move the array if it needs
memory while RaiseEvent is executing.

Jesse
Nov 17 '05 #2

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

Similar topics

4
by: Tim Haughton | last post by:
Can anyone tell me how to dynamically fire an event? I have an object that reflects on which events it has and based on some logic, elects which one to fire. Or at least that's the plan. So...
13
by: John Kiernan | last post by:
Hey JavaScript gurus... I'm going to try this again. I haven't gotten as much help as I have advice on style<grin>. I appreciate (having programmed in other languages for quite a while) that...
1
by: Edward | last post by:
I am having a terrible time getting anything useful out of a listbox on my web form. I am populating it with the results from Postcode lookup software, and it is showing the results fine. What...
24
by: ej1002 | last post by:
Hi I have developed a Windows Application(C# Windows Form) which will get the IFrame Source of the page it is navigating using Webbrowser Control. Now I want do this in ASP.Net web application(C#...
1
by: Luis Esteban Valencia Muñoz | last post by:
Hello Experts, I have three classes: Globals.cs, FunctionalArea.ascx.cs, and ReprotList.ascx.cs. The idea is that when one drop down is changed (i.e. Functional Area), another drop down on...
1
by: Andy | last post by:
Hello, I have a datagrid within another datagrid. The innder datagrid contains a dropdownlist which fires an event as index change (OnSelectedIndexChanged). I can get the ItemIndex of the...
4
by: TS | last post by:
I am creating a User control and i create some dynamic controls in the init handler. one of the controls is a custom validator which i assign a serverValidate event handler. I usally always do my...
1
by: =?iso-8859-1?B?R2VhcvNpZA==?= | last post by:
Hi, Wierd problem. Using ASP.NET 2.0. Have a DropDownList - <asp:DropDownList ID="DropDownListMake" runat="server" CssClass="selectComparison" AutoPostBack="True"...
4
by: Joergen Bech | last post by:
I sometimes use delegates for broadcasting "StateChanged" events, i.e. if I have multiple forms and/or controls that need updating at the same time as the result of a change in a global/common...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...

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.