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

Paasing structs to/from C# via MC++ to C++ dll - How?

Hi,

I am a bit of a newcomer to C# but have experience with (unmanaged) C++.

Now, I have a 3rd party dll and headers. This dll is a C++ style dll that
exports classes and structs.
I am attempting to write a Managed C++ wrapper dll for this dll in order
that it can be used from various C# modules in the overall project.
The managed C++ project can 'see' the definitions for the structs that the
lower functions use in the supplied headers.

I cannot reference these headers from the C# project (and have a feeling
that even if I could it would be a 'bad thing' to do so). So how do I
export wrapper structs from the middle tier managed c++ dll to the upper C#
level and how do I convert and pass them up and down the chain?

Hope this query makes sense. Many thanks

--
KM

Nov 15 '05 #1
3 1587
Keith,

It all depends on the structure actually. Depending on how complex it
is, perhaps you want to create a class representation (in managed code), and
then handle the conversion somewhere in the MC++ code. Can you show the
structure that you want to define/use?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Keith M" <ke***********@nospam.amsjv.com> wrote in message
news:3f********@baen1673807.greenlnk.net...
Hi,

I am a bit of a newcomer to C# but have experience with (unmanaged) C++.

Now, I have a 3rd party dll and headers. This dll is a C++ style dll that
exports classes and structs.
I am attempting to write a Managed C++ wrapper dll for this dll in order
that it can be used from various C# modules in the overall project.
The managed C++ project can 'see' the definitions for the structs that the
lower functions use in the supplied headers.

I cannot reference these headers from the C# project (and have a feeling
that even if I could it would be a 'bad thing' to do so). So how do I
export wrapper structs from the middle tier managed c++ dll to the upper C# level and how do I convert and pass them up and down the chain?

Hope this query makes sense. Many thanks

--
KM


Nov 15 '05 #2

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message

It all depends on the structure actually. Depending on how complex it
is, perhaps you want to create a class representation (in managed code), and then handle the conversion somewhere in the MC++ code. Can you show the
structure that you want to define/use?


Here is a typical one of about 10 that I have:

typedef struct _MYStruct{
LARGE_INTEGER CreationTime;
LARGE_INTEGER LastAccessTime;
LARGE_INTEGER LastWriteTime;
ULONG FileAttributes;
ULONG NumVersions;
ULONG NumFragments;
ULONG Flags;
USHORT ExtraHeaderSize;
USHORT ExtraFooterSize;
} MyStruct;

Any ideas welcome! What a wrapper class would look like and how to convert?
The LARGE_INTEGER member is actually a WIn32 defined structure or union so
how would I incorporate this?
I am thinking I will have to write a series of conversion functions, one for
each struct I want to use and simply do a member wise copy in the function.
As for the large int structure I think I will have to define my own similar
struct and use this in my new wrapper class.

Thanks
Nov 15 '05 #3
Keith,
What a wrapper class would look like and how to convert?
Something like

__value struct MyManagedStruct {
Int64 CreationTime;
Int64 LastAccessTime;
Int64 LastWriteTime;
UInt32 FileAttributes;
UInt32 NumVersions;
UInt32 NumFragments;
UInt32 Flags;
UInt16 ExtraHeaderSize;
UInt16 ExtraFooterSize;
};

The LARGE_INTEGER member is actually a WIn32 defined structure or union so
how would I incorporate this?
Work with the QuadPart member of the union, it's just a 64-bit
integer. You should be able to assign it to/from a System::Int64.

I am thinking I will have to write a series of conversion functions, one for
each struct I want to use and simply do a member wise copy in the function.


Yes, that will work. But for simple integer data like the struct
above, you could also just to a memcpy between the native and managed
structs.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 15 '05 #4

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

Similar topics

26
by: codymanix | last post by:
Last night I had several thought about RAII and want to discuss a bit. Why doesn't CSharp support destructors in structs? Wouldn't that make RAII possible like in C++? When the struct goes out of...
19
by: Jasper Kent | last post by:
Can anyone explain the logic behind structs being allowed neither memeber initialisers or default constructors. Doesn't this just encourage developers to create constructors with dummy...
4
by: MSDousti | last post by:
Hi all, I read some Q&As in the Net, discussing Marshalization of nested structs in C# (or VB.NET). Some guys stated that .NET framework does not support this feature yet. Are they right? ...
19
by: hamil | last post by:
I have a form with one button, Button1, and a Textbox, Textbox1 I have a class, class1 as follows. Public Class Class1 Public DeForm As Object Sub doit() DeForm.Textbox1.text = "It works"...
7
by: James Johnson | last post by:
Are there structs in JavaScript? If not, what's the closest thing, or do I just use parallel arrays? I'm populating a JavaScript array from ColdFusion query, but I don't think I can do this: ...
36
by: Roman Mashak | last post by:
Hello, All! I implemented simple program to eliminate entry from the file having the following structure (actually it's config file of 'named' DNS package for those who care and know): ...
61
by: Marty | last post by:
I am new to C# and to structs so this could be easy or just not possible. I have a struct defined called Branch If I use Branch myBranch = new Branch(i); // everything works If I use Branch...
2
by: dachrist28 | last post by:
I am trying to populate a listbox with data that is pulled from a sql query. Here is my C# code behind the page: sqlConn1.Open(); SqlCommand sqlComm2 = new SqlCommand("SElECT...
5
by: mc | last post by:
I have a function (shown below) that I call to check if a server is present. when a server is present, everything is ok. however when it fails. I get an SocketException fired. On my development...
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
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: 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
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
Oralloy
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,...
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...

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.