Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. COM
  4. Which COM interface to export an object into a particular format

Which COM interface to export an object into a particular format

Scheduled Pinned Locked Moved COM
comtutorialquestion
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Carsten Leue
    wrote on last edited by
    #1

    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

    V 1 Reply Last reply
    0
    • C Carsten Leue

      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

      V Offline
      V Offline
      Vi2
      wrote on last edited by
      #2

      There is the IPersistFile which has Load(filename) and Save(filename). With best wishes, Vita

      C 1 Reply Last reply
      0
      • V Vi2

        There is the IPersistFile which has Load(filename) and Save(filename). With best wishes, Vita

        C Offline
        C Offline
        Carsten Leue
        wrote on last edited by
        #3

        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.

        V 1 Reply Last reply
        0
        • C Carsten Leue

          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.

          V Offline
          V Offline
          Vi2
          wrote on last edited by
          #4

          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

          C 2 Replies Last reply
          0
          • V Vi2

            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

            C Offline
            C Offline
            Carsten Leue
            wrote on last edited by
            #5

            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 the IExport in my pseudocode? I considered using IPersistMoniker 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?

            1 Reply Last reply
            0
            • V Vi2

              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

              C Offline
              C Offline
              Carsten Leue
              wrote on last edited by
              #6

              [Message Deleted]

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups