Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Reading data from IStorage Object
Reading data from IStorage Object [message #464369] Tue, 22 November 2005 09:11 Go to next message
Eclipse User
Originally posted by: andrea.obergfell.hauk-sasko.de

Hi,

I'm trying to drag'n'drop emails from MS Outlook to my Java application.
After doing lots of tests I found out Outlook provides the contents as an
IStorage object (org.eclipse.swt.internal.ole.win32.IStorage). I
subclassed the ByteArrayTransfer class and modified the nativeToJava
method, but now I can't figure out how to get the actual data from the
IStorage object. EnumElements returns 1 value, but I don't know what to do
with it.

Any ideas?
Or is my approach completely wrong?

Thanks
Andrea
Re: Reading data from IStorage Object [message #464381 is a reply to message #464369] Tue, 22 November 2005 14:02 Go to previous messageGo to next message
Veronika Irvine is currently offline Veronika Irvine
Messages: 1272
Registered: July 2009
Senior Member
See org.eclipse.swt.internal.ole.win32.IEnum and
org.eclipse.swt.internal.ole.win32.IEnumSTATSTG.
Similar enumerated types are used in SWT in Clipboard_getAvailableTypes and
DropTarget.setEventData(...)

http://msdn.microsoft.com/library/default.asp?url=/library/e n-us/stg/stg/istorage.asp

http://msdn.microsoft.com/library/default.asp?url=/library/e n-us/stg/stg/istream.asp


"A.Obergfell" <andrea.obergfell@hauk-sasko.de> wrote in message
news:fd6eab50daa92044b39479db3abbec48$1@www.eclipse.org...
> Hi,
>
> I'm trying to drag'n'drop emails from MS Outlook to my Java application.
> After doing lots of tests I found out Outlook provides the contents as an
> IStorage object (org.eclipse.swt.internal.ole.win32.IStorage). I
> subclassed the ByteArrayTransfer class and modified the nativeToJava
> method, but now I can't figure out how to get the actual data from the
> IStorage object. EnumElements returns 1 value, but I don't know what to do
> with it.
>
> Any ideas?
> Or is my approach completely wrong?
>
> Thanks
> Andrea
>
Re: Reading data from IStorage Object [message #464660 is a reply to message #464381] Mon, 28 November 2005 11:52 Go to previous messageGo to next message
Eclipse User
Originally posted by: andrea.obergfell.hauk-sasko.de

public Object nativeToJava(TransferData transferData) {
System.out.println("nativeToJava: type = " + transferData.type);

IDataObject idata = new IDataObject(transferData.pIDataObject);
idata.AddRef();

FORMATETC formatetc = transferData.formatetc;

// fill up the STGMEDIUM structure via IDataObject
STGMEDIUM stg = new STGMEDIUM();
stg.tymed = -1;
int hresult = idata.GetData( formatetc, stg );
idata.Release();

if ( hresult != COM.S_OK )
{
System.out.println("something is wrong here");
}

System.out.println("stg.tymed = " + stg.tymed);
System.out.println("stg.sizeof = " + stg.sizeof);
System.out.println("stg.unionField = " + stg.unionField);
Re: Reading data from IStorage Object [message #464661 is a reply to message #464381] Mon, 28 November 2005 12:01 Go to previous messageGo to next message
Eclipse User
Originally posted by: andrea.obergfell.hauk-sasko.de

public Object nativeToJava(TransferData transferData) {

IDataObject idata = new IDataObject(transferData.pIDataObject);
idata.AddRef();

FORMATETC formatetc = transferData.formatetc;

// fill up the STGMEDIUM structure via IDataObject
STGMEDIUM stg = new STGMEDIUM();
stg.tymed = -1;
int hresult = idata.GetData( formatetc, stg );
idata.Release();

if ( hresult != COM.S_OK )
{
System.out.println("something is wrong here");
}

if ((stg.tymed & 8) == 8)
{
// IStorage
IStorage storage = new IStorage(stg.unionField);
storage.AddRef();

int [] x = new int [1];
int ret = storage.EnumElements(0,0,0,x);

IEnumSTATSTG st = new IEnumSTATSTG(x[0]);
st.AddRef();

// here I don't know how to continue ...
}
}

I think I need to call st.Next(), but don't know the proper arguments.
And then I don't know what to do with with the return value from Next().
IEnumSTATSTG.Next() should be enumerating STATSTG structures, but there's
only a default constructor with no arguments in STATSTG ...
So I'm really confused.

Cheers
Andrea
Re: Reading data from IStorage Object [message #464673 is a reply to message #464661] Mon, 28 November 2005 16:18 Go to previous message
Veronika Irvine is currently offline Veronika Irvine
Messages: 1272
Registered: July 2009
Senior Member
public Object nativeToJava(TransferData transferData) {

IDataObject idata = new IDataObject(transferData.pIDataObject);
idata.AddRef();

FORMATETC formatetc = transferData.formatetc;

// fill up the STGMEDIUM structure via IDataObject
STGMEDIUM stg = new STGMEDIUM();
stg.tymed = -1;
int hresult = idata.GetData( formatetc, stg );
idata.Release();

if ( hresult != COM.S_OK )
{
System.out.println("something is wrong here");
}

if ((stg.tymed & 8) == 8)
{
// IStorage
IStorage storage = new IStorage(stg.unionField);
storage.AddRef();

int [] x = new int [1];
int ret = storage.EnumElements(0,0,0,x);

IEnumSTATSTG enumSTATSTG = new IEnumSTATSTG(x[0]);
enumSTATSTG .AddRef();

STATSTG[] data = new STATSTG[0];
// Loop over enumerator
int rgelt = OS.GlobalAlloc(OS.GMEM_FIXED | OS.GMEM_ZEROINIT,
STATSTG.sizeof);
int[] pceltFetched = new int[1];
enumSTATSTG .Reset();
while (enumSTATSTG .Next(1, rgelt, pceltFetched) == COM.S_OK &&
pceltFetched[0] == 1) {
STATSTG statstg = new STATSTG();
COM.MoveMemory(statstg, rgelt, STATSTG.sizeof);
STATSTG[] newData = new STATSTG[data.length + 1];
System.arraycopy(data, 0, newData, 0, data.length);
newData[data.length] = statstg;
data = newData;
}
OS.GlobalFree(rgelt);

enumSTATSTG .Release();
// do something with STATSTG[]

storage.Release;
}
}
Previous Topic:How to avoid paint merging ?
Next Topic:newbie wizard question
Goto Forum:
  


Current Time: Sun Oct 26 09:41:11 GMT 2014

Powered by FUDForum. Page generated in 0.15625 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software