471,316 Members | 1,403 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,316 software developers and data experts.

Getting the COM IDataObject interface from the DataObject class

The .Net DataObject class implements the COM/OLE IDataObject interface , so
how do I get it.

I have tried this, but it does not work :

// Declare the COM/OLE IDataObject interface

[ComImport, Guid("0000010E-0000-0000-C000-000000000046"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown )]
public interface IOleDataObject
{
[PreserveSig]
int OleGetData(FORMATETC pFormatetc, [Out] STGMEDIUM pMedium);
[PreserveSig]
int OleGetDataHere(FORMATETC pFormatetc, [In, Out] STGMEDIUM pMedium);
[PreserveSig]
int OleQueryGetData(FORMATETC pFormatetc);
[PreserveSig]
int OleGetCanonicalFormatEtc(FORMATETC pformatectIn, [Out] FORMATETC
pformatetcOut);
[PreserveSig]
int OleSetData(FORMATETC pFormatectIn, STGMEDIUM pmedium, int fRelease);
[return: MarshalAs(UnmanagedType.Interface)]
IEnumFORMATETC OleEnumFormatEtc([In, MarshalAs(UnmanagedType.U4)] int
dwDirection);
[PreserveSig]
int OleDAdvise(FORMATETC pFormatetc, [In, MarshalAs(UnmanagedType.U4)] int
advf, [In, MarshalAs(UnmanagedType.Interface)] object pAdvSink, [Out,
MarshalAs(UnmanagedType.LPArray)] int[] pdwConnection);
[PreserveSig]
int OleDUnadvise([In, MarshalAs(UnmanagedType.U4)] int dwConnection);
[PreserveSig]
int OleEnumDAdvise([Out, MarshalAs(UnmanagedType.LPArray)] object[]
ppenumAdvise);
}

-------------------

DataObject data = new DataObject();
IOleDataObject ido = data as IOleDataObject
--------------

When this is run, ido is null. I have also tried varrious other methods like
using Marshal.GetIUnknownForObject, Marshal.QueryInterface,
Marshal.GetTypedObjectForIUnknown, but none of the approaches work.

What am I doing wrong?

Thanks
Bob
Jan 21 '06 #1
4 5812
Bob,

You can use the IDataObject in the
System.Runtime.InteropServices.ComTypes namespace. It is the one you are
looking for.

The DataObject class in the System.Windows.Forms namespace implements
this as well.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Bob Staheli" <st*********@gmail.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
The .Net DataObject class implements the COM/OLE IDataObject interface ,
so how do I get it.

I have tried this, but it does not work :

// Declare the COM/OLE IDataObject interface

[ComImport, Guid("0000010E-0000-0000-C000-000000000046"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown )]
public interface IOleDataObject
{
[PreserveSig]
int OleGetData(FORMATETC pFormatetc, [Out] STGMEDIUM pMedium);
[PreserveSig]
int OleGetDataHere(FORMATETC pFormatetc, [In, Out] STGMEDIUM pMedium);
[PreserveSig]
int OleQueryGetData(FORMATETC pFormatetc);
[PreserveSig]
int OleGetCanonicalFormatEtc(FORMATETC pformatectIn, [Out] FORMATETC
pformatetcOut);
[PreserveSig]
int OleSetData(FORMATETC pFormatectIn, STGMEDIUM pmedium, int fRelease);
[return: MarshalAs(UnmanagedType.Interface)]
IEnumFORMATETC OleEnumFormatEtc([In, MarshalAs(UnmanagedType.U4)] int
dwDirection);
[PreserveSig]
int OleDAdvise(FORMATETC pFormatetc, [In, MarshalAs(UnmanagedType.U4)] int
advf, [In, MarshalAs(UnmanagedType.Interface)] object pAdvSink, [Out,
MarshalAs(UnmanagedType.LPArray)] int[] pdwConnection);
[PreserveSig]
int OleDUnadvise([In, MarshalAs(UnmanagedType.U4)] int dwConnection);
[PreserveSig]
int OleEnumDAdvise([Out, MarshalAs(UnmanagedType.LPArray)] object[]
ppenumAdvise);
}

-------------------

DataObject data = new DataObject();
IOleDataObject ido = data as IOleDataObject
--------------

When this is run, ido is null. I have also tried varrious other methods
like using Marshal.GetIUnknownForObject, Marshal.QueryInterface,
Marshal.GetTypedObjectForIUnknown, but none of the approaches work.

What am I doing wrong?

Thanks
Bob

Jan 21 '06 #2
Hi Nicholas,

Thanks for your reply.

However, System.Runtime.InteropServices.ComTypes.IDataObjec t is only
present in .Net 2.0. I am using .Net 1.1.

How can I do that in this case?

Bob
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:Ot**************@TK2MSFTNGP12.phx.gbl...
Bob,

You can use the IDataObject in the
System.Runtime.InteropServices.ComTypes namespace. It is the one you are
looking for.

The DataObject class in the System.Windows.Forms namespace implements
this as well.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Bob Staheli" <st*********@gmail.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
The .Net DataObject class implements the COM/OLE IDataObject interface ,
so how do I get it.

I have tried this, but it does not work :

// Declare the COM/OLE IDataObject interface

[ComImport, Guid("0000010E-0000-0000-C000-000000000046"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown )]
public interface IOleDataObject
{
[PreserveSig]
int OleGetData(FORMATETC pFormatetc, [Out] STGMEDIUM pMedium);
[PreserveSig]
int OleGetDataHere(FORMATETC pFormatetc, [In, Out] STGMEDIUM pMedium);
[PreserveSig]
int OleQueryGetData(FORMATETC pFormatetc);
[PreserveSig]
int OleGetCanonicalFormatEtc(FORMATETC pformatectIn, [Out] FORMATETC
pformatetcOut);
[PreserveSig]
int OleSetData(FORMATETC pFormatectIn, STGMEDIUM pmedium, int fRelease);
[return: MarshalAs(UnmanagedType.Interface)]
IEnumFORMATETC OleEnumFormatEtc([In, MarshalAs(UnmanagedType.U4)] int
dwDirection);
[PreserveSig]
int OleDAdvise(FORMATETC pFormatetc, [In, MarshalAs(UnmanagedType.U4)]
int advf, [In, MarshalAs(UnmanagedType.Interface)] object pAdvSink, [Out,
MarshalAs(UnmanagedType.LPArray)] int[] pdwConnection);
[PreserveSig]
int OleDUnadvise([In, MarshalAs(UnmanagedType.U4)] int dwConnection);
[PreserveSig]
int OleEnumDAdvise([Out, MarshalAs(UnmanagedType.LPArray)] object[]
ppenumAdvise);
}

-------------------

DataObject data = new DataObject();
IOleDataObject ido = data as IOleDataObject
--------------

When this is run, ido is null. I have also tried varrious other methods
like using Marshal.GetIUnknownForObject, Marshal.QueryInterface,
Marshal.GetTypedObjectForIUnknown, but none of the approaches work.

What am I doing wrong?

Thanks
Bob


Jan 21 '06 #3
Bob,

You should be able to declare this in your code, and it should work:

[ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown ),
Guid("0000010E-0000-0000-C000-000000000046")]
public interface IDataObject
{
void GetData([In] ref FORMATETC format, out STGMEDIUM medium);
void GetDataHere([In] ref FORMATETC format, ref STGMEDIUM medium);
[PreserveSig]
int QueryGetData([In] ref FORMATETC format);
[PreserveSig]
int GetCanonicalFormatEtc([In] ref FORMATETC formatIn, out FORMATETC
formatOut);
void SetData([In] ref FORMATETC formatIn, [In] ref STGMEDIUM medium,
[MarshalAs(UnmanagedType.Bool)] bool release);
IEnumFORMATETC EnumFormatEtc(DATADIR direction);
[PreserveSig]
int DAdvise([In] ref FORMATETC pFormatetc, ADVF advf, IAdviseSink
adviseSink, out int connection);
void DUnadvise(int connection);
[PreserveSig]
int EnumDAdvise(out IEnumSTATDATA enumAdvise);
}-- - Nicholas Paldino [.NET/C# MVP] -
mv*@spam.guard.caspershouse.com

"Bob Staheli" <st*********@gmail.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hi Nicholas,

Thanks for your reply.

However, System.Runtime.InteropServices.ComTypes.IDataObjec t is only
present in .Net 2.0. I am using .Net 1.1.

How can I do that in this case?

Bob
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in message news:Ot**************@TK2MSFTNGP12.phx.gbl...
Bob,

You can use the IDataObject in the
System.Runtime.InteropServices.ComTypes namespace. It is the one you are
looking for.

The DataObject class in the System.Windows.Forms namespace implements
this as well.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Bob Staheli" <st*********@gmail.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
The .Net DataObject class implements the COM/OLE IDataObject interface ,
so how do I get it.

I have tried this, but it does not work :

// Declare the COM/OLE IDataObject interface

[ComImport, Guid("0000010E-0000-0000-C000-000000000046"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown )]
public interface IOleDataObject
{
[PreserveSig]
int OleGetData(FORMATETC pFormatetc, [Out] STGMEDIUM pMedium);
[PreserveSig]
int OleGetDataHere(FORMATETC pFormatetc, [In, Out] STGMEDIUM pMedium);
[PreserveSig]
int OleQueryGetData(FORMATETC pFormatetc);
[PreserveSig]
int OleGetCanonicalFormatEtc(FORMATETC pformatectIn, [Out] FORMATETC
pformatetcOut);
[PreserveSig]
int OleSetData(FORMATETC pFormatectIn, STGMEDIUM pmedium, int fRelease);
[return: MarshalAs(UnmanagedType.Interface)]
IEnumFORMATETC OleEnumFormatEtc([In, MarshalAs(UnmanagedType.U4)] int
dwDirection);
[PreserveSig]
int OleDAdvise(FORMATETC pFormatetc, [In, MarshalAs(UnmanagedType.U4)]
int advf, [In, MarshalAs(UnmanagedType.Interface)] object pAdvSink,
[Out, MarshalAs(UnmanagedType.LPArray)] int[] pdwConnection);
[PreserveSig]
int OleDUnadvise([In, MarshalAs(UnmanagedType.U4)] int dwConnection);
[PreserveSig]
int OleEnumDAdvise([Out, MarshalAs(UnmanagedType.LPArray)] object[]
ppenumAdvise);
}

-------------------

DataObject data = new DataObject();
IOleDataObject ido = data as IOleDataObject
--------------

When this is run, ido is null. I have also tried varrious other methods
like using Marshal.GetIUnknownForObject, Marshal.QueryInterface,
Marshal.GetTypedObjectForIUnknown, but none of the approaches work.

What am I doing wrong?

Thanks
Bob



Jan 21 '06 #4
I tried your declaration but it didnt work..most wierd.

I should note that I changed IAdviseSink from the DAdvice method to an
[In, MarshalAs(UnmanagedType.Interface)] object - does that make a
difference - i would think it is only the GUID applied to the interface that
matters...

Once again..i am using this code :
DataObject d = new DataObject();
IDataObject id = d as IDataObject;

id is still null.

I am out of ideas now.

Bob

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:%2***************@tk2msftngp13.phx.gbl...
Bob,

You should be able to declare this in your code, and it should work:

[ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown ),
Guid("0000010E-0000-0000-C000-000000000046")]
public interface IDataObject
{
void GetData([In] ref FORMATETC format, out STGMEDIUM medium);
void GetDataHere([In] ref FORMATETC format, ref STGMEDIUM medium);
[PreserveSig]
int QueryGetData([In] ref FORMATETC format);
[PreserveSig]
int GetCanonicalFormatEtc([In] ref FORMATETC formatIn, out FORMATETC
formatOut);
void SetData([In] ref FORMATETC formatIn, [In] ref STGMEDIUM medium,
[MarshalAs(UnmanagedType.Bool)] bool release);
IEnumFORMATETC EnumFormatEtc(DATADIR direction);
[PreserveSig]
int DAdvise([In] ref FORMATETC pFormatetc, ADVF advf, IAdviseSink
adviseSink, out int connection);
void DUnadvise(int connection);
[PreserveSig]
int EnumDAdvise(out IEnumSTATDATA enumAdvise);
}-- - Nicholas Paldino [.NET/C# MVP] -
mv*@spam.guard.caspershouse.com

"Bob Staheli" <st*********@gmail.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hi Nicholas,

Thanks for your reply.

However, System.Runtime.InteropServices.ComTypes.IDataObjec t is only
present in .Net 2.0. I am using .Net 1.1.

How can I do that in this case?

Bob
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in message news:Ot**************@TK2MSFTNGP12.phx.gbl...
Bob,

You can use the IDataObject in the
System.Runtime.InteropServices.ComTypes namespace. It is the one you
are looking for.

The DataObject class in the System.Windows.Forms namespace implements
this as well.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Bob Staheli" <st*********@gmail.com> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
The .Net DataObject class implements the COM/OLE IDataObject interface
, so how do I get it.

I have tried this, but it does not work :

// Declare the COM/OLE IDataObject interface

[ComImport, Guid("0000010E-0000-0000-C000-000000000046"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown )]
public interface IOleDataObject
{
[PreserveSig]
int OleGetData(FORMATETC pFormatetc, [Out] STGMEDIUM pMedium);
[PreserveSig]
int OleGetDataHere(FORMATETC pFormatetc, [In, Out] STGMEDIUM pMedium);
[PreserveSig]
int OleQueryGetData(FORMATETC pFormatetc);
[PreserveSig]
int OleGetCanonicalFormatEtc(FORMATETC pformatectIn, [Out] FORMATETC
pformatetcOut);
[PreserveSig]
int OleSetData(FORMATETC pFormatectIn, STGMEDIUM pmedium, int
fRelease);
[return: MarshalAs(UnmanagedType.Interface)]
IEnumFORMATETC OleEnumFormatEtc([In, MarshalAs(UnmanagedType.U4)] int
dwDirection);
[PreserveSig]
int OleDAdvise(FORMATETC pFormatetc, [In, MarshalAs(UnmanagedType.U4)]
int advf, [In, MarshalAs(UnmanagedType.Interface)] object pAdvSink,
[Out, MarshalAs(UnmanagedType.LPArray)] int[] pdwConnection);
[PreserveSig]
int OleDUnadvise([In, MarshalAs(UnmanagedType.U4)] int dwConnection);
[PreserveSig]
int OleEnumDAdvise([Out, MarshalAs(UnmanagedType.LPArray)] object[]
ppenumAdvise);
}

-------------------

DataObject data = new DataObject();
IOleDataObject ido = data as IOleDataObject
--------------

When this is run, ido is null. I have also tried varrious other methods
like using Marshal.GetIUnknownForObject, Marshal.QueryInterface,
Marshal.GetTypedObjectForIUnknown, but none of the approaches work.

What am I doing wrong?

Thanks
Bob



Jan 22 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Max Sandman | last post: by
1 post views Thread by Naveen Mukkelli | last post: by
4 posts views Thread by Hei | last post: by
6 posts views Thread by Mark Wilden | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.