473,769 Members | 1,632 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C++/CLI and fixed size buffers

From the same C++ source code, I'm attempting to generate both an unmanaged
DLL and a managed assembly. This will eliminate interop as the calling code
is slowly migrated to .NET.
However, C++ native compilation allows fixed size buffers (e.g. char
pathName[128]) which we've used to represent a memory mapped file, and I
can't find out how to implement the same in C++/CLI
i.e.

#ifdef _MANAGED
ref class MyClass
#else
class MyClass
#endif
{
char pathName[128];
}

For managed compilation, a compiler error is given saying that mixed types
are not supported.

In C# unsafe code blocks, the fixed keyword is available for fixed size
buffers
public fixed char pathName[128];

What is the equivalent in C++/CLI?
Nov 17 '05 #1
2 4656
Something like this :-

ref class R
{
array<char>^ arr;
R()
{
arr = gcnew array<char>(128 );
}
};

--
Regards,
Nish [VC++ MVP]
http://www.voidnish.com
http://blog.voidnish.com
"ldawson" <ld*****@newsgr oup.nospam> wrote in message
news:eg******** ******@TK2MSFTN GP12.phx.gbl...
From the same C++ source code, I'm attempting to generate both an
unmanaged
DLL and a managed assembly. This will eliminate interop as the calling
code
is slowly migrated to .NET.
However, C++ native compilation allows fixed size buffers (e.g. char
pathName[128]) which we've used to represent a memory mapped file, and I
can't find out how to implement the same in C++/CLI
i.e.

#ifdef _MANAGED
ref class MyClass
#else
class MyClass
#endif
{
char pathName[128];
}

For managed compilation, a compiler error is given saying that mixed types
are not supported.

In C# unsafe code blocks, the fixed keyword is available for fixed size
buffers
public fixed char pathName[128];

What is the equivalent in C++/CLI?

Nov 17 '05 #2
ldawson wrote:
In C# unsafe code blocks, the fixed keyword is available for fixed size
buffers
public fixed char pathName[128];

What is the equivalent in C++/CLI?


Oddly, I just wrote a blog entry on this subject. You can check it out to
see inline_array in C++.

http://blogs.msdn.com/branbray/archi...20/441099.aspx

--
Brandon Bray, Visual C++ Compiler http://blogs.msdn.com/branbray/
Bugs? Suggestions? Feedback? http://msdn.microsoft.com/productfeedback/
Nov 17 '05 #3

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

Similar topics

6
4725
by: grunes | last post by:
I wish to fread a few thousand bytes at a time in turn from several very large files from a DVD data disk, under Redhat Fedora Linux. When this is done the DVD drive wastes a lot of time and almost shakes itself to pieces. I tried using setvbuf, with large buffers, e.g. (example only, not checked): #include <stdio.h>
11
32587
by: Stephan Steiner | last post by:
Hi Generally, FileInfo fi = new FileInfo(path); long size = fi.Length; gets you the length of a file in bytes. However, when copying files, even while the copy operation is still in progress, the filesize, as indicated in Windows Explorer or derived with the above two lines of code, will be the size of the file once the copy operation has completed. Is there a way to
4
1775
by: Paul | last post by:
I'm doing some Pinvoke stuff. How do I deal with functions that pass/receive structures that have fixed length char buffers? I see this: public struct MyArray // This code must appear in an unsafe block { public fixed char pathName; }
4
23823
by: Scott Lemen | last post by:
Hi, Some Win APIs expect a structure with a fixed length string. How is it defined in VB .Net 2003? When I try to use the FixedLengthString class I get an "Array bounds cannot appear in type specifiers" error. Thank you, Scott
4
2195
by: taskswap | last post by:
I'm converting an application that relies heavily on a binary network protocol. Within this protocol are a lot of byte arrays of character data, like: public unsafe struct MsgAddEntry { public byte MsgType; public uint Tag; public fixed byte ID; public fixed byte Val1;
1
10431
by: O.B. | last post by:
In the example below, I'm trying to convert a fixed byte array to a string. I get an error about needing to use "fixed" but I have no clue where to apply it. Help? using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices;
4
1855
by: Jack | last post by:
Hi, I do a webrequest and it returns some text data in a stream. I want to put this text data into a string. I've got it working just fine, but I have to put the text data into into a fixed-size buffer BEFORE I put it into a string (ConstBufferByteSize=1000000). This fixed size buffer wastes space. Is
6
7450
by: =?Utf-8?B?TFBldGVy?= | last post by:
Hi, I would copy the characters of a string variable to a fixed character buffer in a struct (and vice versa) in C#. public struct S { ... public fixed char cBuff; ...
6
2181
by: =?Utf-8?B?TWFyZWs=?= | last post by:
Hi I am trying to dynamically create the following structure using AssemblyBuilder, TypeBuilder and DefineField: public struct SimpleType2 { public double dScalar1; public fixed double dArray; public int iScalar1;
0
9589
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
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,...
0
10211
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, 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...
0
10045
jinu1996
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...
0
9863
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 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...
1
7408
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3958
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
3
2815
bsmnconsultancy
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...

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.