Re: Trying to use unmanaged with C#
- From: Patrick Steele <patrick@xxxxxxxx>
- Date: Thu, 8 Feb 2007 09:46:00 -0500
In article <eLbTd34SHHA.920@xxxxxxxxxxxxxxxxxxxx>,
EdisonCPP@xxxxxxxxxxxxxxxxx says...
Hi,
My company has a large library of COM objects we've been using for years,
it's massive,
re-writing would take months to years.
One of these objects has a method that looks something like this:
HRESULT EnumItems(IUnkown* pUnk, VARIANT Param);
The IUnknown is a callback, where you would have done something like this:
class CCallback : public ICallbackInterface
{
//Implement dummy Release and AddRefs, supply a good
QueryInterface()
HRESULT MyCallback(LONG ValueNeeded1, BSTR ValueNeeded2, VARIANT
Param)
{
//do something with supplied information
return S_OK;
}
//...
};
CCallback* pCb = new CCallback;
pObj->EnumItems((IUnknown*)pCb, this);
internally it Queries for ICallbackInterface and feeds data to the callback.
Now I need to use this in my C# ASP.NET site. So I made something like
this:
//ref COM obj and convert to managed dll.
using System.Runtime.InteropServices;
using MyObjLib;
[ComVisible(true)] //added with no difference after getting error
public class CallbackClass : CallbackInterface
{
public void MyCallback(int ValueNeeded1, string ValueNeeded2, object
Param)
{
//deal with it
}
};
CallbackClass cc = new CallbackClass;
pObj.EnumItems(cc, this);
Did you also mark the assembly as COMVisible? Check out your
AssemblyInfo.cs.
--
Patrick Steele
http://weblogs.asp.net/psteele
.
- Follow-Ups:
- Re: Trying to use unmanaged with C#
- From: Steven Edison
- Re: Trying to use unmanaged with C#
- From: Steven Edison
- Re: Trying to use unmanaged with C#
- References:
- Trying to use unmanaged with C#
- From: Steven Edison
- Trying to use unmanaged with C#
- Prev by Date: Trying to use unmanaged with C#
- Next by Date: Re: Trying to use unmanaged with C#
- Previous by thread: Trying to use unmanaged with C#
- Next by thread: Re: Trying to use unmanaged with C#
- Index(es):
Relevant Pages
|