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. Visual Basic
  4. Stupid question about Automation

Stupid question about Automation

Scheduled Pinned Locked Moved Visual Basic
c++questionwpfwcfcom
5 Posts 4 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.
  • B Offline
    B Offline
    Bash
    wrote on last edited by
    #1

    Hello guys, I'm novice in VB 6.0 but have some skill in VC++. I'm developing COM-server using Visual C++ and "thin client" in VB 6.0 ("late binding"). One of function is present in COM-server as follows: [id(5), helpstring("method Encoder")] HRESULT Encoder([out] long * Result, [out] long * LastError); As you see, method "Encoder" receives two pointers to long data type. I can invoke that method from client written on Visual C++, but I can't do that on VB. Is it possible to call method "Encoder" from VB Client? How? Or I need to rewrite my COM-server and include two separate methods: - get_EncoderResult - get_EncoderLastError ? Yours sincerely, Alex Bash

    D A 2 Replies Last reply
    0
    • B Bash

      Hello guys, I'm novice in VB 6.0 but have some skill in VC++. I'm developing COM-server using Visual C++ and "thin client" in VB 6.0 ("late binding"). One of function is present in COM-server as follows: [id(5), helpstring("method Encoder")] HRESULT Encoder([out] long * Result, [out] long * LastError); As you see, method "Encoder" receives two pointers to long data type. I can invoke that method from client written on Visual C++, but I can't do that on VB. Is it possible to call method "Encoder" from VB Client? How? Or I need to rewrite my COM-server and include two separate methods: - get_EncoderResult - get_EncoderLastError ? Yours sincerely, Alex Bash

      D Offline
      D Offline
      Daniel Turini
      wrote on last edited by
      #2

      Both VBScript and VB can't call via IDispatch (what you call "late binding" in VB world) methods that receive arguments ByRef. You can do this via early binding, though. I see you have your IDL interface defined, so why are you calling this using late binding? Trying to make bits uncopyable is like trying to make water not wet. -- Bruce Schneier By the way, dog_spawn isn't a nickname - it is my name with an underscore instead of a space. -- dog_spawn

      V 1 Reply Last reply
      0
      • B Bash

        Hello guys, I'm novice in VB 6.0 but have some skill in VC++. I'm developing COM-server using Visual C++ and "thin client" in VB 6.0 ("late binding"). One of function is present in COM-server as follows: [id(5), helpstring("method Encoder")] HRESULT Encoder([out] long * Result, [out] long * LastError); As you see, method "Encoder" receives two pointers to long data type. I can invoke that method from client written on Visual C++, but I can't do that on VB. Is it possible to call method "Encoder" from VB Client? How? Or I need to rewrite my COM-server and include two separate methods: - get_EncoderResult - get_EncoderLastError ? Yours sincerely, Alex Bash

        A Offline
        A Offline
        Anonymous
        wrote on last edited by
        #3

        That's because VC++ can handle [out] parameters - VB cannot. In order to return a logical value back to a VB client your interface's final parameter must be marked as [out, retval]. However, you're wanting to return multiple values which is best suited for SAFEARRAYS. So your question was: Is it possible to call method "Encoder" from VB Client? How? With your current implementation? No

        1 Reply Last reply
        0
        • D Daniel Turini

          Both VBScript and VB can't call via IDispatch (what you call "late binding" in VB world) methods that receive arguments ByRef. You can do this via early binding, though. I see you have your IDL interface defined, so why are you calling this using late binding? Trying to make bits uncopyable is like trying to make water not wet. -- Bruce Schneier By the way, dog_spawn isn't a nickname - it is my name with an underscore instead of a space. -- dog_spawn

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

          Really? ' Client's code - VB6:

          Dim o As Cx, o2 As Object
          Dim p1 As Long, p2 As Long
          ...
          Set o = New Cx
          Set o2 = o
          ...
          p1 = 0: p2 = 0
          o.Encoder p1, p2 ' Call by vtable => early binding
          p1 = 0: p2 = 0
          o2.Encoder p1, p2 ' Call by GetIdsOfName&Invoke => late binding
          p1 = 0: p2 = 0
          CallByName o, "Encoder", VbMethod, p1, p2 ' forcible late binding
          p1 = 0: p2 = 0
          CallByName o2, "Encoder", VbMethod, p1, p2

          ' Server's code - C++:

          STDMETHODIMP Cx::Encoder(/*[out]*/ long * Result, /*[out]*/ long * LastError)
          {
          *Result = 22;
          *LastError = 222;
          return S_OK;
          }

          With best wishes, Vita

          A 1 Reply Last reply
          0
          • V Vi2

            Really? ' Client's code - VB6:

            Dim o As Cx, o2 As Object
            Dim p1 As Long, p2 As Long
            ...
            Set o = New Cx
            Set o2 = o
            ...
            p1 = 0: p2 = 0
            o.Encoder p1, p2 ' Call by vtable => early binding
            p1 = 0: p2 = 0
            o2.Encoder p1, p2 ' Call by GetIdsOfName&Invoke => late binding
            p1 = 0: p2 = 0
            CallByName o, "Encoder", VbMethod, p1, p2 ' forcible late binding
            p1 = 0: p2 = 0
            CallByName o2, "Encoder", VbMethod, p1, p2

            ' Server's code - C++:

            STDMETHODIMP Cx::Encoder(/*[out]*/ long * Result, /*[out]*/ long * LastError)
            {
            *Result = 22;
            *LastError = 222;
            return S_OK;
            }

            With best wishes, Vita

            A Offline
            A Offline
            Anonymous
            wrote on last edited by
            #5

            Vi2 wrote: Really? ' Client's code - VB6:

            Dim o As Cx, o2 As Object Dim p1 As Long, p2 As Long ... Set o = New Cx Set o2 = o ... p1 = 0: p2 = 0 o.Encoder p1, p2 ' Call by vtable => early binding

            Vi2 wrote:

            STDMETHODIMP Cx::Encoder(/*[out]*/ long * Result, /*[out]*/ long * LastError)
            {	    
                        *Result = 22;	
                        *LastError = 222;	
                        return S_OK;
            }
            

            I don't think a call to Encoder from a VB6 client will work with the above Encoder definition. At least when I attempted to call Encoder from a VB client using the above Encoder definition in a C++ COM object the program crashed. Is this normal behavior? Or, am I overlooking something? Thanks,

            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