CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 1999
    Posts
    272

    COM guru, this is unexplainable!!!

    I use a double pointer in my server.exe with one Add method in IMath interface like this

    STDMETHODIMP CMath::Add2(long lOp1, long lOp2, long **result)
    {
    // TODO: Add your implementation code here

    **plResult= lOp1 + lOp2; //the program comes here and exit when i step over this line
    return S_OK; // the program never come to this line!!
    }
    // in my client.exe,
    //i call my add function after all th necessary initialization
    long* result;
    result = new long[100];
    pMath->Add(200, 300, &result);
    cout << result; //This line always print 0x000000
    cout <<*result; //client will crash here!




    when i debug into the Add function, i noticed as soon as the program enters the function, the next step
    it exits from the function without even executing the return S_OK!! I noticed the add operation and whatever following the add operation in the add method is never executed!! why is it so? I tried with a
    similar function but using Add(long Op1, long Op2, long* result) instead, and this works fine. Can somebody explain what has happened?
    My ATL server.exe consits of only One Interface with One method Add only! What has happened with
    the double pointer long** result????

    Is it necessary for me to call result = new long[xx]??


  2. #2
    Join Date
    Oct 1999
    Location
    WA
    Posts
    2,393

    Re: COM guru, this is unexplainable!!!

    Just do

    Add2(long, long, long * pResult)
    {
    * pResult =;
    }

    long result[100];
    pMath->Add(200, 300, result);
    count << result[0];




    Your original problem sounds like allocation new long[100] failed. Check result immediately after the allocation. Step into assembly code bravely, it's for human to read.



  3. #3
    Guest

    Re: COM guru, this is unexplainable!!!

    Since it looks like you are using VC++ and MFC, you need to call METHOD_PROLOGUE at the VERY BEGINNING of every function on the interface. The details are long and hair but the jest of it is module state. I vaguely remember something else (V-Table and interface order or some such) but it isn't filter up in my head just now. If I remember anything else, I'll post it.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured