default properties on COM interfaces
-
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
-
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
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 callingCComObject<CField>* pFld; hRes = CComObject<CField>::CreateInstance(&pFld);
inSegment
, that line should be**set** fld = msg.Segment.Field
. Thenfld = "blah"
is ok. Because now field is refering to an active instance of IField in 'msg.Segment' Sameway ifmsg.Segment.Field = "blahh"
gives a type mismatch error, thenmsg.Segment.Field
might not be an active instance, make sure u had calledhRes = CComObject<CField>::CreateInstance(&pFld);
does this make sense...? best wishes ... 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 callingCComObject<CField>* pFld; hRes = CComObject<CField>::CreateInstance(&pFld);
inSegment
, that line should be**set** fld = msg.Segment.Field
. Thenfld = "blah"
is ok. Because now field is refering to an active instance of IField in 'msg.Segment' Sameway ifmsg.Segment.Field = "blahh"
gives a type mismatch error, thenmsg.Segment.Field
might not be an active instance, make sure u had calledhRes = CComObject<CField>::CreateInstance(&pFld);
does this make sense...? best wishes ... mil10.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
-
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
Try to debug into
CField::put_Value
from vb exe and see what is happening insideCField::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 codemsg.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 inCField::put_Value
, then run the ATL project by F5. best wishes..mil10 -
Try to debug into
CField::put_Value
from vb exe and see what is happening insideCField::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 codemsg.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 inCField::put_Value
, then run the ATL project by F5. best wishes..mil10I 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
-
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
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
-
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
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
-
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
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