Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / July 2004

Tip: Looking for answers? Try searching our database.

Passing arrays into unmanaged code

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Steve Baer - 02 Jul 2004 01:11 GMT
I'm wrapping some unmanaged C++ classes with managed versions for use in the
.NET world. Everything is going great except I can't figure out a good
method for passing simple data type arrays into unmanaged classes.

Say I have a function
void UnManagedClass::FillOutArray(int size, int* data);
where data is an array of unmanaged ints and size gives the size of the
array.

I would like to wrap the function like so

void  ManagedClass::FillOutArray(int __gc* data[])
{
   int size = data->Length;
   int __pin* pUnMgdData= (some way to pin the data array???)
   m_internalPtr ->FillOutArray(size, pUnMgdData);    //pointer to internal
instance of unmanaged class
}

I know I could create an array of ints in the function and then copy the
values to the data array after the internal unmanaged call, but I was hoping
there would be a slicker way.

Any help would be greatly appreciated. Thanks in advance,
-steve
Ben Schwehn - 05 Jul 2004 18:39 GMT
> void  ManagedClass::FillOutArray(int __gc* data[])
> {
>     int size = data->Length;
>     int __pin* pUnMgdData= (some way to pin the data array???)

you can pin the first member of the array something like that:

int __pin* pUnMgdData = &data[0];

the entire array is now pinned and you have a pointer to the start of
the array

See MSDN:
 Managed Extensions for C++ Specification
7.7 Pinning Pointers

hth
Ben

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.