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 / .NET Framework / Interop / June 2005

Tip: Looking for answers? Try searching our database.

Byte[] from an IStream

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Chris Capson - 08 Jun 2005 16:43 GMT
I have a C++ .NET application where I need to place an IStream* into a
Byte[] and pass this back to a C# application.

Something like this I guess:
void MailAttachments::GetAttachmentBinary(MAPICDO::Attachment*
pAttachment, Byte b[])
{
 IStream* streamUnk = NULL;

 //attSize is size of the attachment contained within the IStream
 Byte attachmentArray[] = new Byte[attSize];   ....

 //now i need to get the IStream into my Byte[] and return to c#
 hr = streamUnk->Read(attachmentArray, attSize, (ULONG*)&attSize);
\\doesn't compile obviously

 b = attachmentArray;

}

The problem is how do I get the IStream into my Byte[]?

Can anyone help with this?

Any help would be greatly appreciated on this

Chris
Mattias Sjögren - 09 Jun 2005 00:48 GMT
>Something like this I guess:
>void MailAttachments::GetAttachmentBinary(MAPICDO::Attachment*
>pAttachment, Byte b[])
...
>  b = attachmentArray;

You have to make b an output parameter if you want to return something
with it.

>  IStream* streamUnk = NULL;

I assume you actually assign a valid pointer to streamUnk before
calling Read on it.

>  //now i need to get the IStream into my Byte[] and return to c#
>  hr = streamUnk->Read(attachmentArray, attSize, (ULONG*)&attSize);
>\\doesn't compile obviously

Try something like

Byte __pin* p = &attachmentArray[0];
hr = streamUnk->Read(p, attSize, (ULONG*)&attSize);

Mattias

Signature

Mattias Sjögren [MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Chris Capson - 09 Jun 2005 02:55 GMT
Thanks for the Information.

Another question related to this is how do I return a Byte array in C++
as an output? In C# I can do this

Calling application (C#)
{
   byte[] attByteArray=null;
   test.GetAttachmentBinary(attachment, ref attByteArray);
}

C# Method that would return my Byte Array information.
public void GetAttachmentBinary(MAPICDO::Attachment pAttachment, ref
byte[] AttachmentData)
{
   ...
}

How do I do the same in C++? I want to have my calling Application be
the same C# application. But I want my GetAttachmentBinary method to be
in C++ .NET. How Would I define my C++ method so that it would return
the byte[]?

Obviously this won't work but it is what I want to do.
public void GetAttachmentBinary(MAPICDO::Attachment* pAttachment, out
byte[] AttachmentData)
{
   ...
   Byte attachmentArray[] = new Byte[attSize];

   Byte __pin* p = &attachmentArray[0];
   hr = streamUnk->Read(p, attSize, (ULONG*)&attSize);

   AttachmentData = attachmentArray;
}

Once again your help is greatly appreciated on this.

Thanks
Chris

> >Something like this I guess:
> >void MailAttachments::GetAttachmentBinary(MAPICDO::Attachment*
[quoted text clipped - 25 lines]
> http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
> Please reply only to the newsgroup.
Mattias Sjögren - 13 Jun 2005 21:31 GMT
>How do I do the same in C++? I want to have my calling Application be
>the same C# application. But I want my GetAttachmentBinary method to be
[quoted text clipped - 4 lines]
>public void GetAttachmentBinary(MAPICDO::Attachment* pAttachment, out
>byte[] AttachmentData)

I can never quite remember the MC++ syntax but I believe it's
something like

void GetAttachmentBinary(MAPICDO::Attachment* pAttachment, [Out] Byte
(*AttachmentData)[] )

assuming you have

using namespace System;
using namespace System::Runtime::InteropServices;

Mattias

Signature

Mattias Sjögren [MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.


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.