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. How to create an OLE control in EXCEL sheet?

How to create an OLE control in EXCEL sheet?

Scheduled Pinned Locked Moved COM
comhelptutorialquestion
16 Posts 2 Posters 3 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.
  • W whiteclouds

    Problem still exist. The value of hr is "E_NOINTERFACE". I feel very strange that the same operation can completed within Word. I check the interface declaration of CCASign many times. No mistake was found. Please continue to help me! Thank you!

    There is some white cloud floating on the blue sky. That's the landscape I like.

    B Offline
    B Offline
    barneyman
    wrote on last edited by
    #4

    what's the object written using? if it's ATL, use the _ATL_DEBUG_QI to watch for it being queried Not done much with Excel or Word, but it wouldn't surprise me if they use separate threading models, and the E_NOINTERFACE you're getting is because it can't get to an IMarshall interface have a look at http://msdn.microsoft.com/en-us/library/ms687205(v=vs.85).aspx[^]

    W 1 Reply Last reply
    0
    • B barneyman

      what's the object written using? if it's ATL, use the _ATL_DEBUG_QI to watch for it being queried Not done much with Excel or Word, but it wouldn't surprise me if they use separate threading models, and the E_NOINTERFACE you're getting is because it can't get to an IMarshall interface have a look at http://msdn.microsoft.com/en-us/library/ms687205(v=vs.85).aspx[^]

      W Offline
      W Offline
      whiteclouds
      wrote on last edited by
      #5

      My control is written in C++. I had read the article you recommand. My control's ThreadModel is Single-Threaded apartment. I had tried the other key-word. Only "Apartment" and "Both" can work. I think maybe I hadn't implement some methods, so the conversion is failure. I hope you can list all methods I must implement. Thank you!

      There is some white cloud floating on the blue sky. That's the landscape I like.

      B 1 Reply Last reply
      0
      • W whiteclouds

        My control is written in C++. I had read the article you recommand. My control's ThreadModel is Single-Threaded apartment. I had tried the other key-word. Only "Apartment" and "Both" can work. I think maybe I hadn't implement some methods, so the conversion is failure. I hope you can list all methods I must implement. Thank you!

        There is some white cloud floating on the blue sky. That's the landscape I like.

        B Offline
        B Offline
        barneyman
        wrote on last edited by
        #6

        ok - first things first - you need to find out if this is the problem If you're using ATL, enable the _ATL_DEBUG_QI define for the project - this will show you what your project is being queried for (as long as you are running your object under the debugger) If you're not using ATL, you'll have to change your QueryInterface method so it prints out interfaces that are requested, that it doesn't support

        W 1 Reply Last reply
        0
        • B barneyman

          ok - first things first - you need to find out if this is the problem If you're using ATL, enable the _ATL_DEBUG_QI define for the project - this will show you what your project is being queried for (as long as you are running your object under the debugger) If you're not using ATL, you'll have to change your QueryInterface method so it prints out interfaces that are requested, that it doesn't support

          W Offline
          W Offline
          whiteclouds
          wrote on last edited by
          #7

          I had add _ATL_DEBUG_QI define in my project. Then message below is output:

          CComClassFactory - IUnknown
          CComClassFactory - IClassFactory2 - failed
          CComClassFactory - IClassFactory
          CCASign - IDispatch
          CCASign - IConnectionPointContainer
          CCASign - IProvideClassInfo
          CCASign - IConnectionPointContainer
          CCASign - IProvideClassInfo
          CCASign - IOleObject
          CCASign - IOleControl
          CCASign - {049948D1-5686-11CF-8E0D-00AA00A74C5C} - failed
          CCASign - IPersistStreamInit
          CCASign - IConnectionPointContainer
          CCASign - IProvideClassInfo
          CCASign - IOleContainer - failed
          CCASign - IDataObject
          CCASign - IPersistPropertyBag - failed
          CCASign - IRunnableObject - failed
          ATL: IDataObjectImpl::QueryGetData not implemented.
          _CrtDbgReport: String too long or IO ErrorCCASign - IRunnableObject - failed
          CCASign - {049948D1-5686-11CF-8E0D-00AA00A74C5C} - failed
          CCASign - {049948D1-5686-11CF-8E0D-00AA00A74C5C} - failed
          CCASign - IRunnableObject - failed
          ATL: IDataObjectImpl::QueryGetData not implemented.
          _CrtDbgReport: String too long or IO ErrorCCASign - IRunnableObject - failed
          CCASign - IPersistStreamInit

          These message are output when calling Shapes.AddOleObject. I check the interface marked as fail. Such interfaces are not needed to implement except "{049948D1-5686-11CF-8E0D-00AA00A74C5C}". I don't know what interface is "{049948D1-5686-11CF-8E0D-00AA00A74C5C}". My own interface is registered already. And its CLSID isn't {049948D1-5686-11CF-8E0D-00AA00A74C5C}. Is this the reason of problem?

          There is some white cloud floating on the blue sky. That's the landscape I like.

          B 1 Reply Last reply
          0
          • W whiteclouds

            I had add _ATL_DEBUG_QI define in my project. Then message below is output:

            CComClassFactory - IUnknown
            CComClassFactory - IClassFactory2 - failed
            CComClassFactory - IClassFactory
            CCASign - IDispatch
            CCASign - IConnectionPointContainer
            CCASign - IProvideClassInfo
            CCASign - IConnectionPointContainer
            CCASign - IProvideClassInfo
            CCASign - IOleObject
            CCASign - IOleControl
            CCASign - {049948D1-5686-11CF-8E0D-00AA00A74C5C} - failed
            CCASign - IPersistStreamInit
            CCASign - IConnectionPointContainer
            CCASign - IProvideClassInfo
            CCASign - IOleContainer - failed
            CCASign - IDataObject
            CCASign - IPersistPropertyBag - failed
            CCASign - IRunnableObject - failed
            ATL: IDataObjectImpl::QueryGetData not implemented.
            _CrtDbgReport: String too long or IO ErrorCCASign - IRunnableObject - failed
            CCASign - {049948D1-5686-11CF-8E0D-00AA00A74C5C} - failed
            CCASign - {049948D1-5686-11CF-8E0D-00AA00A74C5C} - failed
            CCASign - IRunnableObject - failed
            ATL: IDataObjectImpl::QueryGetData not implemented.
            _CrtDbgReport: String too long or IO ErrorCCASign - IRunnableObject - failed
            CCASign - IPersistStreamInit

            These message are output when calling Shapes.AddOleObject. I check the interface marked as fail. Such interfaces are not needed to implement except "{049948D1-5686-11CF-8E0D-00AA00A74C5C}". I don't know what interface is "{049948D1-5686-11CF-8E0D-00AA00A74C5C}". My own interface is registered already. And its CLSID isn't {049948D1-5686-11CF-8E0D-00AA00A74C5C}. Is this the reason of problem?

            There is some white cloud floating on the blue sky. That's the landscape I like.

            B Offline
            B Offline
            barneyman
            wrote on last edited by
            #8

            your addoleobject call is succeeding You need to look at the debug trace when you call

            HRESULT hr=pObj.QueryInterface(&cpCASign);

            because that's the call that is failing

            W 1 Reply Last reply
            0
            • B barneyman

              your addoleobject call is succeeding You need to look at the debug trace when you call

              HRESULT hr=pObj.QueryInterface(&cpCASign);

              because that's the call that is failing

              W Offline
              W Offline
              whiteclouds
              wrote on last edited by
              #9

              I had make clear that the reason of problem is the interface I need i can't be queried. When the following code executed, nothing output.

              HRESULT hr=pObj.QueryInterface(&cpCASign);

              But i don't know how to fix it. Pls help me. Thx!

              There is some white cloud floating on the blue sky. That's the landscape I like.

              B 1 Reply Last reply
              0
              • W whiteclouds

                I had make clear that the reason of problem is the interface I need i can't be queried. When the following code executed, nothing output.

                HRESULT hr=pObj.QueryInterface(&cpCASign);

                But i don't know how to fix it. Pls help me. Thx!

                There is some white cloud floating on the blue sky. That's the landscape I like.

                B Offline
                B Offline
                barneyman
                wrote on last edited by
                #10

                ok - that would imply that the pObj you get back is not your object does excel manufacture some form of object-site object? looking at the vba excel docs, your object should also turn up in

                OLEObjects

                container; I would write some code to see if I get the same, or different behaviour i.e. Add object to shapes as you are currently doing then look for it in the OLEObjects container then QI that object for your interface

                modified on Tuesday, May 3, 2011 8:07 PM

                W 2 Replies Last reply
                0
                • B barneyman

                  ok - that would imply that the pObj you get back is not your object does excel manufacture some form of object-site object? looking at the vba excel docs, your object should also turn up in

                  OLEObjects

                  container; I would write some code to see if I get the same, or different behaviour i.e. Add object to shapes as you are currently doing then look for it in the OLEObjects container then QI that object for your interface

                  modified on Tuesday, May 3, 2011 8:07 PM

                  W Offline
                  W Offline
                  whiteclouds
                  wrote on last edited by
                  #11

                  Pleasure to see your reply. Thank you very much! Some days ago, I find a message at MSDN. It said that if you want to add an OLE object into Excel worksheet, you should call OLEObjects.Add(), not Shapes.AddOLEObject(), because Shapes encapsulate the OLEObject returned by AddOLEObject. So the next operation such as OLEFormat.get_Object() can't get the raw point of the object inserted. I had tried the way it recommend. But I can't get a OLEObjects from worksheet. I find that the reason of failure is the wrong LANGID parameter. I am trying to find the right parameter for it now. If you can't be success from the code above, you can try to do by this way. And if you know what parameter of LANGID is right, I will be very pleased to know it from you. :-D Sincerely

                  There is some white cloud floating on the blue sky. That's the landscape I like.

                  1 Reply Last reply
                  0
                  • B barneyman

                    ok - that would imply that the pObj you get back is not your object does excel manufacture some form of object-site object? looking at the vba excel docs, your object should also turn up in

                    OLEObjects

                    container; I would write some code to see if I get the same, or different behaviour i.e. Add object to shapes as you are currently doing then look for it in the OLEObjects container then QI that object for your interface

                    modified on Tuesday, May 3, 2011 8:07 PM

                    W Offline
                    W Offline
                    whiteclouds
                    wrote on last edited by
                    #12

                    The message I get tell me that I should call _WorkSheet.OLEObjects() to get an OLEObjects, then call OLEObjects.Add() to insert my own object. But I get an error whose code is 0x800A03EC. This means I should set the right CultureInfo before calling OLEObjects.Add(). But I can't find any hint to set it besides using .NET framework. Should I using .NET just for this? I had try to call GetSystemDefaultLCID() and ConvertDefaultLocale() to fix it. But the same error occurred. What shall I do?

                    There is some white cloud floating on the blue sky. That's the landscape I like.

                    B 1 Reply Last reply
                    0
                    • W whiteclouds

                      The message I get tell me that I should call _WorkSheet.OLEObjects() to get an OLEObjects, then call OLEObjects.Add() to insert my own object. But I get an error whose code is 0x800A03EC. This means I should set the right CultureInfo before calling OLEObjects.Add(). But I can't find any hint to set it besides using .NET framework. Should I using .NET just for this? I had try to call GetSystemDefaultLCID() and ConvertDefaultLocale() to fix it. But the same error occurred. What shall I do?

                      There is some white cloud floating on the blue sky. That's the landscape I like.

                      B Offline
                      B Offline
                      barneyman
                      wrote on last edited by
                      #13

                      I'm afraid I don't know - sorry ... Things *I* would look at ... 1. What interfaces are being queried from your object during the OLEObjects.Add; do any of those want or return an LCID - if no interfaces are being queried it may be something missing from your type library 2. I would try doing the Shapes.AddObject as before, but then querying the OLEObjects rather than the object shape returns - the docs suggest the object will turn up in both places 3. If neither of those got me anywhere, I'd start looking at the object Shapes.AddObject returned, querying it for standard container interfaces and see if i could get to the 'real' object underneath (IOleContainer for instance) best of luck

                      W 1 Reply Last reply
                      0
                      • B barneyman

                        I'm afraid I don't know - sorry ... Things *I* would look at ... 1. What interfaces are being queried from your object during the OLEObjects.Add; do any of those want or return an LCID - if no interfaces are being queried it may be something missing from your type library 2. I would try doing the Shapes.AddObject as before, but then querying the OLEObjects rather than the object shape returns - the docs suggest the object will turn up in both places 3. If neither of those got me anywhere, I'd start looking at the object Shapes.AddObject returned, querying it for standard container interfaces and see if i could get to the 'real' object underneath (IOleContainer for instance) best of luck

                        W Offline
                        W Offline
                        whiteclouds
                        wrote on last edited by
                        #14

                        Sorry, maybe I make you nervous. That's my fault. :) 1. Nothing output when I call OLEObjects.Add. Maybe it's because I call the Dispatch.Invoke() to add. The reason of I call Dispatch.Invoke() instead of OLEObjects.Add() is that an error of 0x800A03EC always occurred for OLEObjects.Add(). 2. I can't get the meaning of your second suggestion. You tell me to query OLEObjects at the object Shapes.AddObject returned? 3. Your meaning is that I should query some container interfaces such as IOleContainer for the object returned by Shapes.AddOLEObject(), isn't it? Why? By the way, the error of 0x800A03EC isn't means wrong cultureinfo. The correct meaning is that another operation background is executed on the same object. I must make the object such as button lost focus. This is a bug for Office 2003. :) Following is the explanation from Microsoft: http://support.microsoft.com/kb/823988/en-us[^][] I had try to do as the code provided by Microsoft. But nothing changed. I hope you can help me in advance. Thank you!

                        There is some white cloud floating on the blue sky. That's the landscape I like.

                        B 1 Reply Last reply
                        0
                        • W whiteclouds

                          Sorry, maybe I make you nervous. That's my fault. :) 1. Nothing output when I call OLEObjects.Add. Maybe it's because I call the Dispatch.Invoke() to add. The reason of I call Dispatch.Invoke() instead of OLEObjects.Add() is that an error of 0x800A03EC always occurred for OLEObjects.Add(). 2. I can't get the meaning of your second suggestion. You tell me to query OLEObjects at the object Shapes.AddObject returned? 3. Your meaning is that I should query some container interfaces such as IOleContainer for the object returned by Shapes.AddOLEObject(), isn't it? Why? By the way, the error of 0x800A03EC isn't means wrong cultureinfo. The correct meaning is that another operation background is executed on the same object. I must make the object such as button lost focus. This is a bug for Office 2003. :) Following is the explanation from Microsoft: http://support.microsoft.com/kb/823988/en-us[^][] I had try to do as the code provided by Microsoft. But nothing changed. I hope you can help me in advance. Thank you!

                          There is some white cloud floating on the blue sky. That's the landscape I like.

                          B Offline
                          B Offline
                          barneyman
                          wrote on last edited by
                          #15

                          2. make the previous

                          spShapes->AddOLEObject(ClassType,vEmpty,vEmpty,vtFalse,vEmpty,0,vEmpty,left,top,g_iCtrlInitWidth,g_iCtrlInitHeight);

                          call, but then look for your object in the OLEObjects() collection 3. Yes - I am assuming that Shape wraps your object in some form of container, so you *might* be able to get to that container, and ask IT for the enclosed object - alternatively, from within your IOleObject, find out what it's clientSite is, and see if that's the object Shape is giving you

                          W 1 Reply Last reply
                          0
                          • B barneyman

                            2. make the previous

                            spShapes->AddOLEObject(ClassType,vEmpty,vEmpty,vtFalse,vEmpty,0,vEmpty,left,top,g_iCtrlInitWidth,g_iCtrlInitHeight);

                            call, but then look for your object in the OLEObjects() collection 3. Yes - I am assuming that Shape wraps your object in some form of container, so you *might* be able to get to that container, and ask IT for the enclosed object - alternatively, from within your IOleObject, find out what it's clientSite is, and see if that's the object Shape is giving you

                            W Offline
                            W Offline
                            whiteclouds
                            wrote on last edited by
                            #16

                            Hi, barneyman. I had fixed this problem. The reason of problem is that I missed a procedure. The right step is: 1. Get a pointer of OLEFormat with calling Shape.get_OLEFormat() 2. Get a pointer of _OLEObject with calling OLEFormat.get_Object() 3. Get a pointer of Dispatch with calling _OLEObject.get_Object() 4. Convert the Dispatch to my own object's pointer. Thank you for waste your time to help me. I hope I could get more help from you later! Good luck!

                            There is some white cloud floating on the blue sky. That's the landscape I like.

                            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