When use Midl.Exe for generate the tlb with the next idl, i get several warnings, one of them affects to the RemoteGetData,RemoteGetDataHere and RemoteSetData functions of the IDataObject: the second argument of the RemoteGetData (STGMEDIUM * medium) can't be referenced and is parsing like a pointer, i must use unsafe code for manage it but this code break when i get one parameter of the STGMEDIUM... my code appear at the behind this idl file
//dll_code.idl
[
uuid(XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX)
]
library dll_code
{
import "MsHtmHst.idl";
import "Mshtml.idl";
...
enum tagDOCHOSTUIDBLCLK;
enum tagDOCHOSTUIFLAG;
enum tagDOCHOSTUITYPE;
...
interface IDataObject;
interface HTMLDocumentEvents2;
...
};
//Code 1 - using a struct
public struct STGMEDIUM
{
[MarshalAs(int, SizeConst=1024)] //MAX_COLUMN_NAME_LEN
public tagTYMED tymed;
public int tymed;
[MarshalAs(UnmanagedType.LPStr, SizeConst=1024)]
public string filename;
}
...
// This is the function DragEnter code
// pDataObj is a dll_code.IDataObject
dll_code.IEnumFORMATETC enumFORMATETC;
pDataObj.EnumFormatEtc(0,out enumFORMATETC);
dll_code.tagFORMATETC fmtetc;
uint pcelFetched=0;
enumFORMATETC.RemoteNext(1, out fmtetc,out pcelFetched);
STGMEDIUM medium = new STGMEDIUM();
do{
int idFormat = (int)fmtetc.cfFormat;
if (idFormat == (DataFormats.GetFormat(DataFormats.FileDrop)).Id){
System.IntPtr pointerToMedium = Marshal.AllocHGlobal(Marshal.SizeOf(medium));
pDataObj.RemoteGetData(ref fmtetc,pointerToMedium);// Call to the RemoteGetData (the second value must be a STGMEDIUM on a well done dll.
Marshal..PtrToStructure(pointerToMedium, medium); <-- BREAK AT THIS POINT
enumFORMATETC.RemoteNext(1, out fmtetc,out pcelFetched);
}
}while (((int)fmtetc.cfFormat) != 0)
//Code 2 - using a buffer
...
// This is the function DragEnter code
// pDataObj is a dll_code.IDataObject
dll_code.IEnumFORMATETC enumFORMATETC;
pDataObj.EnumFormatEtc(0,out enumFORMATETC);
dll_code.tagFORMATETC fmtetc;
uint pcelFetched=0;
enumFORMATETC.RemoteNext(1, out fmtetc,out pcelFetched);
STGMEDIUM medium = new STGMEDIUM();
do{
int idFormat = (int)fmtetc.cfFormat;
if (idFormat == (DataFormats.GetFormat(DataFormats.FileDrop)).Id){
unsafe
{
uint[] data = new uint[1024];
fixed (uint * pointerToFileName = data)
{
System.IntPtr IntPtrPointer= new System.IntPtr(pointerToFileName);
pDataObj.RemoteGetData(ref fmtetc,IntPtrPointer); // Call to the RemoteGetData (the second value must be a STGMEDIUM on a well done dll.
// at this point:
// data[0] = 15 (the CF_HDROP defined VALUE)
// data[1] = (maybe a pointer to something)
// data[2,...] = 0
p = new string((char *)data[1]); // This generate a corrupted String, maybe because this is a pointer to a union, i have more code but no way for to catch the file name of the file dropped
}
}
}
}while (((int)fmtetc.cfFormat) != 0)
all help is well recived