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. C / C++ / MFC
  4. HRESULT variable returning negative value

HRESULT variable returning negative value

Scheduled Pinned Locked Moved C / C++ / MFC
c++comsysadmintutorial
13 Posts 6 Posters 2 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.
  • U User 14466593

    Greetings. I'm a newbie here and also into C++ programming but I would like to say this is a very helpful site to watch and learn and I would like to thank to all you out there for sharing your knowledge. As part of my interests about C++ and COM objects I was looking some tutorials and I have found this one nicely done: COM from scratch - PART TWO[^] I'm trying to re-create the client part of the improved example but it's not working. When I tried to do some debugging I was looking at some values and I've found this:

    hr=-2147221164

    Looking for some explanation I made some research and I understood that -among other things- this might be happening because of some uninitialized pointers, but I tried that suggestion and still no luck with MSVS 2008 and this simple code for a client-server application.

    //-----------//
    // Client
    //-----------//
    void main()

    {
    HRESULT hr;
    IUnknown* pIUnknown;
    IComponent* pIComponent;
    IClassFactory* pIClassFactory;

    ::CoInitialize(NULL);
    /\*
    //Once the CoCreateInstance is called, the component 
    //will be created and the client can not 
    //control it, that's why CoCreateInstance is inflexible 
    //and the solution is to call CoGetClassObject function
    hr = ::CoCreateInstance(CLSID\_Component,NULL,
            CLSCTX\_INPROC\_SERVER,IID\_IUnknown,(void\*\*)&pIUnknown) ; 
    if (SUCCEEDED(hr))
        {
            hr=pIUnknown->QueryInterface(IID\_IComponent,(void\*\*)&pIComponent);
            if(SUCCEEDED(hr))
               pIComponent->Print("COM from scratch.");
        }
    
     \*/ 
    //-------------------------------//
    // improvement of the client code
    //------------------------------//
    // By calling the CoGetClassObject function, the client can control
    // creation of the component
    hr=CoGetClassObject(CLSID\_Component,CLSCTX\_INPROC\_SERVER, 
                 NULL,IID\_IClassFactory,(void\*\*)&pIClassFactory);
    if (SUCCEEDED(hr))
    {
        hr=pIClassFactory->CreateInstance(NULL,
                IID\_IComponent,(void\*\*)&pIComponent);
        if(SUCCEEDED(hr))
           pIComponent->Print("COM from scratch.");
    }
    
    ::CoUninitialize ();
    

    }

    What could be the reason(s) this

    hr

    variable is retu

    J Offline
    J Offline
    jeron1
    wrote on last edited by
    #2

    Perhaps there's something useful in the following thread. https://www.codeproject.com/Answers/779932/Class-not-registered-Exception-from-HRESULT-x-REGD#answer2

    "the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst "I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle

    1 Reply Last reply
    0
    • U User 14466593

      Greetings. I'm a newbie here and also into C++ programming but I would like to say this is a very helpful site to watch and learn and I would like to thank to all you out there for sharing your knowledge. As part of my interests about C++ and COM objects I was looking some tutorials and I have found this one nicely done: COM from scratch - PART TWO[^] I'm trying to re-create the client part of the improved example but it's not working. When I tried to do some debugging I was looking at some values and I've found this:

      hr=-2147221164

      Looking for some explanation I made some research and I understood that -among other things- this might be happening because of some uninitialized pointers, but I tried that suggestion and still no luck with MSVS 2008 and this simple code for a client-server application.

      //-----------//
      // Client
      //-----------//
      void main()

      {
      HRESULT hr;
      IUnknown* pIUnknown;
      IComponent* pIComponent;
      IClassFactory* pIClassFactory;

      ::CoInitialize(NULL);
      /\*
      //Once the CoCreateInstance is called, the component 
      //will be created and the client can not 
      //control it, that's why CoCreateInstance is inflexible 
      //and the solution is to call CoGetClassObject function
      hr = ::CoCreateInstance(CLSID\_Component,NULL,
              CLSCTX\_INPROC\_SERVER,IID\_IUnknown,(void\*\*)&pIUnknown) ; 
      if (SUCCEEDED(hr))
          {
              hr=pIUnknown->QueryInterface(IID\_IComponent,(void\*\*)&pIComponent);
              if(SUCCEEDED(hr))
                 pIComponent->Print("COM from scratch.");
          }
      
       \*/ 
      //-------------------------------//
      // improvement of the client code
      //------------------------------//
      // By calling the CoGetClassObject function, the client can control
      // creation of the component
      hr=CoGetClassObject(CLSID\_Component,CLSCTX\_INPROC\_SERVER, 
                   NULL,IID\_IClassFactory,(void\*\*)&pIClassFactory);
      if (SUCCEEDED(hr))
      {
          hr=pIClassFactory->CreateInstance(NULL,
                  IID\_IComponent,(void\*\*)&pIComponent);
          if(SUCCEEDED(hr))
             pIComponent->Print("COM from scratch.");
      }
      
      ::CoUninitialize ();
      

      }

      What could be the reason(s) this

      hr

      variable is retu

      J Offline
      J Offline
      jeron1
      wrote on last edited by
      #3

      Perhaps there is something useful in this[^] thread.

      "the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst "I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle

      U 1 Reply Last reply
      0
      • J jeron1

        Perhaps there is something useful in this[^] thread.

        "the debugger doesn't tell me anything because this code compiles just fine" - random QA comment "Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst "I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle

        U Offline
        U Offline
        User 14466593
        wrote on last edited by
        #4

        Hey, thank you very much for that fast reply. I saw that discussion and I see all those errors are related to a poor server registration. In my case, I double checked that my server is registered when I was doing some debugging. If you see the paths provided in the sources there is certainly something like this:

        REGEDIT
        HKEY_CLASSES_ROOT\Codeproject.Component.1 =
        Codeproject Component Version 1.0
        HKEY_CLASSES_ROOT\Codeproject.Component.1\CLSID =
        {49BF12F1-5041-48da-9B44-AA2FAA63AEFB}
        HKEY_CLASSES_ROOT\Codeproject.Component = Codeproject Component
        HKEY_CLASSES_ROOT\Codeproject.Component\CurVer = Codeproject.Component.1
        HKEY_CLASSES_ROOT\CLSID\{49BF12F1-5041-48da-9B44-AA2FAA63AEFB} =
        Codeproject Component 1.0
        HKEY_CLASSES_ROOT\CLSID\{49BF12F1-5041-48da-9B44-AA2FAA63AEFB}\InprocServer32 =
        c:\codeproject\component.dll
        HKEY_CLASSES_ROOT\CLSID\{49BF12F1-5041-48da-9B44-AA2FAA63AEFB}\ProgID =
        Codeproject.Component.1
        HKEY_CLASSES_ROOT\CLSID\{49BF12F1-5041-48da-9B44-AA2FAA63AEFB}\
        VersionIndependentProgID = Codeproject.Component

        All my entries are OK with my server registered so I suppose the problem is somewhere but I can't find it because my lack of expertise. Looking at the MSDN/documentation the value expected should be one of these:

        S_OK
        Location and connection to the specified class object was successful.

        REGDB_E_CLASSNOTREG
        The CLSID is not properly registered. This error can also indicate that the value you specified in dwClsContext is not in the registry.

        E_NOINTERFACE
        Either the object pointed to by ppv does not support the interface identified by riid, or the QueryInterface operation on the class object returned E_NOINTERFACE.

        REGDB_E_READREGDB
        There was an error reading the registration database.

        CO_E_DLLNOTFOUND
        Either the in-process DLL or handler DLL was not found (depending on the context).

        CO_E_APPNOTFOUND
        The executable (.exe) was not found (CLSCTX_LOCAL_SERVER only).

        E_ACCESSDENIED
        There was a general access failure on load.

        CO_E_ERRORINDLL
        There is an error in the executable image.

        CO_E_APPDIDNTREG
        The executable was launched, but it did not register the class object (and it may have shut down).

        and not that negative value

        hr=-2147221164

        What could be happening with this variable

        hr

        if all variables/pointers are initialized and the server/COM Object is well registered

        1 Reply Last reply
        0
        • U User 14466593

          Greetings. I'm a newbie here and also into C++ programming but I would like to say this is a very helpful site to watch and learn and I would like to thank to all you out there for sharing your knowledge. As part of my interests about C++ and COM objects I was looking some tutorials and I have found this one nicely done: COM from scratch - PART TWO[^] I'm trying to re-create the client part of the improved example but it's not working. When I tried to do some debugging I was looking at some values and I've found this:

          hr=-2147221164

          Looking for some explanation I made some research and I understood that -among other things- this might be happening because of some uninitialized pointers, but I tried that suggestion and still no luck with MSVS 2008 and this simple code for a client-server application.

          //-----------//
          // Client
          //-----------//
          void main()

          {
          HRESULT hr;
          IUnknown* pIUnknown;
          IComponent* pIComponent;
          IClassFactory* pIClassFactory;

          ::CoInitialize(NULL);
          /\*
          //Once the CoCreateInstance is called, the component 
          //will be created and the client can not 
          //control it, that's why CoCreateInstance is inflexible 
          //and the solution is to call CoGetClassObject function
          hr = ::CoCreateInstance(CLSID\_Component,NULL,
                  CLSCTX\_INPROC\_SERVER,IID\_IUnknown,(void\*\*)&pIUnknown) ; 
          if (SUCCEEDED(hr))
              {
                  hr=pIUnknown->QueryInterface(IID\_IComponent,(void\*\*)&pIComponent);
                  if(SUCCEEDED(hr))
                     pIComponent->Print("COM from scratch.");
              }
          
           \*/ 
          //-------------------------------//
          // improvement of the client code
          //------------------------------//
          // By calling the CoGetClassObject function, the client can control
          // creation of the component
          hr=CoGetClassObject(CLSID\_Component,CLSCTX\_INPROC\_SERVER, 
                       NULL,IID\_IClassFactory,(void\*\*)&pIClassFactory);
          if (SUCCEEDED(hr))
          {
              hr=pIClassFactory->CreateInstance(NULL,
                      IID\_IComponent,(void\*\*)&pIComponent);
              if(SUCCEEDED(hr))
                 pIComponent->Print("COM from scratch.");
          }
          
          ::CoUninitialize ();
          

          }

          What could be the reason(s) this

          hr

          variable is retu

          V Offline
          V Offline
          Victor Nijegorodov
          wrote on last edited by
          #5

          From MSDN:

          Quote:

          REGDB_E_CLASSNOTREG 0x80040154 Class not registered

          Haven't you registered it? Or did you mix something related 32/64bit?

          U 1 Reply Last reply
          0
          • V Victor Nijegorodov

            From MSDN:

            Quote:

            REGDB_E_CLASSNOTREG 0x80040154 Class not registered

            Haven't you registered it? Or did you mix something related 32/64bit?

            U Offline
            U Offline
            User 14466593
            wrote on last edited by
            #6

            Hey Victor, nice to see you around. Yes, I have registered the server. First, I did it with the script provided by the tutorial (you may take a look at my previous messages), then I made a double check manually comparing the registry entries and it was running perfectly. I'm using for this project MSVS 2008 to avoid problems because the tutorial is very old (2004) and everything is kind of mandatory with the Win32 target (no x64 builds). I'm confused, if not registered (but it is), I should get the something like this

            REGDB_E_CLASSNOTREG
            //The CLSID is not properly registered. This error can also indicate that the value you specified in dwClsContext is not in the registry.

            This is ackward for

            hr=-2147221164

            and a successful server/COM Object registration.

            L 1 Reply Last reply
            0
            • U User 14466593

              Hey Victor, nice to see you around. Yes, I have registered the server. First, I did it with the script provided by the tutorial (you may take a look at my previous messages), then I made a double check manually comparing the registry entries and it was running perfectly. I'm using for this project MSVS 2008 to avoid problems because the tutorial is very old (2004) and everything is kind of mandatory with the Win32 target (no x64 builds). I'm confused, if not registered (but it is), I should get the something like this

              REGDB_E_CLASSNOTREG
              //The CLSID is not properly registered. This error can also indicate that the value you specified in dwClsContext is not in the registry.

              This is ackward for

              hr=-2147221164

              and a successful server/COM Object registration.

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #7

              It is not a negative integer, it is a hexadecimal status code. Convert it to its proper value and you can see what it represents.

              J 1 Reply Last reply
              0
              • L Lost User

                It is not a negative integer, it is a hexadecimal status code. Convert it to its proper value and you can see what it represents.

                J Offline
                J Offline
                jschell
                wrote on last edited by
                #8

                And get into the habit of doing that all the time also.

                L 1 Reply Last reply
                0
                • J jschell

                  And get into the habit of doing that all the time also.

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #9

                  I have been, for more than 20 years. ;)

                  1 Reply Last reply
                  0
                  • U User 14466593

                    Greetings. I'm a newbie here and also into C++ programming but I would like to say this is a very helpful site to watch and learn and I would like to thank to all you out there for sharing your knowledge. As part of my interests about C++ and COM objects I was looking some tutorials and I have found this one nicely done: COM from scratch - PART TWO[^] I'm trying to re-create the client part of the improved example but it's not working. When I tried to do some debugging I was looking at some values and I've found this:

                    hr=-2147221164

                    Looking for some explanation I made some research and I understood that -among other things- this might be happening because of some uninitialized pointers, but I tried that suggestion and still no luck with MSVS 2008 and this simple code for a client-server application.

                    //-----------//
                    // Client
                    //-----------//
                    void main()

                    {
                    HRESULT hr;
                    IUnknown* pIUnknown;
                    IComponent* pIComponent;
                    IClassFactory* pIClassFactory;

                    ::CoInitialize(NULL);
                    /\*
                    //Once the CoCreateInstance is called, the component 
                    //will be created and the client can not 
                    //control it, that's why CoCreateInstance is inflexible 
                    //and the solution is to call CoGetClassObject function
                    hr = ::CoCreateInstance(CLSID\_Component,NULL,
                            CLSCTX\_INPROC\_SERVER,IID\_IUnknown,(void\*\*)&pIUnknown) ; 
                    if (SUCCEEDED(hr))
                        {
                            hr=pIUnknown->QueryInterface(IID\_IComponent,(void\*\*)&pIComponent);
                            if(SUCCEEDED(hr))
                               pIComponent->Print("COM from scratch.");
                        }
                    
                     \*/ 
                    //-------------------------------//
                    // improvement of the client code
                    //------------------------------//
                    // By calling the CoGetClassObject function, the client can control
                    // creation of the component
                    hr=CoGetClassObject(CLSID\_Component,CLSCTX\_INPROC\_SERVER, 
                                 NULL,IID\_IClassFactory,(void\*\*)&pIClassFactory);
                    if (SUCCEEDED(hr))
                    {
                        hr=pIClassFactory->CreateInstance(NULL,
                                IID\_IComponent,(void\*\*)&pIComponent);
                        if(SUCCEEDED(hr))
                           pIComponent->Print("COM from scratch.");
                    }
                    
                    ::CoUninitialize ();
                    

                    }

                    What could be the reason(s) this

                    hr

                    variable is retu

                    S Offline
                    S Offline
                    Stefan_Lang
                    wrote on last edited by
                    #10

                    I don't know how to fix it, but you can find ot more about the error code by converting it to hex (e. g. with the Windows calculator: -2147221164 corresponds to 0x80040154 Then go to this page[^] to find this code and look up its meaning: This error code is listed as REGDB_E_CLASSNOTREG, which means "Class not registered." [edit] P.S.: Only now I see that this is what you've been discussing with Victor above. Sometimes I'm blind.... [/edit]

                    GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)

                    U 1 Reply Last reply
                    0
                    • S Stefan_Lang

                      I don't know how to fix it, but you can find ot more about the error code by converting it to hex (e. g. with the Windows calculator: -2147221164 corresponds to 0x80040154 Then go to this page[^] to find this code and look up its meaning: This error code is listed as REGDB_E_CLASSNOTREG, which means "Class not registered." [edit] P.S.: Only now I see that this is what you've been discussing with Victor above. Sometimes I'm blind.... [/edit]

                      GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)

                      U Offline
                      U Offline
                      User 14466593
                      wrote on last edited by
                      #11

                      Hello Stefan, thank you very much for your inputs. By the way, I've been out of town this weekend, I apologize for not being around on time in my own discussion. Many thanks to Richard McCutchan and jschell as well. Stefan, all that makes sense. This error (or status) code is trown at the

                      CoGetClassObject

                      function. As I'm following the tutorial instructions, and even the original sources to be sure I'm learning step by step, my guess is that there is something missing with the registration required and those what you can find in the typical .reg file provided. Yes, it's a 15 years old (really good) tutorial and maybe Windows 10 doesn't get along with all those old keys and need something else (I don't know, just guessing, he he). I'm going to make a more in deep research about this because, clearly, the COM Object needs more "registration" somewhere. Kind regards.

                      S 1 Reply Last reply
                      0
                      • U User 14466593

                        Hello Stefan, thank you very much for your inputs. By the way, I've been out of town this weekend, I apologize for not being around on time in my own discussion. Many thanks to Richard McCutchan and jschell as well. Stefan, all that makes sense. This error (or status) code is trown at the

                        CoGetClassObject

                        function. As I'm following the tutorial instructions, and even the original sources to be sure I'm learning step by step, my guess is that there is something missing with the registration required and those what you can find in the typical .reg file provided. Yes, it's a 15 years old (really good) tutorial and maybe Windows 10 doesn't get along with all those old keys and need something else (I don't know, just guessing, he he). I'm going to make a more in deep research about this because, clearly, the COM Object needs more "registration" somewhere. Kind regards.

                        S Offline
                        S Offline
                        Stefan_Lang
                        wrote on last edited by
                        #12

                        Member 14499563 wrote:

                        ...15 years old (really good) tutorial and [...] Windows 10...

                        I strongly suspect that this combination is at least part of the problem (also, I think that, indeed, tutorials used to be better in the past - but that is just my subjective impression ;) ) Unfortunately my knowledge on this topic is no more up to date than this tutorial. I hope you can resolve this anyway.

                        GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)

                        U 1 Reply Last reply
                        0
                        • S Stefan_Lang

                          Member 14499563 wrote:

                          ...15 years old (really good) tutorial and [...] Windows 10...

                          I strongly suspect that this combination is at least part of the problem (also, I think that, indeed, tutorials used to be better in the past - but that is just my subjective impression ;) ) Unfortunately my knowledge on this topic is no more up to date than this tutorial. I hope you can resolve this anyway.

                          GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)

                          U Offline
                          U Offline
                          User 14466593
                          wrote on last edited by
                          #13

                          I believe that too.A lot of things have happened in so many years and likely that's not a very good combination in this case, specially when it comes to Windows and its sometimes "very tricky" registry. I've tried three different tutorials (unfortunately all of them very old too) and I got the same result at the same point and the same function, so maybe there is something I have to fix behind the scenes of the new Windows 10 registry and well, I'll -try to- work on it. Don't feel sorry for yourself, I really appreciate your input: we can't have all the answers :-D TY Stefan_Lang :thumbsup:

                          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