Re: How do I pinvoke this function?



Ben,

While that is the case, COM demands that all interfaces derive from
IUnknown. If an interface has to derive from that, then the vtable for that
interface is always going to be populated with the entries for the methods
in IUnknown in the first three slots, follwed by the methods for the
interface itself. Since the interface here doesn't derive from IUnknown,
its vtable is not going to have those entries.

There is no way that this interface could be used in COM.

--
- Nicholas Paldino [.NET/C# MVP]
- mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx

"Ben Voigt [C++ MVP]" <rbv@xxxxxxxxxxxxx> wrote in message
news:%23qFCpDDtHHA.1060@xxxxxxxxxxxxxxxxxxxxxxx

"Nicholas Paldino [.NET/C# MVP]" <mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote
in message news:ePBhq1CtHHA.1212@xxxxxxxxxxxxxxxxxxxxxxx
That's the thing, if it doesn't derive from IUnknown, then it can't
possibly be a COM interface pointer. Just because it is an interface
doesn't mean that it is supported by COM.

COM is as much a binary standard for v-table layout as anything else, and
that interface would meet the COM binary standard.


--
- Nicholas Paldino [.NET/C# MVP]
- mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx

"Ben Voigt [C++ MVP]" <rbv@xxxxxxxxxxxxx> wrote in message
news:%23orbHrCtHHA.4796@xxxxxxxxxxxxxxxxxxxxxxx

"Nicholas Paldino [.NET/C# MVP]" <mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote
in message news:%23%232aRXCtHHA.4796@xxxxxxxxxxxxxxxxxxxxxxx
Karthik,

I believe in this case that IProgress is not actually a class, but
an interface pointer. The thing is, while you will be able to call it
in C#, you won't be able to call the methods on the interface pointer,
as it needs to be a COM interface pointer in order to interop
correctly. .NET interop

It looks like a COM interface pointer to me... or at least binary
compatible. No IUnknown or IDispatch support though.

You'll need a type library for it, and to run tlbimp.

The lack of IUnknown may cause problems.

does not support native C++ interfaces.

Your P/Invoke declaration would look like this:

[DllImport("THE_DLL.dll", SetLastError = true)]
static extern void SomeFunc(IntPtr handle, IntPtr progress);

And the best you could do with the progress pointer is pass it
around.


--
- Nicholas Paldino [.NET/C# MVP]
- mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx


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











.



Relevant Pages

  • How do you do asynchronous processing in C#
    ... I'm trying to implement asynchronous call to COM interface below and having trouble understanding what C# code will allow me to update progress bar while call is running. ... I have an object called MyDownloader which has a method of BeginDownload below, I need to periodically update main program about progress and when call is completed to return back to processing. ... An IDownloadProgressChangedCallback interface that is called periodically for download progress changes before completion. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: IClassFactory::CreateInstance(IID_IUnknown) ?
    ... for IUnknown and return the resulting interface pointer. ... A class factory is not itself aggregating anything. ...
    (microsoft.public.win32.programmer.ole)
  • Rechenintensiver Workthread mit Progressbar (Umsetzung von C#/VB nach VC++)
    ... System.Threading.WaitCallback, progress) ... Private Sub bearbeitung ... Public Interface IProgressCallback ...
    (microsoft.public.de.vc)
  • Re: [opensuse] Dropped packages
    ... under the xen hypervisor. ... does ethtool -K $INTERFACE tx off ... "Progress is possible only if we train ourselves to think about programs ...
    (SuSE)
  • Re: GetType().FullName is "System.__ComObject"
    ... the way this works is through an interface (IUnknown) that every COM object must implement. ... QueryInterface is called to say, "please give me a pointer to your interface, or else tell me if you don't implement that interface". ... The interface pointer you get in return may or may not even be implemented by the same "class" you called QueryInterface on. ...
    (microsoft.public.vstudio.general)