|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
how to pass a byte array by referenceI am new to Managed c++ and C# . I've to use unmanaged code in C# . For that I've written a managed wrapper. I am passing a byte array to a function and updating that byte array. And I've to use that in my C# code. And the link http://groups.google.co.in/group/microsoft.public.dotnet.languages.vc/browse_thread/thread/f2af8dac6c3bd57a/6a697b4b060b8f93?lnk=st&q=C2234+%2B+managed+c%2B%2B&rnum=3&hl=en#6a697b4b060b8f93 says that "you dont need to declare it as a reference, since in Managed C++ you pass everything by reference by default." So I've tried like foo(Byte byteBuffer __gc[]) in my MC++ code. But when I get the value in my C# code it has not been updated. Can any one know how to pass a byte array by reference .. Thanks in advance.... Regards, RSL. >So I've tried like foo(Byte byteBuffer __gc[]) in my MC++ code. That should work as long as you only want to change the elements ofthe existing array. If you want to return a new array, you need to pass it by reference. >But when I get the value in my C# code it has not been updated. Can you post more of your code? Perhaps the problem is elsewhere.Mattias -- Mattias Sjögren [C# MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com Please reply only to the newsgroup. Mattias Sjögren wrote:
Show quote > >So I've tried like foo(Byte byteBuffer __gc[]) in my MC++ code. Hi Mattias,> > That should work as long as you only want to change the elements of > the existing array. If you want to return a new array, you need to > pass it by reference. > > > >But when I get the value in my C# code it has not been updated. > > Can you post more of your code? Perhaps the problem is elsewhere. > > > Mattias > > -- > Mattias Sjögren [C# MVP] mattias @ mvps.org > http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com > Please reply only to the newsgroup. I could not reply to your mail as I was on vacation. void foo(Byte byteBuffer __gc[]) { unsigned long ulBufferSize = 0 ; Encoding *encoder = Encoding::Unicode ; String* strtemp ; PutBLOB(); strtemp = encoder->GetString(byteBuffer); m_Blob->WriteToBuffer(static_cast<unsigned char*>(Marshal::StringToHGlobalAnsi (strtemp).ToPointer())); byteBuffer = encoder->GetBytes(strtemp->ToCharArray()); } Is there something wrong?If so.. please let me know. And if any one has solution for this please suggest..Thanks in advance. Regards, RSL |
|||||||||||||||||||||||