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

Return an array from the unmanaged

Hello,

I try to edit an array of double (or whatever type) allocated in the
managed code from the unmanaged code.
Is it possible ?
I have an unsupported exception with the below code.

void ExpTest(double* tab)
{
for(int i=0;i<3;i++)
{
tab[i]=i;
}
}

[DllImport("***.dll")]
static extern void ExpTest(ref double[] ouput);

public void Test(ref double[] output)
{
try
{
ExpTest(ref output);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}

Thx

Apr 12 '06 #1
1 1568


"serj" <da**********@gmail.com> wrote in message
news:11*********************@g10g2000cwb.googlegro ups.com...
| Hello,
|
| I try to edit an array of double (or whatever type) allocated in the
| managed code from the unmanaged code.
| Is it possible ?
| I have an unsupported exception with the below code.
|
| void ExpTest(double* tab)
| {
| for(int i=0;i<3;i++)
| {
| tab[i]=i;
| }
| }
|
| [DllImport("***.dll")]
| static extern void ExpTest(ref double[] ouput);
|
| public void Test(ref double[] output)
| {
| try
| {
| ExpTest(ref output);
| }
| catch (Exception ex)
| {
| MessageBox.Show(ex.ToString());
| }
| }
|
| Thx
|

Remove the ref keyword, the interop marshaler will pass a (pinned) pointer
to the array's first element.
But beware, what you are doing is dangerous, you must make sure you don't
write more elements than the the passed array can hold. There is no way for
the unmanaged side to know the length of the array, so you need to pass this
size as well.

Willy.

Apr 12 '06 #2

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

Similar topics

9
by: Angel | last post by:
Hi again, I'm trying to call functions from a proprietary DLL but it's turned out to be more difficult than I thought. I have this W32.DLL which was written in C by USPS. They don't provide the...
16
by: Ekim | last post by:
hello, I'm allocating a byte-Array in C# with byte byteArray = new byte; Now I want to pass this byte-Array to a managed C++-function by reference, so that I'm able to change the content of the...
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?...
2
by: Daniel Mori | last post by:
Hi, Im hoping someone can give me some advice. Im doing some development using VS Whidbey 2005 beta 1. Im about to implement some highly time critical code related to a managed collection of...
17
by: mr.resistor | last post by:
hey i am having a few problems calling a C DLL from C#. i am using a simple function that takes an array of floats and an integer as an input, but i cannot seem to get it to work. when i try to...
4
by: Andreas Reiff | last post by:
Hi! I want some communication to take place between a c++ app and a c++ .dll with an intermediate managed/unmanaged c++ dll. Basicall, I want the unmanaged c++ dll to have a callback to the...
9
by: =?Utf-8?B?U2hhcm9u?= | last post by:
In my managed code (C#) I have a some dozens of single dimension byte array. I get each of this arrays from another unmanaged code (first DLL). I need to stitch these arrays to a dual dimensions...
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...
13
by: =?Utf-8?B?U2hhcm9u?= | last post by:
I have the following managed C++ function (VC++ 2005 (C++/CLI) System::Array^ ManagedCppClass::GetData() { BYTE* pData; int len; m_pureNativeCPPObj->GetData(pData, len); // Get the data buffer...
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
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.