Re: How do I pinvoke this function?
- From: "Willy Denoyette [MVP]" <willy.denoyette@xxxxxxxxxx>
- Date: Thu, 21 Jun 2007 20:09:09 +0200
"Karthik V" <karthikveeramani@xxxxxxxxx> wrote in message news:1182443257.074652.317580@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
In a certain dll, there is this function:
typedef DWORD STDAPICALLTYPE SOMEFUNC(VOID *pHandle, IProgress
*pProgress);
where IProgress is
class IProgress { public: virtual void Update(UINT progress) = 0; };
To pinvoke this from C#, I tried the following:
[DllImport("THE_DLL.dll", SetLastError = true)]
static extern void SomeFunc(IntPtr handle, Progress progress);
and defined Progress as
public class Progress
{
public void Update(ushort progress)
{
// some code
}
}
Trying to invoke SomeFunc and passing an object of Progress, I get an
"Attempted to read or write protected memory" error. The other methods
in the same dll that don't involve the progress callback object (but
involve the handle parameter) work fine.
Please let me know how to pinvoke this function.
It looks like IProgress is a native C++ class, you can't use such classes directly from C#, you will have to wrap this class in a managed wrapper using C++/CLI (VS2005 C++ using /clr option).
Willy.
.
- References:
- How do I pinvoke this function?
- From: Karthik V
- How do I pinvoke this function?
- Prev by Date: Re: Unreachable expression code detected
- Next by Date: Re: Cell Phone
- Previous by thread: Re: How do I pinvoke this function?
- Next by thread: Re: Datagridview column
- Index(es):
Relevant Pages
|