I am building an ATL Based DLL. This DLL exposes a interface say MyInterface having two methods
SetIconStream (BSTR a_bstrIconFileName)
GetIconStream (BSTR* a_pIconStream)
SetIconStream Method takes the parameter as the filename of the icon file. In this method it opens the File and read the binary data of the icon file using the normal file functions and store this binary icon stream into a stream of a Compound Doc File.
The GetIconStream method opens the stream and gets the binary icon stream into a buffer. After Converting the buffer into the BSTR through the SysAllocByteLen () function and pass it back to the Caller of the method.
Now if I open a new file in binary mode after getting the binary icon stream from the stream of the compound file and put this into the newly opened file, then the icon file thus created is same as the original icon file.
But If I convert the buffer into the BSTR and then try to put the contents of the BSTR into another file then the icon file generated is not same as the original icon file. Plus the binary contents of the file are different than the Original file.
So my question is how to get the binary data out of the BSTR so that the file created (contents from BSTR) will be same as original one?