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. expression cannot be evaluated:0x0046d5b0 _com_error

expression cannot be evaluated:0x0046d5b0 _com_error

Scheduled Pinned Locked Moved COM
comdebugginghelpquestionlearning
13 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.
  • G gtag

    Hi, Again I am here with new one. Following is the code , I am attaching the instance of excel to active excel. Excel::_ApplicationPtr XL;      Excel::_WorkbookPtr book;      string XLWBName; try      {      CoInitialize(NULL);      HRESULT hr = XL.GetActiveObject(_T("Excel.Application"));                book = XL->;Workbooks->;Item[1];           XLWBName = book->Name;                     return true;      }      catch(_com_error &error)      {           cout << "COM error"<< endl;             return false;      } I implemented this in two applications: In 1st application it is working perfectly , after coinitialize i kept the breakpoint then it is called 2 methods from comip.h 1st is:HRESULT GetActiveObject(const CLSID& rclsid) throw() 2nd is: HRESULT GetActiveObject(LPCWSTR clsidString) throw() In 2nd application it is not working and checked the sequence of methods calling from comip.h, its calling only one method that is : HRESULT GetActiveObject(LPCWSTR clsidString) throw() Checked the value of book and other instances: ((*(IUnknown*)(&(*(IDispatch*)(&*((book).m_pInterface)))))).__vfptr __vfptr = CXX0030: Error: expression cannot be evaluated [0] = 0x0046d5b0 _com_error::`scalar deleting destructor'(unsigned int) __vfptr = 0x004f5af4 const _com_error::`vftable' please give me clue where I am doing wrong or something need to be added? Regards, Gtag

    S Offline
    S Offline
    Stuart Dootson
    wrote on last edited by
    #2

    Is the second application compiled with Unicode turned on? Because your passing an LPCTSTR (which can be ASCII or Unicode, depending on pre-processor macro settings) to GetActiveObject, where you are meant to pass an LPCWSTR

    Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

    G 1 Reply Last reply
    0
    • S Stuart Dootson

      Is the second application compiled with Unicode turned on? Because your passing an LPCTSTR (which can be ASCII or Unicode, depending on pre-processor macro settings) to GetActiveObject, where you are meant to pass an LPCWSTR

      Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

      G Offline
      G Offline
      gtag
      wrote on last edited by
      #3

      Sorry I am new to this, I searched for this option, i didn't find it? Please tell me where I can find this option in Microsoft visual studio 2008(Professional edition). Regards, gtag

      S 1 Reply Last reply
      0
      • G gtag

        Sorry I am new to this, I searched for this option, i didn't find it? Please tell me where I can find this option in Microsoft visual studio 2008(Professional edition). Regards, gtag

        S Offline
        S Offline
        Stuart Dootson
        wrote on last edited by
        #4

        Don't worry too much about that - just make sure you use

        L"Excel.Application"

        instead of

        _T("Excel.Application")

        Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

        G 1 Reply Last reply
        0
        • S Stuart Dootson

          Don't worry too much about that - just make sure you use

          L"Excel.Application"

          instead of

          _T("Excel.Application")

          Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

          G Offline
          G Offline
          gtag
          wrote on last edited by
          #5

          I changed it , but same issue. Is there any other way? Regards, Gtag

          S 1 Reply Last reply
          0
          • G gtag

            I changed it , but same issue. Is there any other way? Regards, Gtag

            S Offline
            S Offline
            Stuart Dootson
            wrote on last edited by
            #6

            What HRESULT was returned from GetActiveObject? Was Excel running when you did the GetActiveObject call?

            Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

            G 1 Reply Last reply
            0
            • S Stuart Dootson

              What HRESULT was returned from GetActiveObject? Was Excel running when you did the GetActiveObject call?

              Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

              G Offline
              G Offline
              gtag
              wrote on last edited by
              #7

              hr = 0x800401e3 Operation unavailable Excel was running. With other application I can attach with both option s _T or L. Even can read xlworksheet names and all. Regards, Gtag

              S 1 Reply Last reply
              0
              • G gtag

                hr = 0x800401e3 Operation unavailable Excel was running. With other application I can attach with both option s _T or L. Even can read xlworksheet names and all. Regards, Gtag

                S Offline
                S Offline
                Stuart Dootson
                wrote on last edited by
                #8

                gtag wrote:

                hr = 0x800401e3 Operation unavailable

                Right - well that explains why you weren't getting a pointer to the Excel application. Doing a quick Google (you know, like you could have done) brings up this MS support page[^] which deals with your scenario.

                Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

                G 1 Reply Last reply
                0
                • S Stuart Dootson

                  gtag wrote:

                  hr = 0x800401e3 Operation unavailable

                  Right - well that explains why you weren't getting a pointer to the Excel application. Doing a quick Google (you know, like you could have done) brings up this MS support page[^] which deals with your scenario.

                  Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

                  G Offline
                  G Offline
                  gtag
                  wrote on last edited by
                  #9

                  Surely I will check out the blog u mentioned. After doing little analysis on both the applications I have got few inputs for not getting attached to active object, but solution I couldn't? Following are the functions called from comip.h HRESULT GetActiveObject(const CLSID& rclsid) throw()       {           _Release();             IUnknown* pIUnknown;             HRESULT hr = ::GetActiveObject(rclsid, NULL, &pIUnknown);             if (SUCCEEDED(hr)) {                   hr = pIUnknown->QueryInterface(GetIID(), reinterpret_cast<void**>(&m_pInterface));                   pIUnknown->Release();             }             if (FAILED(hr)) {                   // just in case refcount = 0 and dtor gets called                   m_pInterface = NULL;             }             return hr;       }       // Attach to the active object specified by clsidString.       // First convert the LPCWSTR to a CLSID.       //       HRESULT GetActiveObject(LPCWSTR clsidString) throw()       {             if (clsidString == NULL) {                   return E_INVALIDARG;             }             CLSID clsid;             HRESULT hr;             if (clsidString[0] == '{') {                   hr = CLSIDFromString(const_cast<LPWSTR> (clsidString), &clsid);             }             else {             &nb

                  S G 2 Replies Last reply
                  0
                  • G gtag

                    Surely I will check out the blog u mentioned. After doing little analysis on both the applications I have got few inputs for not getting attached to active object, but solution I couldn't? Following are the functions called from comip.h HRESULT GetActiveObject(const CLSID& rclsid) throw()       {           _Release();             IUnknown* pIUnknown;             HRESULT hr = ::GetActiveObject(rclsid, NULL, &pIUnknown);             if (SUCCEEDED(hr)) {                   hr = pIUnknown->QueryInterface(GetIID(), reinterpret_cast<void**>(&m_pInterface));                   pIUnknown->Release();             }             if (FAILED(hr)) {                   // just in case refcount = 0 and dtor gets called                   m_pInterface = NULL;             }             return hr;       }       // Attach to the active object specified by clsidString.       // First convert the LPCWSTR to a CLSID.       //       HRESULT GetActiveObject(LPCWSTR clsidString) throw()       {             if (clsidString == NULL) {                   return E_INVALIDARG;             }             CLSID clsid;             HRESULT hr;             if (clsidString[0] == '{') {                   hr = CLSIDFromString(const_cast<LPWSTR> (clsidString), &clsid);             }             else {             &nb

                    S Offline
                    S Offline
                    Stuart Dootson
                    wrote on last edited by
                    #10

                    Read the page I pointed you at. Don't bother digging through the Microsoft library code - the error is not in that.

                    Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

                    1 Reply Last reply
                    0
                    • G gtag

                      Surely I will check out the blog u mentioned. After doing little analysis on both the applications I have got few inputs for not getting attached to active object, but solution I couldn't? Following are the functions called from comip.h HRESULT GetActiveObject(const CLSID& rclsid) throw()       {           _Release();             IUnknown* pIUnknown;             HRESULT hr = ::GetActiveObject(rclsid, NULL, &pIUnknown);             if (SUCCEEDED(hr)) {                   hr = pIUnknown->QueryInterface(GetIID(), reinterpret_cast<void**>(&m_pInterface));                   pIUnknown->Release();             }             if (FAILED(hr)) {                   // just in case refcount = 0 and dtor gets called                   m_pInterface = NULL;             }             return hr;       }       // Attach to the active object specified by clsidString.       // First convert the LPCWSTR to a CLSID.       //       HRESULT GetActiveObject(LPCWSTR clsidString) throw()       {             if (clsidString == NULL) {                   return E_INVALIDARG;             }             CLSID clsid;             HRESULT hr;             if (clsidString[0] == '{') {                   hr = CLSIDFromString(const_cast<LPWSTR> (clsidString), &clsid);             }             else {             &nb

                      G Offline
                      G Offline
                      gtag
                      wrote on last edited by
                      #11

                      NO, I am getting same error value in hr. I am still trying. As I am mentioned in above , "_Release();"   is not getting called. I checked in other app where it is working if I right click on _Release() and see the definition , nothing is reflecting overthere but when I did the same thing in current app(where its not working) , symbols are not loaded it is showing. Is this the issue? Regards, Gtag

                      G 1 Reply Last reply
                      0
                      • G gtag

                        NO, I am getting same error value in hr. I am still trying. As I am mentioned in above , "_Release();"   is not getting called. I checked in other app where it is working if I right click on _Release() and see the definition , nothing is reflecting overthere but when I did the same thing in current app(where its not working) , symbols are not loaded it is showing. Is this the issue? Regards, Gtag

                        G Offline
                        G Offline
                        gtag
                        wrote on last edited by
                        #12

                        I tried the solution mentioned in the blog posted by u, but hr value I am getting same. Even intellisense is not working in comip.h. But it is working in other project. If you get any clue , then please let me know. Thanks in advance. Regards, GTag.

                        modified on Monday, September 21, 2009 5:24 AM

                        G 1 Reply Last reply
                        0
                        • G gtag

                          I tried the solution mentioned in the blog posted by u, but hr value I am getting same. Even intellisense is not working in comip.h. But it is working in other project. If you get any clue , then please let me know. Thanks in advance. Regards, GTag.

                          modified on Monday, September 21, 2009 5:24 AM

                          G Offline
                          G Offline
                          gtag
                          wrote on last edited by
                          #13

                          Hi Stuart, Thanks for helping me in this issue. Today I resolved the issue. It has to do with security, as my application is having service which runs under "System" user name and Excel runs under other login not system, so it was not accessing excel under other login. Now I am able to access active object. Thanks once again.

                          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