Which COM interface to export an object into a particular format
-
I would like my COM object to expose the functionality to export itself into different binary representations into an output stream. E.g. to render itself into a stream as PDF or as JPEG, etc. The functionality itself is already available, but I don't know how to expose this function in terms of standard COM interfaces. I looked at the IPersistXXX interfaces but they don't allow to specify the target format but assume that the format is inherent to the object. Also for every output format there are potentially format dependent options that need to be passed in. IPersistMoniker looked promising but I am not sure if the intent of this interface is the export into different formats. I would like to reuse existing COM interfaces if possible rather than defining my own interface. What do you recommend? Best regards Carsten
-
I would like my COM object to expose the functionality to export itself into different binary representations into an output stream. E.g. to render itself into a stream as PDF or as JPEG, etc. The functionality itself is already available, but I don't know how to expose this function in terms of standard COM interfaces. I looked at the IPersistXXX interfaces but they don't allow to specify the target format but assume that the format is inherent to the object. Also for every output format there are potentially format dependent options that need to be passed in. IPersistMoniker looked promising but I am not sure if the intent of this interface is the export into different formats. I would like to reuse existing COM interfaces if possible rather than defining my own interface. What do you recommend? Best regards Carsten
-
Hi Vita. Right, but how does the interface allow me to export my object? I would guess the correct format by evaluating the file extension, but that won't work if want to stream the content instead of writing it to a file (IPersistStream). Also IPersistFile does not allow me to pass extra information to configure the export process, such as target width/height of an exported bitmap or the compression ratio for JPEG.
-
Hi Vita. Right, but how does the interface allow me to export my object? I would guess the correct format by evaluating the file extension, but that won't work if want to stream the content instead of writing it to a file (IPersistStream). Also IPersistFile does not allow me to pass extra information to configure the export process, such as target width/height of an exported bitmap or the compression ratio for JPEG.
Right, but how does the interface allow me to export my object?
As usual IPersist* interface. If you try to find some export interface, so you can use the exact IPersistFile. If you aren't able to choice the export interface, you should implement the exact one required by client.
I would guess the correct format by evaluating the file extension, but that won't work if want to stream the content instead of writing it to a file (IPersistStream).
The stream stores the binary data which presents this object (see OleLoadFromStream). There is no matter which format the object used to be stored. With best wishes, Vita
-
Right, but how does the interface allow me to export my object?
As usual IPersist* interface. If you try to find some export interface, so you can use the exact IPersistFile. If you aren't able to choice the export interface, you should implement the exact one required by client.
I would guess the correct format by evaluating the file extension, but that won't work if want to stream the content instead of writing it to a file (IPersistStream).
The stream stores the binary data which presents this object (see OleLoadFromStream). There is no matter which format the object used to be stored. With best wishes, Vita
Hi Vita. I guess I want to make a different point. The COM object that I have represents a graphic with an internal binary representation that is specifc to my application. I want to export this graphic to JPEG into a stream (or a number of other formats). The JPEG representation is not enough to recreate my graphics, so it is not equivalent to persisting my object, I just want to export it to a stream (not to a file), e.g. to pipe it into another filter stream or to return it as a response to an http request. Somewhat like this (pseudocode):
IUnknown* pMyObject = ... IStream* pOut = ... // E.g. via SHCreateStreamOnFile(...) IExport* pExport; pMyObject->QueryInterface(IID_IExport, (LPVOID*) &pExport); LPCWSTR mimeType = L"image/jpeg"; IBindCtx* pJpegOptions = ... IPersistStream* pPersStream; pExport->get_Persister(&pPersStream, mimeType, pJpegOptions); pPersStream->Save(pOut, FALSE); // export the same instance into a different format mimeType = L"application/postscript"; IBindCtx* pPostscriptOptions = ... pExport->get_Persister(&pPersStream, mimeType, pPostscriptOptions ); pPersStream->Save(pOut, FALSE);
I wonder if this is the right programming pattern to export an object and if yes, is there a standard interface that corresponds to theIExport
in my pseudocode? I considered usingIPersistMoniker
like this:IUnknown* pMyObject = ... IPersistMoniker* pPersMon; pMyObject->QueryInterface(IID_IPersistMoniker, (LPVOID*) &pPersMon); IMoniker* pOutMon; CreateFileMoniker(L"test.jpg", &pOutMon); IBindCtx* pJpegOptions = ... pPersMon->Save(pOutMon, pJpegOptions, FALSE)
Is this the right pattern? -
Right, but how does the interface allow me to export my object?
As usual IPersist* interface. If you try to find some export interface, so you can use the exact IPersistFile. If you aren't able to choice the export interface, you should implement the exact one required by client.
I would guess the correct format by evaluating the file extension, but that won't work if want to stream the content instead of writing it to a file (IPersistStream).
The stream stores the binary data which presents this object (see OleLoadFromStream). There is no matter which format the object used to be stored. With best wishes, Vita
[Message Deleted]