473,395 Members | 2,689 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,395 software developers and data experts.

Interacting with a C++ DLL

Unsolved problem ...

I'm new to C# and having a problem with interaction between a (legacy) C++ dll

and functions in my C# module. I'm using a third party C++ DLL, no source

available (so, not possible to rebuilt it with Managed extensions)
At a certain point in my C#-app I have to return the address of a (managed-)

read-buffer into one of the arguments of a callback function, needed by that

DLL

The legacy C++ DLL callback interface looks like this
static MC_STATUS MediaToFile( char* Afilename
void* AuserInfo
int* AdataSize
void** AdataBuffer,
int AisFirst
int* AisLast

The fourth callback argument: <void** AdataBuffer> needs to be returned with

the address of the managed buffer used in my C# function
I've implemented the above in C# as follows

public delegate int MediaToFile
[MarshalAs(UnmanagedType.LPStr)
string filename
IntPtr info
ref int size
ref IntPtr bufferPtr
int first
ref int last)

..

//Data read in my C#-app are put into CBinfo.buffer
[StructLayout(LayoutKind.Sequential)
public class CBinf

public IntPtr stream
public int messageID
[MarshalAs(UnmanagedType.ByValArray, SizeConst=8192)
public byte[] buffer

..
// Instantiating it
public CBinfo cbi
..

//In the MediaToFile implementation I wrote the following
..
FileStream fs=fi.OpenRead()
nBytesRead=fs.Read(cbi.buffer, 0, nBytes)
..

Next step, the problem: I have to deliver the "cbi.buffer" location (its

address) to the callback argument: "ref IntPtr bufferPtr"
The DLL apparently needs to 'look back' into the buffer data
How to do this
(In C++ I used to write it like this: *AdataBuffer = CBInfo->buffer;

Doing Marshal.nnn / Unsafe / danger of GarbColl moving the buffer....? Please

advise - Thank you for your time
Nov 16 '05 #1
1 1392
key

" function, needed by that

DLL:

The legacy C++ DLL callback interface looks like this:
static MC_STATUS MediaToFile( char* Afilename,
void* AuserInfo,
int* AdataSize,
void** AdataBuffer,
int AisFirst,
int* AisLast)

The fourth callback argument: <void** AdataBuffer> needs to be returned with
the address of the managed buffer used in my C# function.
I've implemented the above in C# as follows:

public delegate int MediaToFile(
[MarshalAs(UnmanagedType.LPStr)]
string filename,
IntPtr info,
ref int size,
ref IntPtr bufferPtr,
int first,
ref int last);

...

//Data read in my C#-app are put into CBinfo.buffer:
[StructLayout(LayoutKind.Sequential)]
public class CBinfo
{
public IntPtr stream;
public int messageID;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=8192)]
public byte[] buffer;
}
...
// Instantiating it:
public CBinfo cbi;
...

//In the MediaToFile implementation I wrote the following:
...
FileStream fs=fi.OpenRead();
nBytesRead=fs.Read(cbi.buffer, 0, nBytes);
...
Next step, the problem: I have to deliver the "cbi.buffer" location (its

address) to the callback argument: "ref IntPtr bufferPtr".
The DLL apparently needs to 'look back' into the buffer data.
How to do this?
(In C++ I used to write it like this: *AdataBuffer = CBInfo->buffer;)

Doing Marshal.nnn / Unsafe / danger of GarbColl moving the buffer....? Please
advise - Thank you for your time!

Nov 16 '05 #2

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

Similar topics

0
by: Andrew Crowe | last post by:
Hi guys, I'm having some trouble using the exec() command on a Windows 2000 / IIS server (PHP5rc2 running as ISAPI). I can execute programs fine, but they are unable to interact with any files...
1
by: Hugh McLaughlin | last post by:
Hello Everyone and thanks for your help in advance. I am working on an application that consists of sever web controls. The header control has a dropdown list for the user to select. I want to...
2
by: John | last post by:
Hi Is it possible for an asp.net site that when it is viewed by a user, the site can interact with the desktop apps possibly written in vb or access? The use I am looking for is that if the user...
2
by: Michael Quan | last post by:
Hello I was wondering if someone could point to me information on how to start an external process and how to interact with it For example In my C# program I want to start a process that will...
1
by: ls | last post by:
Hi, The following URL a has a video entitled "Interacting With Web Sites in Code." The video explains exactly what I am trying to do which is to directly communicate with a website and...
0
by: Paul Wagstaff | last post by:
Hi all, My large public sector employer makes use of a large private sector comglomarate for our IT, and so flexibilty and attention to the needs of the little people aren't exactly top of...
1
by: Raman | last post by:
Hi to all. Can any one tell me how to interact with Internal modem in C on windows platform. And also how to play a WAV file on 16-bit dos envirnoment.
0
by: Mr Bounce | last post by:
Hi, Probably well worn ground, this, but im stumped and need some help, if you could: I'm trying to write some code for a windows service that needs to run in the background polling a server...
3
by: Eps | last post by:
Hi, I am writing an mp3 player using wpf, I have three user controls (media library, media controls and a playlist). Obviously I need these to interact with each other, I assume the best way to...
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
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...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.