Solved

How to put and retreive byte array through SAFEARRAY

Posted on 2003-12-02
7
1,286 Views
Last Modified: 2010-05-18
Hi,

I m relatively new to C++. Can any of them tell me how to put byte array into a safe array and retreive them. I m forced to use this Safe array and i m new to C++. so can anyone post a piece of code for this. Any sample code is appreciated.

Thanks
Ram
0
Comment
Question by:rampriya_sb
  • 4
  • 3
7 Comments
 
LVL 19

Expert Comment

by:Dexstar
ID: 9863005
@rampriya_sb:

> I m relatively new to C++. Can any of them tell me how to put byte array into
> a safe array and retreive them. I m forced to use this Safe array and i m new
> to C++. so can anyone post a piece of code for this. Any sample code is appreciated.

Whenever I need to use a SAFEARRAY, I use this class:
     http://www.sellsbrothers.com/tools/comvector.h

Then you can write code like this:
     CComVector<BYTE>   vec;

     vec.Create( 100 );  // Create a safe array with 100 bytes
     {
          CComVectorData<BYTE> data( vec );
         
          data[0] = 0x01;
          data[1] = 0x02;
     }

If you need help using those classes let me know.  They include pretty good examples.

Hope That Helps,
Dex*
0
 

Author Comment

by:rampriya_sb
ID: 9863059
Dex,

Thanks for the help, Yaa, this class seems to be useful and reduces my job i guess... so can u include some more examples on this. you can mail me at rampriya_sb@yahoo.com

Thanks in advance
Ram
0
 
LVL 19

Expert Comment

by:Dexstar
ID: 9863073
Ram,

I'd be happy to provide you with another example, but if I e-mail it to you, then it doesn't help anyone else who reads this question.  What do you need to do with the SAFEARRAY?  I'll try to give you an exact example.

Dex*
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

Author Comment

by:rampriya_sb
ID: 9863131
Dex,

ok, thats fine, I need to pass a byte array in the safe array. I'll be passing the reference of this safe array to another code, where i need to retreive the byte array. So please let me know how to go about using this class...

Thanks
Ram
0
 
LVL 19

Expert Comment

by:Dexstar
ID: 9863728
Ram,

Okay, this example will create a SAFEARRAY, copy in a byte array (lpData) that has a size of dwSize:
     CComVector<BYTE>   vec;
     vec.Create( dwSize );
     {
          CComVectorData<BYTE> data( vec );
         
          ::CopyMemory( &(data[0]), lpData, dwSize );
     }
     // Now, you can use "vec" for anything that calls for a SAFEARRAY
     SomeFunc( vec );

What else would you like to see?

Dex*
0
 

Author Comment

by:rampriya_sb
ID: 9870419
Dex*

Thanks a lot for your help, I need another help. I have stored a bmp file in the database. I need to display that on the screen, how do i display that on the screen? can you help me out..

thanks
ram
0
 
LVL 19

Accepted Solution

by:
Dexstar earned 500 total points
ID: 9870437
Sure, I can help you, but you should open a new question, so that other people can help you too.

If you're done with this question, you should accept an answer.  If you aren't finished, then you should explain what else you need.

Dex*
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now