473,376 Members | 1,012 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,376 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 5939
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Max Sandman | last post by:
I need to import and export CSV files. Before I head off the create my own CSV parser (got the link to Falafel's articles), is there a way to use the DataObject class in this process? I don't want...
12
by: craigkenisston | last post by:
Hi, I will use an example to do a simplified description of my problem, please don't laugh. I just "believe" I would have to use either interface or abstract classes, but I've not ever write an...
1
by: Naveen Mukkelli | last post by:
Hi, I've got 3 Network Interface Cards(NIC) in my PC. Lets say NIC1, NIC2, NIC3. I have openend network connections in control panel and renamed them to Network 1, Network 2, Network 3. I'm...
1
by: Robin Tucker | last post by:
I have an existing COM object that supports IDataObject (written in C++). I want to use GetFormats and GetData on this object in VB.NET, but I blooming well can't. If I write: Dim theObject...
4
by: Hei | last post by:
Hi is vb.net' "interface" is sound like C++ "abstract class" ? Hei
0
by: Rodolfo | last post by:
Hi all.... I have to develop a class application but I must use a COM+ DLL (vb6) intalled in a remote COM+ server. The proxy application is already installed in IIS server but I can't use any...
6
by: Mark Wilden | last post by:
Take a class, RateTableProductCode. It needs to share implementation with other classes, so the common code is placed in a ProductCode class, from which it derives. There needs to be an...
1
by: Ezmeralda | last post by:
Hello, I need to an TCP/IP Interface for communication with an embedded device. Since I have two different design ideas in mind, I am wondering whether you could give me some hints to decide:...
3
by: Adrian | last post by:
In the following code example I am trying to create a generic interface for a bunch of objects. Each concrete type is stored in its own container and the a container of pointer's to base is used so I...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.