I'm having a very difficult time coming across an appropriate solution
for this seemingly simple problem. I've written a managed wrapper
class for some legacy C++ routines. One routine generates an array of
ints, which I wish to expose through the managed wrapper. The managed
C++ wrapper is being used as an intermediary to allow VB.NET to access
the legacy C routines (and the return array, in particular).
Given these constraints, can someone please instruct the best course of
action? I can't figure out how to define/update the C array to be .NET
compatible. Do I need to use the Marshal class? Do I need to declare
an "array<int, 1>" and use a handle (^). Any help, particularly
specific syntax examples, would be tremendous.
void returnArray(int * pArray, int& pSize); //Legacy C function
Thanks, Josh 12 2190
Without doing any research I would think you have to use a SAFEARRAY in your
managed wrapper.
<jo*********@gm ail.comwrote in message
news:11******** **************@ 16g2000cwy.goog legroups.com...
I'm having a very difficult time coming across an appropriate solution
for this seemingly simple problem. I've written a managed wrapper
class for some legacy C++ routines. One routine generates an array of
ints, which I wish to expose through the managed wrapper. The managed
C++ wrapper is being used as an intermediary to allow VB.NET to access
the legacy C routines (and the return array, in particular).
Given these constraints, can someone please instruct the best course of
action? I can't figure out how to define/update the C array to be .NET
compatible. Do I need to use the Marshal class? Do I need to declare
an "array<int, 1>" and use a handle (^). Any help, particularly
specific syntax examples, would be tremendous.
void returnArray(int * pArray, int& pSize); //Legacy C function
Thanks, Josh
Kurt thank you for responding. Unfortunately even if a SAFEARRAY is
the answer, I am uncertain how to properly implement it. If anyone
else has suggestions and specific examples I'd be grateful.
-Josh jo*********@gma il.com wrote:
I'm having a very difficult time coming across an appropriate solution
for this seemingly simple problem. I've written a managed wrapper
class for some legacy C++ routines. One routine generates an array of
ints, which I wish to expose through the managed wrapper. The managed
C++ wrapper is being used as an intermediary to allow VB.NET to access
the legacy C routines (and the return array, in particular).
Given these constraints, can someone please instruct the best course
of action? I can't figure out how to define/update the C array to be
.NET compatible. Do I need to use the Marshal class? Do I need to
declare an "array<int, 1>" and use a handle (^). Any help,
particularly specific syntax examples, would be tremendous.
void returnArray(int * pArray, int& pSize); //Legacy C function
Based on that declaration, it looks like the caller is allocating memory
that this function will fill. If that's indeed the case, you can create a
managed array and pass a pinned pointer to the first element of that array
to your legacy function. The fact that pSize is being passed by reference
leads me to suspect that it's set to the size of the memory allocation on
input to the function, and set to the size of the actual data on return from
the function.
#pragma unmanaged
extern void r(int* p, int& s);
#pragma managed
public ref class X
{
static array<int>^ f(int s)
{
array<int>^ a = gcnew array<int>(s);
pin_ptr<intp = &a[0];
r(p,s);
return a;
}
};
-cd
Kurt wrote:
Without doing any research I would think you have to use a SAFEARRAY
in your managed wrapper.
SAFEARRAY is needed only for returning an array to VB6 or any other OLE
automation client. VB.NET can handle an array<int>^ since that's just an
ordinary CLR array.'
-cd
Josh
Look in MSDN there are several good examples for creating SAFEARRAYs.
<jo*********@gm ail.comwrote in message
news:11******** **************@ 73g2000cwn.goog legroups.com...
Kurt thank you for responding. Unfortunately even if a SAFEARRAY is
the answer, I am uncertain how to properly implement it. If anyone
else has suggestions and specific examples I'd be grateful.
-Josh
Kurt, thanks again. Carl, your example seems to be the direction I
need to head. Thank you for getting me pointed there. I will take
examine how this C++.NET class looks when viewed from VB.NET.
Can you tell me how the .NET code will differ when the C routine does
the memory allocation AND the array filling (returning an array
pointer)?
Thank you.
-Josh
Kurt, thanks again. Carl, your example seems to be the direction I
need to head. Thank you for getting me pointed there. I will take
examine how this C++.NET class looks when viewed from VB.NET.
Can you tell me how the .NET code will differ when the C routine does
the memory allocation AND the array filling (returning an array
pointer)?
Thank you.
-Josh
Kurt, thanks again. Carl, your example seems to be the direction I
need to head. Thank you for getting me pointed there. I will take
examine how this C++.NET class looks when viewed from VB.NET.
Can you tell me how the .NET code will differ when the C routine does
the memory allocation AND the array filling (returning an array
pointer)?
Thank you.
-Josh
Kurt, thanks again. Carl, your example seems to be the direction I
need to head. Thank you for getting me pointed there. I will take
examine how this C++.NET class looks when viewed from VB.NET.
Can you tell me how the .NET code will differ when the C routine does
the memory allocation AND the array filling (returning an array
pointer)?
Thank you.
-Josh This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: rakefet |
last post by:
Hi.
I'm really new to this world of .Net so your help would be most
appreciated...
We have API and COM interfaces developed in c. We would also like to
supply a .net interface to our clients.
Searching - I found many new words :-) like .Net wrapper, Assembly...
but I couldn't find a clear cut answer -
|
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 byteArray and afterwards see
the changes in C#.
(if you wanna know more details: the goal is to write the content of an
existing char-array in c++ precisely into the passed byteArray, so that
after the function has proceded the content of the...
|
by: Brett Styles |
last post by:
Hi Guys,
I am trying to access a class in an unmanaged dll. I have
created a wrapper managed class to access the functions I need but no matter
what I try from the MSDN samples I can not get it to work with my code. I
have a VB Net front end which need the access the unmanaged functions. The
wrapper I wrote can be accessed but the wrapper will not compile when I
refer to the unmanaged class. I have tried using header file for definitions...
|
by: DotNetJunkies User |
last post by:
Background:
I am creating a VC++ .NET wrapper for a C++ DLL; the aim is to use this wrapper in C# as shown below:
Range r = new Range( 2, 2 );
r = new Cell( “Hello Mum” );
Range is a managed wrapper around an unmanaged range class. Vector is a managed wrapper around an unmanaged vector class. Cell is a managed wrapper around an unmanaged cell class.
Here r returns a managed Vector* and r accesses a particular Cell in the Vector.
|
by: WithPit |
last post by:
I am trying to create an managed wrapper but have some problems with it by
using abstract classes.
In my unmanaged library code i had the following three classes with the
following hierarchy
Referenced (class)
Object (abstract class, inheriting from referenced)
Node (class, inheriting from object)
| |
by: Amit Dedhia |
last post by:
Hi All
I have a VC++ 2005 MFC application with all classes defined as
unmanaged classes. I want to write my application data in xml format.
Since ADO.NET has buit in functions available for this, I want to use
it. Is it possible to call Managed class functions from Unmanaged
class? How to do it?
I did something like this.
I declared a managed class (in C++ CLI) called as MyManagedClass whose
|
by: pkoniusz |
last post by:
Hello everybody,
Been just thinking how actually one could convert the following
unmanaged code to the managed C++:
struct JustAnExample
{
char value1;
int value2;
// etc ....
|
by: =?Utf-8?B?RWR3YXJkUw==?= |
last post by:
I would greatly appreciate some help on passing managed object into unmanaged
code.
I need to pass a reference (address of) of a managed class into unmanaged
code (written by a thrid party). The 3rd party unmanaged DLL will pass this
reference into standard Win32 unmanaged static callback function in my code.
Inside this unmanaged callback function I need to cast this unmnaged pointer
that I have received from 3rd party back into the...
|
by: chandramohanp |
last post by:
I am having problem to delete a Managed C++ DLL that was used in a
pure C# DLL even in the following scenario.
1. Launch the application. This applicatio has its own default
applicaiton domain.
2. Create a new Application Domain.
3. Load the Pure C# DLL in the new applicaiton domain. This C# DLL uses
managed C++ DLL.
4. Create a Proxy object using CreateInstanceAndUnwrap for the wrapper
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |