Solved

How to put and retreive byte array through SAFEARRAY

Posted on 2003-12-02
7
1,282 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

863 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

24 Experts available now in Live!

Get 1:1 Help Now