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. default properties on COM interfaces

default properties on COM interfaces

Scheduled Pinned Locked Moved COM
comhelptutorialquestion
8 Posts 3 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.
  • D Offline
    D Offline
    Dave Bryant
    wrote on last edited by
    #1

    I've encountered a probably setting a default property on a COM interface I am generating. This interface, IField, is generating dynamically from my application, and extends another of my interfaces, IMessageComponent (also generated dynamically, which inherits from IDispatch). I want to make the Value property (which is read/write) the default of the IField interface, so i've the the ID to zero. When using it from VB6, it sometimes works. It always works if I am reading the value from the default property. e.g. str = msg.Segment.Field This always works However, when setting the value it does not work if there the object is set indirectly. For example: Dim fld As Test.Field fld = msg.Segment.Field fld = "blah" This always works msg.Segment.Field = "blah" This never works works - VB always gives a compile-time type mismatch error. Has anyone encountered this previously and know of a workaround? Cheers Dave http://www.cloudsofheaven.org

    M V 2 Replies Last reply
    0
    • D Dave Bryant

      I've encountered a probably setting a default property on a COM interface I am generating. This interface, IField, is generating dynamically from my application, and extends another of my interfaces, IMessageComponent (also generated dynamically, which inherits from IDispatch). I want to make the Value property (which is read/write) the default of the IField interface, so i've the the ID to zero. When using it from VB6, it sometimes works. It always works if I am reading the value from the default property. e.g. str = msg.Segment.Field This always works However, when setting the value it does not work if there the object is set indirectly. For example: Dim fld As Test.Field fld = msg.Segment.Field fld = "blah" This always works msg.Segment.Field = "blah" This never works works - VB always gives a compile-time type mismatch error. Has anyone encountered this previously and know of a workaround? Cheers Dave http://www.cloudsofheaven.org

      M Offline
      M Offline
      Mil10
      wrote on last edited by
      #2

      Hi Dave, Dim fld As Test.Field fld = msg.Segment.Field fld = "blah" This always works I couldn't understand how the code above works without error. Because 'fld' is just a variable of type IField, not an instance of IField. So the statement 'fld = msg.Segment.Field' shouldn't work. Even if u r calling CComObject<CField>* pFld; hRes = CComObject<CField>::CreateInstance(&pFld); in Segment, that line should be **set** fld = msg.Segment.Field. Then fld = "blah" is ok. Because now field is refering to an active instance of IField in 'msg.Segment' Sameway if msg.Segment.Field = "blahh" gives a type mismatch error, then msg.Segment.Field might not be an active instance, make sure u had called hRes = CComObject<CField>::CreateInstance(&pFld); does this make sense...? best wishes ... mil10.

      D 1 Reply Last reply
      0
      • M Mil10

        Hi Dave, Dim fld As Test.Field fld = msg.Segment.Field fld = "blah" This always works I couldn't understand how the code above works without error. Because 'fld' is just a variable of type IField, not an instance of IField. So the statement 'fld = msg.Segment.Field' shouldn't work. Even if u r calling CComObject<CField>* pFld; hRes = CComObject<CField>::CreateInstance(&pFld); in Segment, that line should be **set** fld = msg.Segment.Field. Then fld = "blah" is ok. Because now field is refering to an active instance of IField in 'msg.Segment' Sameway if msg.Segment.Field = "blahh" gives a type mismatch error, then msg.Segment.Field might not be an active instance, make sure u had called hRes = CComObject<CField>::CreateInstance(&pFld); does this make sense...? best wishes ... mil10.

        D Offline
        D Offline
        Dave Bryant
        wrote on last edited by
        #3

        You're right, the line should be "set fld = msg.Segment.Field" - it was that in my VB code, but as I am a C++ programmer, not a VB 'programmer', i forgot it when i wrote that message. However, i can guarrantee that the object does always exist - that's why I don't understand why it doesn't work... Anyway, I'm just looking for ideas... Dave http://www.cloudsofheaven.org

        M 1 Reply Last reply
        0
        • D Dave Bryant

          You're right, the line should be "set fld = msg.Segment.Field" - it was that in my VB code, but as I am a C++ programmer, not a VB 'programmer', i forgot it when i wrote that message. However, i can guarrantee that the object does always exist - that's why I don't understand why it doesn't work... Anyway, I'm just looking for ideas... Dave http://www.cloudsofheaven.org

          M Offline
          M Offline
          Mil10
          wrote on last edited by
          #4

          Try to debug into CField::put_Value from vb exe and see what is happening inside CField::put_Value . Since u r not a vb prgmr , i donno whether u familier with debugging into an atl dll from vb. anyway FYI - Just create the vb app with the code msg.Segment.Field = "blahh" into an EXE. Then change ATL project build setting to Win32Debug Goto "Project->Settings->Debug->Executable for debug session:" and browse the VB exe path into the text field. Put break point in CField::put_Value , then run the ATL project by F5. best wishes..mil10

          D 1 Reply Last reply
          0
          • M Mil10

            Try to debug into CField::put_Value from vb exe and see what is happening inside CField::put_Value . Since u r not a vb prgmr , i donno whether u familier with debugging into an atl dll from vb. anyway FYI - Just create the vb app with the code msg.Segment.Field = "blahh" into an EXE. Then change ATL project build setting to Win32Debug Goto "Project->Settings->Debug->Executable for debug session:" and browse the VB exe path into the text field. Put break point in CField::put_Value , then run the ATL project by F5. best wishes..mil10

            D Offline
            D Offline
            Dave Bryant
            wrote on last edited by
            #5

            I do know how to debug from VB, but unfortunately it's not going to help here. It's a compile error, not a runtime error. Dave http://www.cloudsofheaven.org

            M 1 Reply Last reply
            0
            • D Dave Bryant

              I do know how to debug from VB, but unfortunately it's not going to help here. It's a compile error, not a runtime error. Dave http://www.cloudsofheaven.org

              M Offline
              M Offline
              Mil10
              wrote on last edited by
              #6

              Seems very strange..if u mind to send me the source code I am ok to debug. otherwise try unregister/reregister or more safely try on another mechine. Because I had faced almost simialr prblm early. Initialy the DISP_ID was 1. After registration with 1, I changed it to 0 to set it as default. Again registred the component but, showed err in my mechine but worked fine in another mechine( with fresh registry entries). best wishes..mil10

              D 1 Reply Last reply
              0
              • M Mil10

                Seems very strange..if u mind to send me the source code I am ok to debug. otherwise try unregister/reregister or more safely try on another mechine. Because I had faced almost simialr prblm early. Initialy the DISP_ID was 1. After registration with 1, I changed it to 0 to set it as default. Again registred the component but, showed err in my mechine but worked fine in another mechine( with fresh registry entries). best wishes..mil10

                D Offline
                D Offline
                Dave Bryant
                wrote on last edited by
                #7

                Thanks for the offer, but don't worry about it. I'll give it a go on a clean machine and see what happens. If that doesn't work, then i'll just leave it as is - the default property would be a nice extra to have, but it can still be used fine without it. Thanks a lot for your help. Dave http://www.cloudsofheaven.org

                1 Reply Last reply
                0
                • D Dave Bryant

                  I've encountered a probably setting a default property on a COM interface I am generating. This interface, IField, is generating dynamically from my application, and extends another of my interfaces, IMessageComponent (also generated dynamically, which inherits from IDispatch). I want to make the Value property (which is read/write) the default of the IField interface, so i've the the ID to zero. When using it from VB6, it sometimes works. It always works if I am reading the value from the default property. e.g. str = msg.Segment.Field This always works However, when setting the value it does not work if there the object is set indirectly. For example: Dim fld As Test.Field fld = msg.Segment.Field fld = "blah" This always works msg.Segment.Field = "blah" This never works works - VB always gives a compile-time type mismatch error. Has anyone encountered this previously and know of a workaround? Cheers Dave http://www.cloudsofheaven.org

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

                  Because "Field" property gives an object (some interface like IField or IDispatch), the VB makes some additional action. fld = "blah" This always works because the VB cannot assign the string value to the object variable. He should call some method(property) for this. And this action is a calling of property-by-default (with dispid=0) if this property is presented by the object. msg.Segment.Field = "blah" This never works because the VB will call the "Field" property of msg.Segment object with parameter which equals to "blah". It gives the compilation error because probably the "Field" property does not have the parameters. Try the following construction msg.Segment.Field() = "blah" With best wishes, Vita

                  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