By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,333 Members | 1,843 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,333 IT Pros & Developers. It's quick & easy.

Need advice on the best way to intertwine fixed size 'C' data blocks into managed classes.

P: n/a
I have a managed C++ assembly in which I need to interact with some 'C' APIs
that take fixed size 'C' data blocks. I need to wrap these data blocks into
a managed object. It seems like a lot of redundancy and extra code to have
to marshal .net data from managed to unmanaged for this. Is there some
built-in method in managed C++ that can allow me to create a managed
structure and convert it into a fixed size 'C' data block? I am trying to
figure out the most efficient way to do this without having to write a whole
lot of extra code.

Note, that some of the data consists of character string arrays that I would
like to have wrapped with fixed size String objects.

Example:

void UnmanagedFunc(void *MemBlock, int MemBlockLength)
{
// Do stuff with memory block
}

public __value struct MyStruct
{
int iVal1;
int iVal2;
String *strVal1; // Want this to be translated into a fixed size
character array
};

void MyFunc()
{
MyStruct Struct1;

Struct1.iVal1 = 1;
Struct1.iVal2 = 2;
Struct1.strVal1 = "Test"; // Want this to be a frixed size string of
say 20 characters.

// This is where I want the structure to somehow return a fixed size memory
block that
// can be marshaled to the 'C' API.and also for the structure to know it's
length as a fixed size.
UnmanagedFunc(Struct1, Struct1.Length);
}

--
-----------------------------------
Ken Varn
Senior Software Engineer
Diebold Inc.

EmailID = varnk
Domain = Diebold.com
-----------------------------------
Jul 13 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.