vkarthik 0 Newbie Poster

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.