Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - Implementing Unmanaged Interface in C#

Reply
 
Old 03-13-2008   #1 (permalink)
Saad


 
 

Implementing Unmanaged Interface in C#

Hi,

I have an unmanged interface which i have exposed through COM to C#. I
have been able to implement the interface in one of the C# classes
(say Class1) as well.

But now what i want to do is that i need to pass the reference of the
object of Class1 to this COM wrapper...and then from inside that
wrapper i want to call one of the func of that class1.

What i did roughly is something like this:

/
*********************************************************************************************************/
//this is the interface that was exposed
// IExportedClassWrapper
[
object,
uuid("7DD5445A-A8AE-471C-A065-629C3A004362"),
dual, helpstring("IExportedClassWrapper Interface"),
pointer_default(unique)
]
__interface IExportedClassWrapper : IDispatch
{
[id(4), helpstring("method CheckInterfaceOne")] HRESULT
CheckInterfaceOne(IDispatch* a, [out,retval] LONG* RetParam);
};
/
*********************************************************************************************************/

/
*********************************************************************************************************/
STDMETHODIMP CExportedClassWrapper::CheckInterfaceOne(IDispatch* a,
LONG* RetParam)
{
// TODO: Add your implementation code here
IExportedClassWrapper* objI = static_cast<IExportedClassWrapper*>(a);

//THIS IS THE LINE ON WHICH I'M GETTING EXCEPTION
//SAYING THAT THE CALLING CONVENTION IS NOT RIGHT....
objI->MethodSampleReturn(RetParam);

return S_OK;
}
/
*********************************************************************************************************/

/
*********************************************************************************************************/
//then the C# class implemented it like
public class Class1 : SampleCISCOATLCOMWrapper.IExportedClassWrapper
{
public Class1()
{
//
// TODO: Add constructor logic here
//
}

#region IExportedClassWrapper Members

public int CheckInterfaceOne(object a)
{
// TODO: Add Class1.CheckInterfaceOne implementation
//THIS IS THE METHOD
THAT I WANT TO CALL FROM COM
return 20;
}

#endregion
}
/
*********************************************************************************************************/
//and then i used this interface like this in C#

SampleCISCOATLCOMWrapper.CExportedClassWrapperClass objCl = new
SampleCISCOATLCOMWrapper.CExportedClassWrapperClass();

Class1 objClass = new Class1();

int nRet = objCl.CheckInterfaceOne(objClass);
/
*********************************************************************************************************/

this whole thing is sort of circular....

I think you got an idea of what i want to do...
Is it possible?
And how?

Note: I dont have much experience in COM ...

Thanks,
Saad.

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Linker error when linking unmanaged library with manged exe .NET General
Unmanaged C++ client invoke C# component to Add PSSnapin Failed PowerShell
Problem getting exception info from unmanaged C++ .NET General
Dispose Unmanaged resources .NET General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46