Hi,
I have an old problem which I couldn't solve so far. Now I have found a post
in that group that gave me an idea, but I can not fully understand it.
The problem is: I'm trying to use a Windows.Forms.U serControl in a COM
environment, i.e. I want to host that control in a COM host. So far, so
good, I can host it, but I can not reach the parent COM object from the
control (Parent property is null :( ).
I have stopped the control in the debugger and I found in the watch window
some properties, like ActiveXInstance
{System.Windows .Forms.Control. ActiveXImpl}
The problem is that they are private to the base class, so I can not access
them.
Now the question: is it possible somehow to access these base properties
programmaticall y. I have found a post which mentions something about
reflection (whatever that mean). Can I use a reflection to access these
properties?
Any help will be highly appreciated.
Thanks
Sunny
Nov 15 '05
10 7366
Your code has been really helpful to me, as I encountered exactly the
same problem as Sunny (i.e. adding property pages to Outlook), except
that I'm using VB.NET. I thought that anyone trying to achieve this
may be interested to know that the code can be simplified to the
following:-
Public ReadOnly Property PageSite() As PropertyPageSit e
Get
Dim typeUnsafeNativ eMethods As Type = GetType
_(Windows.Forms .Control).Assem bly.GetType
_("System.Windo ws.Forms.Unsafe NativeMethods")
Dim typeOleObject As Type =
typeUnsafeNativ eMethods.GetNes tedType _("IOleObject ")
Dim methodGetClient Site As Reflection.Meth odInfo = _
typeOleObject.G etMethod("GetCl ientSite")
Dim site As Object = methodGetClient Site.Invoke(Me,
Nothing)
Try
Return CType(site, PropertyPageSit e)
Catch ex As InvalidCastExce ption
'Handle the exception
End Try
End Get
End Property
The above PageSite property is added to your class that implements the
Outlook.Propert yPage interface.
One further necessity though, will probably be to set the caption of
the property page (the tab heading). In order to do this, I found that
I had to define my own interface as follows (substitute a GUID where
the x's are):-
<GuidAttribute( "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"),
InterfaceTypeAt tribute _ (ComInterfaceTy pe.InterfaceIsI Dispatch)> _
Public Interface IMyProperties
Inherits PropertyPage
<DispId(-518)> ReadOnly Property Caption() As String
End Interface
Instead of implementing Outlook.Propert yPage, your class would then
implement IMyProperties.
"Sunny" <su******@icebe rgwireless.com> wrote in message news:<O0******* *******@TK2MSFT NGP10.phx.gbl>. .. Hi Vladimir, IT WORKS IT WORKS. You are great. I have implemented this in C# and it gave me the reference I needed. I suppose, that I had to implement all of your code, but I stopped at the check for site is Nothing, because I can cast it at the type I want. So, I do not know what the rest of the code have to do. If you have a little time, pls, explain. Nevertheless so far, you are the only guy around who have succeeded to solve that problem. I have posted it allover, with different ideas, but ... nothing.
Thank you again Sunny
"Vladimir Kouznetsov" <vl************ *****@REMOVETHI Sngrain.com> wrote in message news:O9******** ******@TK2MSFTN GP09.phx.gbl... Here is a sample code (in VB but it shouldn't not be difficult to translate it) I used to get UserMode property:
Dim strAssembly As String strAssembly = Type.GetType("S ystem.Object"). Assembly.CodeBa se.Replace("msc orlib.dll", "System.Windows .Forms.dll") strAssembly = strAssembly.Rep lace("file:///", String.Empty) strAssembly = Reflection.Asse mblyName.GetAss emblyName(strAs sembly).FullNam e Dim unmt As Type = _ Type.GetType(Re flection.Assemb ly.CreateQualif iedName(strAsse mbly, "System.Windows .Forms.UnsafeNa tiveMethods")) Dim ioot As Type = unmt.GetNestedT ype("IOleObject ") Dim mi As Reflection.Meth odInfo = ioot.GetMethod( "GetClientSite" ) Dim site As Object = mi.Invoke(Me, Nothing) If site Is Nothing Then Return -1
' We are hosted by a COM container
Dim dsite As IDispatch = site
' All the uninitialized arguments work fine in this case Dim id As Guid Dim params As DISPPARAMS Dim lcid As System.UInt32 Dim wFlags As System.UInt16 = System.UInt16.P arse(2.ToString ()) Dim result As Object dsite.Invoke(-709, id, lcid, wFlags, params, result, Nothing, Nothing)
If result Then Return 1 Else Return 0 End If
That should give you an idea how to do what you want. IIRC IOleClientSite has method GetContainer() which I think you need (not the parent COM object). BTW You can use ildasm on System.Windows. Forms.dll to make yourself familiar with the internal classes and implementations .
thanks, v
"Sunny" <su******@icebe rgwireless.com> wrote in message news:ui******** ******@tk2msftn gp13.phx.gbl... Hi, it seems that I have to guess what property to get, so I'll play with all of them, but that happen always with combination COM/.Net/Outlook :) The problem is, that I have read some of docs for reflection, and I still have no idea where to start and how to access these private members :( So any example will be helpful.
Sunny
"Ignacio Machin" <ignacio.mach in AT dot.state.fl.us > wrote in message news:ul******** ********@TK2MSF TNGP12.phx.gbl. .. > Hi Sunny, > > > I think that yes, it's possible to access the private properties of a class > using reflection, I haven't tested it but I also saw the post of Nicholas > and until now all that he said is true ;) , the thing is ( also stated in > the post ) what are you planning to do with it? it;s a private property and > you have no idea of how it's used or what it means. > > Cheers, > > -- > Ignacio Machin, > ignacio.machin AT dot.state.fl.us > Florida Department Of Transportation > > "Sunny" <su******@icebe rgwireless.com> wrote in message > news:uO******** *****@tk2msftng p13.phx.gbl... > > Hi, > > I have an old problem which I couldn't solve so far. Now I have found a post > > in that group that gave me an idea, but I can not fully understand it. > > The problem is: I'm trying to use a Windows.Forms.U serControl in a COM > > environment, i.e. I want to host that control in a COM host. So far, so > > good, I can host it, but I can not reach the parent COM object from the > > control (Parent property is null :( ). > > I have stopped the control in the debugger and I found in the watch window > > some properties, like ActiveXInstance > > {System.Windows .Forms.Control. ActiveXImpl} > > The problem is that they are private to the base class, so I can not access > > them. > > > > Now the question: is it possible somehow to access these base properties > > programmaticall y. I have found a post which mentions something about > > reflection (whatever that mean). Can I use a reflection to access these > > properties? > > > > Any help will be highly appreciated. > > > > Thanks > > Sunny > > > > > >
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: vijay |
last post by:
Hello
I wanted to understand a contradictory design of C++
class A
{public:
virtual void f(){ cout<<" base f"<<endl; }
};
class B:public A
{
|
by: Alf P. Steinbach |
last post by:
#include <iostream>
struct Belcher
{
int x;
void belch() { std::cout << x << std::endl; }
Belcher( int anX ): x( anX ) {}
};
struct Person: private Belcher { Person(): Belcher( 666 ) {} };
|
by: Marc Scheuner [MVP ADSI] |
last post by:
Folks,
I've created a descendant of ListView, and I would like to be able to
tell it to "hide" two of the base class's properties - how can I
accomplish this?
I know I can add a attribute to the properties to
remove them from the object inspector window - that's not all, though
- I'd like to make them unavailable from code, too.
|
by: Chris |
last post by:
Hi
I am trying to create a base class with the Protected keyword
Protected MustInherit Class MyBaseClas
..
..
End Clas
And I got an error saying something like the Protected keyword cannot be used
|
by: Taran |
last post by:
Hi All,
I tried something with the C++ I know and some things just seem
strange.
consider:
#include <iostream>
using namespace std;
| |
by: Darren.Ratcliffe |
last post by:
Hi guys
Posted what was probably a rather confusing post about this the other
day, so I am going to have another go and see if I can make more sense.
This sis purely a
I've got a base class called animal, and from within animal you can
access lots more classes such as feline, canine, reptile and
amphibian.....
|
by: Tech quest |
last post by:
Hi,
I have a C# Class Libarary which is exposed to COM. The issue is base class members are not exposed to COM.As per msdn
http://msdn2.microsoft.com/en-us/library/8877bdk6(VS.80).aspx Managed Clas hierarchies flatten out when exposed as COM objects.
Please let me know how i can resove this issue. Thanks a lot in advance
Here is the sample Application Code:
The issue is base class member properties VehicleName ,Vehicle Type are not...
|
by: Charles Law |
last post by:
I have a base class MyBaseClass, and several classes that inherit from it:
MyClass1, MyClass2, etc.
The base class implements IEnumerable(Of IMyBaseClassRow). The base class
has a DataTable object that contains different data depending on which of
MyClass1, MyClass2 are instantiated.
I want to be able to iterate through the rows of the data table using For
Each on my derived classes retrieving a custom row with properties specific
to...
|
by: Charles Law |
last post by:
I have a base class and derived classes that relate to a set of documents I
process. e.g. DocBase, DocA, DocB, DocC. The processing of each document is
handled in teh derived classes, as you might imagine, but the base class has
properties and methods that are common to all documents.
The processing of each docuemnt can result in a range of document specific
errors, which I want to raise as events on the document object, but there
are...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| | |