Re: How do I pinvoke this function?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



"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.

.



Relevant Pages

  • Re: How do I pinvoke this function?
    ... you won't be able to call the methods on the interface pointer, ... And the best you could do with the progress pointer is pass it around. ... IProgress ... static extern void SomeFunc ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: How do I pinvoke this function?
    ... you won't be able to call the methods on the interface pointer, ... And the best you could do with the progress pointer is pass it around. ... IProgress ... static extern void SomeFunc ...
    (microsoft.public.dotnet.languages.csharp)
  • How do I pinvoke this function?
    ... In a certain dll, there is this function: ... IProgress ... Progress progress); ... Please let me know how to pinvoke this function. ...
    (microsoft.public.dotnet.languages.csharp)
  • RE: Diagnostics.Process.Start as another user from ASP.NET 2.0
    ... Any further progress on this? ... pinvoke to create new process under specific user), ... Steven Cheng ... Microsoft MSDN Online Support Lead ...
    (microsoft.public.dotnet.framework.aspnet)