473,320 Members | 1,879 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 a ref array to the method in C# (which written in C++)

Hi All!
I have a dll, which is written in VC++.NET.
In the dll, I write a method like that
void SetData(double* array, int len)
.....

then, I use this dll in a C#-Application, trying to pass
double[] myArray = new double[10];
MyObj.SetData(myArray, 10);

it posted an error: Can not convert from 'doublt[]' to 'ref double'.
Pls help me to solve this problem!
thanks!
Nov 17 '05 #1
2 1199
Hi Alex
you can try

double[] myArray = new double[10];
unsafe
{
fixed(double *myPtr = myArray)
SetData(myPtr, 10);
}

with "Allow unsafe code blocks" configuration enable.

Alex wrote:
Hi All!
I have a dll, which is written in VC++.NET.
In the dll, I write a method like that
void SetData(double* array, int len)
....

then, I use this dll in a C#-Application, trying to pass
double[] myArray = new double[10];
MyObj.SetData(myArray, 10);

it posted an error: Can not convert from 'doublt[]' to 'ref double'.
Pls help me to solve this problem!
thanks!

Nov 17 '05 #2
Thank Shortgrey!

but I don't know how my project has not worked yet, event I have done
anything as you guide

double[] x = new double[10];

double[] y = new double[10];

for (int i = 0; i < 10; i++)

{

x[i] = i;

y[i] = 10*i;
unsafe

{

fixed(double *xx = x)

fixed(double *yy = y)

myDllObj.SetData(xx, yy, 10, true);
}

The same error!


"Shortgrey" <no*****@please.fr> wrote in message
news:d3**********@news.tiscali.fr...
Hi Alex
you can try

double[] myArray = new double[10];
unsafe
{
fixed(double *myPtr = myArray)
SetData(myPtr, 10);
}

with "Allow unsafe code blocks" configuration enable.

Alex wrote:
Hi All!
I have a dll, which is written in VC++.NET.
In the dll, I write a method like that
void SetData(double* array, int len)
....

then, I use this dll in a C#-Application, trying to pass
double[] myArray = new double[10];
MyObj.SetData(myArray, 10);

it posted an error: Can not convert from 'doublt[]' to 'ref double'.
Pls help me to solve this problem!
thanks!

Nov 17 '05 #3

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

Similar topics

4
by: Fred | last post by:
Hi, i know how to pass a value from Javascript to ASP with a hidden field into a form and submitting it, or with cookies, but here i have to pass a lot of data in an array. There is a list of...
7
by: SB | last post by:
What is the proper way to pass a character array (char *) from a "C" dll to a C# method (delegate) in my app? Getting the dll (which simulates a third party dll) to call my delegate works fine. ...
5
by: apm | last post by:
Any and all: Is there an efficient way to pass a large array from .NET to COM? Can references (or pointer) be passed from COM to NET and NET to COM without the object it refers to being copied?...
3
by: Brett | last post by:
I have several classes that create arrays of data and have certain properties. Call them A thru D classes, which means there are four. I can call certain methods in each class and get back an...
4
by: _Mario.lat | last post by:
Hallo, I have a little question: In the function session_set_save_handler I can pass the name of function which deal with session. In Xoops code I see the use of this function like that: ...
14
by: Abhi | last post by:
I wrote a function foo(int arr) and its prototype is declared as foo(int arr); I modify the values of the array in the function and the values are getting modified in the main array which is...
11
by: venkatagmail | last post by:
I have problem understanding pass by value and pass by reference and want to how how they are or appear in the memory: I had to get my basics right again. I create an array and try all possible...
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
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: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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.