Solved

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

Posted on 2009-07-13
2
394 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
Comment Utility
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This video discusses moving either the default database or any database to a new volume.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

772 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now