Click here to Skip to main content
14,268,184 members

C / C++ / MFC

 
GeneralRe: Return From DoModal with RadioButton Pin
Randor 30-Jun-19 8:08
professional Randor 30-Jun-19 8:08 
GeneralRe: Return From DoModal with RadioButton Pin
ForNow30-Jun-19 9:43
memberForNow30-Jun-19 9:43 
PraiseRe: Return From DoModal with RadioButton Pin
Randor 30-Jun-19 14:22
professional Randor 30-Jun-19 14:22 
GeneralRe: Return From DoModal with RadioButton Pin
ForNow30-Jun-19 16:24
memberForNow30-Jun-19 16:24 
AnswerRe: Return From DoModal with RadioButton Pin
Randor 30-Jun-19 17:34
professional Randor 30-Jun-19 17:34 
GeneralRe: Return From DoModal with RadioButton Pin
Victor Nijegorodov30-Jun-19 21:37
memberVictor Nijegorodov30-Jun-19 21:37 
GeneralRe: Return From DoModal with RadioButton Pin
Randor 30-Jun-19 22:38
professional Randor 30-Jun-19 22:38 
QuestionHRESULT variable returning negative value Pin
Member 1449956328-Jun-19 5:58
memberMember 1449956328-Jun-19 5:58 
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 returning that value and how to fix it? Thank you in advance
AnswerRe: HRESULT variable returning negative value Pin
jeron128-Jun-19 6:15
memberjeron128-Jun-19 6:15 
GeneralRe: HRESULT variable returning negative value Pin
Member 1449956328-Jun-19 6:57
memberMember 1449956328-Jun-19 6:57 
AnswerRe: HRESULT variable returning negative value Pin
Victor Nijegorodov28-Jun-19 7:42
memberVictor Nijegorodov28-Jun-19 7:42 
GeneralRe: HRESULT variable returning negative value Pin
Member 1449956328-Jun-19 8:48
memberMember 1449956328-Jun-19 8:48 
GeneralRe: HRESULT variable returning negative value Pin
Richard MacCutchan29-Jun-19 7:23
protectorRichard MacCutchan29-Jun-19 7:23 
GeneralRe: HRESULT variable returning negative value Pin
jschell30-Jun-19 7:14
memberjschell30-Jun-19 7:14 
GeneralRe: HRESULT variable returning negative value Pin
Richard MacCutchan30-Jun-19 10:14
protectorRichard MacCutchan30-Jun-19 10:14 
AnswerRe: HRESULT variable returning negative value Pin
Stefan_Lang30-Jun-19 22:09
memberStefan_Lang30-Jun-19 22:09 
PraiseRe: HRESULT variable returning negative value Pin
Member 144995631-Jul-19 4:05
memberMember 144995631-Jul-19 4:05 
GeneralRe: HRESULT variable returning negative value Pin
Stefan_Lang1-Jul-19 21:31
memberStefan_Lang1-Jul-19 21:31 
GeneralRe: HRESULT variable returning negative value Pin
Member 144995632-Jul-19 6:29
memberMember 144995632-Jul-19 6:29 
QuestionHook stops application Pin
Mark_G0027-Jun-19 5:34
memberMark_G0027-Jun-19 5:34 
AnswerRe: Hook stops application Pin
leon de boer27-Jun-19 7:13
memberleon de boer27-Jun-19 7:13 
GeneralRe: Hook stops application Pin
Mark_G0028-Jun-19 3:23
memberMark_G0028-Jun-19 3:23 
GeneralRe: Hook stops application Pin
Victor Nijegorodov28-Jun-19 4:50
memberVictor Nijegorodov28-Jun-19 4:50 
GeneralRe: Hook stops application Pin
Mark_G0028-Jun-19 6:41
memberMark_G0028-Jun-19 6:41 
GeneralRe: Hook stops application Pin
Victor Nijegorodov28-Jun-19 7:45
memberVictor Nijegorodov28-Jun-19 7:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.