Control supporting Windowless mode.

Hello.

I need to create COM object that support

IOleInPlaceObjectWindowless

System.Windows.Forms.Control doesn't support this interface. That's why i decide to implement similar control that can be activated in windowless mode. I uses

using Microsoft.VisualStudio.OLE.Interop;

library that contain IOle interfaces.

[Guid("66F34D16-6DCC-42d6-B7CF-788216B72C0F")]

[ClassInterface(ClassInterfaceType.None)]

[ComDefaultInterface(typeof(IMyControl))]

publicpartialclassMyControl

:Component

,IMyControl

,IOleObject

{

public MyControl()

{

InitializeComponent();

.....

publicint GetUserType(uint dwFormOfType,IntPtr userType)

{

if (dwFormOfType == 1)

{

userType =Marshal.StringToHGlobalAnsi(GetType().FullName);

}

else

{

userType =Marshal.StringToHGlobalAnsi( GetType().Name );

}

return 0;

}

.....

}

When I tried to insert this control in tstcon32 application during calling first function GetUserType() this app crashed...

Where I mistaked?..

Maybe other way of creating Windowless control in .NET is exist...

[2797 byte] By [AlexeyE.Rybakov-CpsLabs] at [2008-1-6]
# 1
This code doesn't look good. You'd want to pass userType with the "out" keyword. And the dwFormOfType argument tells you the format of the string it wants, not how it is stored. If this code compiles, there's something wrong with your declaration of IOleObject. The GetUserType() method declaration should look like this:

[PreserveSig]
int GetUserType([In, MarshalAs(UnmanagedType.U4)] int dwFormOfType,
[MarshalAs(UnmanagedType.LPWStr)] out string userType);

I copied this from the internal declaration I found in System.Windows.Forms.dll with Reflector. Afaik, Windows Forms has no support for windowless controls at all. Good luck!

nobugz at 2007-10-2 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 2

Thank you for you reply!

I have reflected library and copied code from thare into my aplication. It is work now.

But I need to create an analog of System.Windows.Forms.Control it can take much time...

Have you variant why Microsoft doesn't implement windowless mode for NET Forms control (MFC realization support windowless mode)?

Maybe some problems can appearing during implementaion?...

AlexeyE.Rybakov-CpsLabs at 2007-10-2 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 3
Windowless controls was something that was important 10 years ago when Windows still could only supply a limited number of window handles to an app. That hasn't been a problem since Windows NT became the grand father of all new versions. Windows Forms subsequently gave up on the idea. Although they are back in the .NET 2.0 version with the ToolStrip control. Not based on IOleInPlaceObjectWindowless though.

You are probably going to have a heck of a time making it work in .NET, you'll have to implement lots of interfaces. Doing it in C++ with MFC or ATL seems a much better idea, especially since you can borrow a lot of existing code. There was a project that created light weight controls. It has been shutdown for a while but the source code is still available.

nobugz at 2007-10-2 > top of Msdn Tech,.NET Development,.NET Base Class Library...

.NET Development

Site Classified