Hi,
How do we marshall a type like this from a C++/CLI class wrapper to an
unmanaged method?
typedef struct
{
UINT32 blah : 1;
UINT32 blah2 : 1;
UINT32 blah3: 1;
UINT32 someValue : 12;
}SOMESTRUCT;
Thanks. 4 5458
.. wrote: How do we marshall a type like this from a C++/CLI class wrapper to an unmanaged method?
typedef struct { UINT32 blah : 1; UINT32 blah2 : 1; UINT32 blah3: 1; UINT32 someValue : 12; }SOMESTRUCT;
The C++ language doesn't really have the notion of an unmanaged method. A
method that is implemented in native code cannot access CLR types, but
otherwise that's it. The API can have CLR types or it can have native types.
Of course, ref classes do not allow bit fields (mostly because the
efficiency win is probably outweighed by the working set caused by the CLR).
Wrapping is about containing a native type though, not creating a replica of
it with a CLR type. That said, here's an example in the new C++ syntax.
// Native type with bitfield
struct X {
int a : 1;
int b : 2;
int c : 3;
};
// CLR type that wraps X
ref class W {
X * x;
public:
W(int a, int b, int c) {
x = new X;
x->a = a;
x->b = b;
x->c = c;
}
~W() {
delete x;
}
!W() {
delete x;
}
property X* MyX {
X* get() { return x; }
}
};
// Native API
void F(X* x) { /*...*/ }
// Managed API
void F(W^ w) {
F(w->MyX);
}
--
Brandon Bray, Visual C++ Compiler http://blogs.msdn.com/branbray/
This posting is provided AS IS with no warranties, and confers no rights.
inline.
"Brandon Bray [MSFT]" <br******@onlin e.microsoft.com > wrote in message
news:uK******** ********@TK2MSF TNGP11.phx.gbl. .. . wrote: How do we marshall a type like this from a C++/CLI class wrapper to
an unmanaged method?
typedef struct { UINT32 blah : 1; UINT32 blah2 : 1; UINT32 blah3: 1; UINT32 someValue : 12; }SOMESTRUCT; The C++ language doesn't really have the notion of an unmanaged method. A method that is implemented in native code cannot access CLR types, but otherwise that's it. The API can have CLR types or it can have native
types. Of course, ref classes do not allow bit fields (mostly because the efficiency win is probably outweighed by the working set caused by the
CLR). Wrapping is about containing a native type though, not creating a replica
of it with a CLR type. That said, here's an example in the new C++ syntax.
// Native type with bitfield struct X { int a : 1; int b : 2; int c : 3; };
// CLR type that wraps X ref class W { X * x;
public: W(int a, int b, int c) { x = new X; x->a = a; x->b = b; x->c = c; }
~W() { delete x; }
!W() { delete x; }
Whats this "!" syntax? I never seen it before. *dumb mode ON* property X* MyX { X* get() { return x; } } };
// Native API void F(X* x) { /*...*/ }
// Managed API void F(W^ w) { F(w->MyX); }
-- Brandon Bray, Visual C++ Compiler http://blogs.msdn.com/branbray/ This posting is provided AS IS with no warranties, and confers no rights.
Basically I have these classses that I need to get visible int he managed
world in my C# project.
I have done the usual mixed mode wrapper with a library being a proxy for
every method and have a few structs that I have to pass in and out so I
mirrord those. But these bitfields got me stumped.
So IF I understand that right I basically wrap this bitfield and set it via
a ctor in the CLR type, unless I specify propsets for every member, right?
.. wrote: Whats this "!" syntax? I never seen it before.
It is how you write finalizers in the new syntax. It's similar to how
destructors are written with the ~ syntax.
I have done the usual mixed mode wrapper with a library being a proxy for every method and have a few structs that I have to pass in and out so I mirrord those. But these bitfields got me stumped. So IF I understand that right I basically wrap this bitfield and set it via a ctor in the CLR type, unless I specify propsets for every member, right?
Exactly what you do depends on the abstraction. The example I showed simply
gave a way to wrap an existing type that has bit fields into a managed type
that C# can understand. The point is that there is no need to encode bit
types inside a ref or value class because you can simply wrap the native
type.
--
Brandon Bray, Visual C++ Compiler http://blogs.msdn.com/branbray/
This posting is provided AS IS with no warranties, and confers no rights.
.. wrote: Whats this "!" syntax? I never seen it before.
It is how you write finalizers in the new syntax. It's similar to how
destructors are written with the ~ syntax.
I have done the usual mixed mode wrapper with a library being a proxy for every method and have a few structs that I have to pass in and out so I mirrord those. But these bitfields got me stumped. So IF I understand that right I basically wrap this bitfield and set it via a ctor in the CLR type, unless I specify propsets for every member, right?
Exactly what you do depends on the abstraction. The example I showed simply
gave a way to wrap an existing type that has bit fields into a managed type
that C# can understand. The point is that there is no need to encode bit
types inside a ref or value class because you can simply wrap the native
type.
--
Brandon Bray, Visual C++ Compiler http://blogs.msdn.com/branbray/
This posting is provided AS IS with no warranties, and confers no rights. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Davide Bruzzone |
last post by:
Greetings all...
I need to create a number of bitfield structs whose contents are
smaller than the size of an int. For example:
typedef struct foo FOO;
struct foo {
unsigned char fieldOne: 2, fieldTwo: 6;
};
|
by: Ray |
last post by:
When a single-bit bitfield that was formed from an enum
is promoted/cast into an integer, does ANSI C say anything
about whether that integer should be signed or unsigned?
SGI IRIX cc thinks it is an unsigned integer, so I
see a +1 if the bit is set. Microsoft VC++ thinks it's
signed, so I see -1 if the bit is set.
Ex.
typedef enum {
|
by: Andy Venikov |
last post by:
Sometimes you want to use a bitfield to hold an enum value. In such
cases you would only use as many bits as are needed to encode the
full set of enum values. And it is a pain to recompute and updated
the bitfield length each time you add new enum values. But there is
a way to make the compiler do it for you. Like this:
enum Enums
{
Enum1,
Enum2,
|
by: Animesh |
last post by:
Hi All,
I don't know whethher this is possible or not. This is the result of a
bad design problem.
Here I go; I have a structure like this:
typedef struct _s_index_entry {
char *doc_id;
double s_id;
|
by: Howard Kaikow |
last post by:
I've got the following in a VB 6 project:
Private Type PROCESSENTRY32
dwSize As Long
cntUsage As Long
th32ProcessID As Long
th32DefaultHeapID As Long
th32ModuleID As Long
cntThreads As Long
th32ParentProcessID As Long
| |
by: RJ Lohan |
last post by:
Howdy,
I have a legacy DLL for which I have a problem marshalling a parameter type
of char**.
The function header (C++) is as so;
extern "C" __declspec(dllexport) int __stdcall GetChildren(GetChildrenParm
*, Results *);
|
by: arne |
last post by:
Hi all,
cleaning up some elderly code, I stumbled across the following:
/**************************************************/
struct {
uint bf:8;
char a1;
char a2;
|
by: shaun roe |
last post by:
For a bit of seasonal festive fun, I thought I'd try making a bitfield
function, i.e. a function returning, for example, the value of bits 1 to
5 of a word as an integer, when the exact bits are known at compile
time.
The data word is always 32 bit unsigned integer (its a data stream from
some embedded controller).
The legacy code I have has lines like:
errNum = (dataWord>>1) & 31; //bits 1 to 5 is an error code
|
by: calenlas |
last post by:
Hi all,
I'm taking my first steps into C# <--C++ DLL Interop and
unfortunately I've run into (what seems to be) a very complicated case
as my first task. Perhaps someone here can help me.
I need to pass an array of RADIO_INFO2 structures to be filled by a
function in the DLL. This is how the structure is defined in the C++
example that comes with the DLL:
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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: 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: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
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: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |