467,114 Members | 1,293 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,114 developers. It's quick & easy.

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

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
  • viewed: 1207
Share:

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

15 posts views Thread by Roy Smith | last post: by
2 posts views Thread by Mike Button | last post: by
7 posts views Thread by Timothy Shih | last post: by
2 posts views Thread by Andrew S. Giles | last post: by
2 posts views Thread by ldawson | last post: by
20 posts views Thread by Joe | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.