Click to See Complete Forum and Search --> : COM guru, this is unexplainable!!!


mce16
October 14th, 1999, 09:55 PM
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]??

Feng Yuan
October 19th, 1999, 12:48 AM
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.

October 19th, 1999, 05:02 PM
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.