Hi i have an application hosting webbrowser control in design mode. I also
wrote a custom OleUndoManger. My problem is if I move or resize a html
element the application crashes. With NullPointerException.
Can anybody check if the definition is correct?
TIA dom
Please respond on
d-dot-mohl-at-hico-dot-com
Here is my definition of the ole interfaces:
[ComVisible(true), Guid("B3E7C340-EF97-11CE-9BC9-00AA00608E01"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IEnumOleUndoUnits {
[return: MarshalAs(UnmanagedType.I4)]
[PreserveSig]
int Next(
[In, MarshalAs(UnmanagedType.U4)]
int numDesired,
[Out, MarshalAs(UnmanagedType.Interface)]
out IOleUndoUnit unit,
[Out, MarshalAs(UnmanagedType.U4)]
out int numReceived);
[PreserveSig]
int Skip(
[In, MarshalAs(UnmanagedType.I4)]
int numToSkip);
[PreserveSig]
int Reset();
[PreserveSig]
int Clone(
[Out, MarshalAs(UnmanagedType.Interface)]
out IEnumOleUndoUnits enumerator);
};
[ComVisible(true), Guid("A1FAF330-EF97-11CE-9BC9-00AA00608E01"),
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
public interface IOleParentUndoUnit : IOleUndoUnit {
[return: MarshalAs(UnmanagedType.I4)]
[PreserveSig]
int Open(
[In, MarshalAs(UnmanagedType.Interface)]
IOleParentUndoUnit parentUnit);
[return: MarshalAs(UnmanagedType.I4)]
[PreserveSig]
int Close(
[In, MarshalAs(UnmanagedType.Interface)]
IOleParentUndoUnit parentUnit,
[In, MarshalAs(UnmanagedType.Bool)]
bool fCommit);
[return: MarshalAs(UnmanagedType.I4)]
[PreserveSig]
int Add(
[In, MarshalAs(UnmanagedType.Interface)]
IOleUndoUnit undoUnit);
[return: MarshalAs(UnmanagedType.I4)]
[PreserveSig]
int FindUnit(
[In, MarshalAs(UnmanagedType.Interface)]
IOleUndoUnit undoUnit);
[return: MarshalAs(UnmanagedType.I4)]
[PreserveSig]
int GetParentState(
[Out, MarshalAs(UnmanagedType.I4)]
out int state
);
}
[ComVisible(true), ComImport(),
Guid("6D5140C1-7436-11CE-8034-00AA006009FA"),
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
public interface IOleServiceProvider {
[return: MarshalAs(UnmanagedType.I4)]
[PreserveSig]
int QueryService(
[In] ref Guid guidService,
[In] ref Guid riid,
out IntPtr ppvObject);
}
[ComVisible(true), Guid("D001F200-EF97-11CE-9BC9-00AA00608E01"),
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
public interface IOleUndoManager {
[PreserveSig]
int Open(
[In, MarshalAs(UnmanagedType.Interface)]
IOleParentUndoUnit parentUndo);
[PreserveSig]
int Close(
[In, MarshalAs(UnmanagedType.Interface)]
IOleParentUndoUnit parentUndo,
[In, MarshalAs(UnmanagedType.Bool)]
bool fCommit);
[PreserveSig]
int Add(
[In, MarshalAs(UnmanagedType.Interface)]
IOleUndoUnit undoUnit);
[return: MarshalAs(UnmanagedType.I4)]
int GetOpenParentState();
[PreserveSig]
int DiscardFrom(
[In, MarshalAs(UnmanagedType.Interface)]
IOleUndoUnit undoUnit);
void UndoTo(
[In, MarshalAs(UnmanagedType.Interface)]
IOleUndoUnit undoUnit);
void RedoTo(
[In, MarshalAs(UnmanagedType.Interface)]
IOleUndoUnit undoUnit);
[return: MarshalAs(UnmanagedType.Interface)]
IEnumOleUndoUnits EnumUndoable();
[return: MarshalAs(UnmanagedType.Interface)]
IEnumOleUndoUnits EnumRedoable();
[return: MarshalAs(UnmanagedType.BStr)]
string GetLastUndoDescription();
[return: MarshalAs(UnmanagedType.BStr)]
string GetLastRedoDescription();
void Enable(
[In, MarshalAs(UnmanagedType.Bool)]
bool fEnable);
}
[ComVisible(true), Guid("894AD3B0-EF97-11CE-9BC9-00AA00608E01"),
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
public interface IOleUndoUnit {
[return: MarshalAs(UnmanagedType.I4)]
[PreserveSig]
int Do(
[In, MarshalAs(UnmanagedType.Interface)]
IOleUndoManager undoManager);
[return: MarshalAs(UnmanagedType.I4)]
[PreserveSig]
int GetDescription(
[Out, MarshalAs(UnmanagedType.BStr)]
out string bStr);
[return: MarshalAs(UnmanagedType.I4)]
[PreserveSig]
int GetUnitType(
[Out]
out Guid clsid,
[Out, MarshalAs(UnmanagedType.I4)]
out int plID);
[return: MarshalAs(UnmanagedType.I4)]
[PreserveSig]
int OnNextAdd();
}
Mattias Sj?gren - 19 Jan 2005 21:31 GMT
>[ComVisible(true), Guid("B3E7C340-EF97-11CE-9BC9-00AA00608E01"),
>InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[quoted text clipped - 8 lines]
> [Out, MarshalAs(UnmanagedType.U4)]
> out int numReceived);
Since it's legal to pass a NULL pointer for numRecieved, you should
declare the last parameter as an IntPtr passed by value. You can then
write the number of returned elements with Marshal.WriteInt32().
>[ComVisible(true), Guid("A1FAF330-EF97-11CE-9BC9-00AA00608E01"),
>InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
>public interface IOleParentUndoUnit : IOleUndoUnit {
Interface inheritance doesn't work as you expect with COM interop.
IOleParentUndoUnit must redeclare all methods from the IOleUndoUnit
interface.
And finally, you ought to mark these interfaces with the ComImport
attribute.
Mattias

Signature
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.