Click to See Complete Forum and Search --> : com: client in VC++ and server in c#


callavin
June 12th, 2006, 05:55 AM
I made one com application in C#(2005)

namespace com_server
{
[InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
public interface _Class1
{
[DispId(1)]
int adingg(int a, int b);
}

[ClassInterface(ClassInterfaceType.None)]
public class Class1 : _Class1
{
public Class1() { }

public int adingg(int a, int b)
{
return ((a+b));
}
}
}

In the properties of this solution I choose "Make it a COM application", which i think generates the GUID stuff to the code.
I registered it.

Then In VC++ MFC application I imported the corresponding tlb file.
And added these lines in the cpp file.

com_server ::_Class1Ptr ptr(__uuidof(com_server ::_Class1 ));
int num = ptr->adingg(12,14);

The VC++ application build fine but it is giving unhabdled exception. guideme where I am wrong

Plz tell me some good tutorial on this stuff also..

-----------
thanks

Krishnaa
June 12th, 2006, 06:00 AM
Can you describe the crash i.e. when, what function, what argument etc.. ?

Also are you passing any type of strings to that COM object ? what type are you using ??

callavin
June 12th, 2006, 06:10 AM
well I was debugging and found out it fails in the first line itself
" com_server ::_Class1Ptr ptr(__uuidof(com_server ::_Class1 ));"

going deep into the this

this is the functiion which fails the application

HRESULT CreateInstance(const CLSID& rclsid, IUnknown* pOuter = NULL, DWORD dwClsContext = CLSCTX_ALL) throw()

these are the arguments which are being passed in this function respectively

B817F446-B6FF-3C5F-A655-A23E57628B8C, 0x00000000,7

then in the same function it executes this line
hr = CoCreateInstance(rclsid, pOuter, dwClsContext, __uuidof(IUnknown), reinterpret_cast<void**>(&pIUnknown));

and value of 'hr' comes as -858993460. and the program fails by giving the error
unhandled exception in xxx.exe(kernel32.dll):0xE06D7363: Microsoft c++ Exception.

callavin
June 13th, 2006, 06:46 AM
Now i am really confused.
In one application the above written code is working fine.
then I made anothe dialog based MFC and wrote the same code. Now again it is giving same error.


how come one application is running perfect while another one is crashing.