Jump to content

  • Log In with Google      Sign In   
  • Create Account

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


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 Telios   Members   -  Reputation: 398

Like
0Likes
Like

Posted 01 August 2012 - 12:55 PM

Hiya,

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

typedef std::vector<char> FileBuffer;

void ArchiveWriter::write(const std::string& name, const FileBuffer& fileBuffer);


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 byte[] type is similar to std::vector<char>?

Any help is appreciated!

Cheers.

Edited by Telios, 01 August 2012 - 12:57 PM.


Sponsor:

#2 rip-off   Moderators   -  Reputation: 8737

Like
0Likes
Like

Posted 01 August 2012 - 04:01 PM

Why? Are you allowed to change the interface? If so, I'd recommend using an iterator version of the code. Otherwise you'll have to copy the byte array into a std::vector.

#3 Telios   Members   -  Reputation: 398

Like
0Likes
Like

Posted 01 August 2012 - 04:10 PM

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 vector<char> equivalent, but if there's a more sensible alternative I'm all ears!

Thanks.

#4 DZee   Members   -  Reputation: 190

Like
1Likes
Like

Posted 01 August 2012 - 06:13 PM

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 byte[] is equivalent to unsigned char(Unsigned 8-bit integer). 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, 01 August 2012 - 06:17 PM.

I "surf" the web, literally.


#5 Telios   Members   -  Reputation: 398

Like
0Likes
Like

Posted 02 August 2012 - 02:26 AM

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!




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS