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

Passing C# delegate to C++ with byte array parameter

Hi All,

I am trying to write a C# program to call a routine in managed C++.
In the routine, the C# program passes a delegate to the managed C++.
The delegate looks like this in c++:
public __delegate void FoundPidDelegate (
unsigned char *pData,
);

The C++ is able to call the C# because my routine in C# is unsafe and
looks like this:
static private void MyFoundPidFunction (byte *pData)

Is there any way to make a "safe" C# function that looks like this:
static private void MyFoundPidFunction (byte []pData)
and lets me pass it as a delegate to the C++?

Thanks,

Josh
Nov 16 '05 #1
2 3251
Is there any way to make a "safe" C# function that looks like this:
static private void MyFoundPidFunction (byte []pData)
and lets me pass it as a delegate to the C++?


Change the delegate signature to

public __delegate void FoundPidDelegate (
unsigned char pData __gc[],
);

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 16 '05 #2
When I arrive back in my C# program, the pData array only has one
element and if I try to look at pData[1], I get an error.

In C++ I am allocating the memory like this:
unsigned char arrManaged __gc [] = new unsigned char
__gc[iDataLen];
Then I call the C# delegate routine like this:
m_pFoundFunc(arrManaged);

What am I doing wrong?

Thanks!

Josh

Mattias Sjögren <ma********************@mvps.org> wrote in message news:<eo**************@TK2MSFTNGP09.phx.gbl>...
Is there any way to make a "safe" C# function that looks like this:
static private void MyFoundPidFunction (byte []pData)
and lets me pass it as a delegate to the C++?


Change the delegate signature to

public __delegate void FoundPidDelegate (
unsigned char pData __gc[],
);

Mattias

Nov 16 '05 #3

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

Similar topics

4
by: Mark Rae | last post by:
Hi, Can anyone please tell me if it's possible to pass a System.Web.Mail.MailMessage object to a ASP.NET Web Service? Maybe using XML Serialization / Deserialization? I've been asked to...
8
by: intrepid_dw | last post by:
Hello, all. I've created a C# dll that contains, among other things, two functions dealing with byte arrays. The first is a function that returns a byte array, and the other is intended to...
0
by: Richard Buckshaw | last post by:
Mimick the older C/ pascal dll parameter passing convention? - VB Class Mod? Hello, I have been attempting to write a VB class that would expose its stuff to an older (ok, legacy application)...
7
by: Richard Grant | last post by:
Hi. In c/C++ i can pass the address of a subroutine to another subroutine as an actual parameter How do I do that in VB .NET What should be the syntax for a parameter to receive the address of a...
3
by: DaTurk | last post by:
If I call this method, and pass it a byte by ref, and initialize another byte array, set the original equal to it, and then null the reference, why is the original byte array not null as well? I...
7
by: Andreas Reiff | last post by:
Hey! I have a managed c++ app (actually, the app is mixed managed/unmanaged, but this happens in the managed part) that dynamically generates some program in c# (with CSharpCodeProvider). The...
17
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need...
11
by: Bob Yang | last post by:
Hi, I have this in C++ and I like to call it from c# to get the value but I fail. it will be good if you can give me some information. I tried it in VB.net it works but I use almost the same way as...
10
by: vcquestions | last post by:
Hi. Is there way to have a function pointer to a delegate in c++/cli that would allow me to pass delegates with the same signatures as parameters to a method? I'm working with managed code. ...
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...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...

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.