This document is archived and information here might be outdated. Recommended version. |
A reference to the currently running application.
Interfaces | Description |
---|---|
IApplication | Provides access to members that query or modify the application. |
If for some reason you can't easily get a reference to the Application object in your code, you can create a new AppRef object. For example, there are cases where you may implement an object that exists within the application framework but there is no way to traverse the application hierarchy from that object. In order to provide developers access to the application object there is a singleton object that provides a pointer to the running application object.
Note you can only use the AppRef object if your code is running inside one of the ArcGIS application processes.
Since AppRef is a singleton, you should use the Activator class to create an instance of it.
// Get the actual underlying COM type
Type t = Type.GetTypeFromCLSID(typeof(AppRefClass).GUID);
// Or if ProgID or CLSID is known, use it directly
//Type t = Type.GetTypeFromProgID("esriFramework.AppRef");
//Type t = Type.GetTypeFromCLSID(new Guid("e1740ec5-9513-11d2-a2df-0000f8774fb5"));
System.Object obj = Activator.CreateInstance(t);
IApplication app = obj as IApplication;
Since AppRef is a singleton, you should use the Activator class to create an instance of it.
Dim t As Type = Type.GetTypeFromProgID("esriFramework.AppRef")
Dim obj As System.Object = Activator.CreateInstance(t)
Dim app As IApplication = obj