Sign in to follow this  
beebs1

std::vector<char> in C++/CLI?

Recommended Posts

beebs1    398
Hiya,

I have a C++ class with a public method like so:

[code]
typedef std::vector<char> FileBuffer;

void ArchiveWriter::write(const std::string& name, const FileBuffer& fileBuffer);
[/code]


I need to use this from C#, so I've written a C++/CLI wrapper DLL around the class. I'm a little stuck on the method above, as I'm not sure how I can pass a byte buffer from C# and convert it to a vector<char>.

My understanding of C# isn't really up to scratch, but I believe a [font=courier new,courier,monospace]byte[][/font] type is similar to [font=courier new,courier,monospace]std::vector<char>[/font]?

Any help is appreciated!

Cheers. Edited by Telios

Share this post


Link to post
Share on other sites
beebs1    398
Yep, I can change the interface.

I'm not very familiar with .NET, so I've just tried to match the interface as closely as possible when writing the CLI wrapper. I've been hunting around for a [font=courier new,courier,monospace]vector<char>[/font] equivalent, but if there's a more sensible alternative I'm all ears!

Thanks.

Share this post


Link to post
Share on other sites
DZee    194
A few months ago I ported all the Kinect C# code to C++/CLI and it took months. I can't remember exactly, but know that a[b] byte[] is equivalent to unsigned char([/b][b]Unsigned 8-bit integer)[/b]. I used regular buffer arrays for my work, I think they were pointers, so I can't help you with that vector signature.

You should be able to get away with a regular [ ] array. Perhaps a ^ handle pointer. Thing is I was porting from C# to C++ and you are doing the opposite, can't help you more than that =/.


I'm not 100%, but from memory, you might have to use a uchar * and point to the first block of memory and pin it in managed code to convert it. Edited by DZee

Share this post


Link to post
Share on other sites
beebs1    398
Aha, thanks. I'm note sure that there's actually any way to construct a std::vector<> using pre-allocated memory - so I'm going down the wrong path here. I'll change the interface to accept a pointer and size, and try your suggestion.

Thanks!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this