Solved

Unmanaged DLL: C# variable for C++ char**

Posted on 2009-07-13
2
404 Views
Last Modified: 2012-05-07
Hello.

I'm making an application that works with buffers. I have to call some C++ functions with data pointers as arguments. I'm trying to not use unsafe code.
One of the functions have two parameters of type char*. I've defined on C# two buffers:

byte[] Buffer1 = new byte[SIZE];
byte[] Buffer1 = new byte[SIZE];

On the dllimport I use marshaling:
....
[MarshalAs(UnmanagedType.LPArray)] byte[] buffer1,
[MarshalAs(UnmanagedType.LPArray)] byte[] buffer2,
....

These two buffers are filled by the C++ function.
Two retrieve the data of the buffers, I use another C++ function. This function returns in a parameter the last buffer filled:

void FillBuff(char **Pbuff);

Pbuff is a pointer to one of the byte[] buffers defined above.
The problem is that I don't know how to define a C# to assign the pointer returned by the C++ function and accessing to the buffer's content. I've tried several thigs with no success, some of them dying at compilation time, others at execution time.

Any suggestion?

Thanks in advance
0
Comment
Question by:xmasdeu
2 Comments
 
LVL 41

Accepted Solution

by:
graye earned 250 total points
ID: 24859078
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Greetings C# program 17 124
Sent email using Shared Mailbox from outlook in C# 5 50
"Emulate" TAB key when press Enter Key 3 46
C# MVC Insert Multiple Row into DB 2 30
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question