Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 19th, 2003, 02:54 PM
Registered User
 
Join Date: Nov 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default warning generating dll with IDataObject

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






Similar Threads
Thread Thread Starter Forum Replies Last Post
What am I doing wrong- Generating .dll chobo2 C# 2008 aka C# 3.0 2 December 7th, 2008 04:56 PM
convert unmanaged dll to managed dll nitesh kumar Visual C++ 2005 0 August 4th, 2008 04:53 AM
Install problems - VS 6.0 on XP SCRRUN.DLL PDM.DLL jeff4444 Visual C++ 0 December 6th, 2006 08:48 PM
The database dll crdb_oracle.dll could not be load Yeliz Crystal Reports 0 October 18th, 2006 08:12 AM
DLL & Excel - keep having to reset DLL reference! James Diamond Pro VB 6 2 May 25th, 2004 03:37 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.