0% found this document useful (0 votes)
195 views3 pages

MMC Snapin

The Snap-in Designer for Microsoft(r) Visual Basic allows snap-ins to be written in Visual Basic. The designer window is used to define most of the snap-in's UI and run-time behavior. Code for events that can't be defined at design time is written in the designer's code window.

Uploaded by

rajes_india
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
195 views3 pages

MMC Snapin

The Snap-in Designer for Microsoft(r) Visual Basic allows snap-ins to be written in Visual Basic. The designer window is used to define most of the snap-in's UI and run-time behavior. Code for events that can't be defined at design time is written in the designer's code window.

Uploaded by

rajes_india
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd

Introduction

The Snap-in Designer for Microsoft® Visual Basic® is a development tool that enables Microsoft® Management Console snap-ins to be
written in Visual Basic. The Snap-in Designer supports development of MMC 1.1 and MMC 1.2 snap-ins only (the Snap-in Designer does
not support MMC 2.0 features). The Snap-in Designer is installed when you install the MMC samples from the Platform SDK. The following
topics provide an overview of the designer's features and introduce basic concepts.
Software Requirements
The following software is required to run the Snap-in Designer for Visual Basic:
• Microsoft Windows NT® Workstation or Server version 4.0 with Service Pack 3 or later, or Microsoft Windows® 2000, or
Microsoft Windows® 98, or Microsoft Windows Me
• Microsoft Visual Basic version 6.0 (no specific service pack required)
• Microsoft Management Console version 1.1 or later
To install the Snap-in Designer, install the MMC samples from the Platform SDK.
What Is the Snap-in Designer?
The Snap-in Designer for Visual Basic is an ActiveX® designer that allows a snap-in to be written entirely in Visual Basic. The designer
supports 100% of MMC 1.1 and MMC 1.2 functionality, so a Visual Basic snap-in can do anything that can be done in a C++ snap-in for
MMC 1.1 and 1.2. The Snap-in Designer does not support MMC 2.0 features. When the snap-in designer is installed, it is integrated into
the Visual Basic integrated development environment (IDE) and it adds a new project type called "SnapIn."
The designer window is used to define most of the snap-in's user interface (UI) and run-time behavior. For behavior that can't be defined
at design time, you write code for event handlers in the designer's code window. Examples of events are toolbar button clicks, menu
clicks, snap-in loading, and so on. This is similar to using a Visual Basic form and writing code for events that occur throughout the form's
life cycle and when the user interacts with its UI. Double-clicking any element in the designer window takes you to the relevant event
handler in the code window.
The snap-in's code uses an object model defined by the designer that maps all of the UI elements in a snap-in. This is similar to a Visual
Basic form in that the form object has its properties and events and all of the controls on the form have their properties and events.
Snap-ins can be debugged in Visual Basic's source debugger and they can be compiled into DLLs. The Visual Basic Package and
Deployment Wizard can be used to create a setup program for your snap-in.
The designer allows for rapid development of snap-ins and requires significantly less code than C++ snap-ins. Both development and test
time are greatly reduced and the learning curve is much shorter for new snap-in programmers. Simple snap-ins such as menu extensions
can be written with a tiny amount of MMC "plumbing" code. For example, the ComDetect sample snap-in that extends the FileExplorer
sample's context menus contains 35 lines of code and only 8 of them pertain to interfacing with MMC. Much of the very complex code in
C++ snap-ins has been vastly simplified so features such as multiple selection in list views require no more than a few lines of very easy
coding.
What Is an ActiveX Designer?
An ActiveX designer is an in-process ActiveX object that extends the functionality of the Visual Basic IDE. Visual Basic 6.0 ships with
numerous ActiveX designers such as the Data Environment Designer, the DHTML Page Designer, webclasses, and so on. Designers must
be written in C++ and they consist of a design-time component and a run-time DLL. Visual Basic defines a special set of interfaces in
addition to the standard ActiveX control interfaces that it uses to communicate with designers. These interfaces allow a designer to
seamlessly integrate into the IDE and handle such things as saving and loading of the designer's state information, registration,
debugging, and so on.
When a designer is installed it appears on the Designers tab in the Components dialog box from the Project menu. When a designer is
added to a project it appears like any other project window such as a form or a UserControl object. The developer interacts with the
designer window to enter as much information as possible to determine its run-time behavior. When the project is saved the designer
saves its information into a .dsr file and a .dsx file. This is similar to the way a form saves its information into an .frm file and an .frx file.
When the project is compiled into a DLL, the designer stores all of the settings entered by the developer as well as registration
information in the compiled DLL. Visual Basic also stores all of the compiled event handler code in the DLL. The DLL can be registered
just like any ActiveX DLL by using Regsvr32.exe.
When the designer object is loaded at run time, (for example, when MMC loads your snap-in), the Visual Basic runtime is loaded and then
it loads the designer's runtime DLL and gives it the information stored at design time. The designer runtime communicates with the
containing application (MMC.exe in the case of snap-ins) and uses the design-time information to answer most of the container's
requests. When the designer runtime cannot answer a request or it needs to give the snap-in the opportunity to customize the response,
it fires an event into the compiled Visual Basic code. The code you wrote for the event handler is run and will typically call back into the
runtime using the object model or return a value that tells the runtime how to respond to the container. The snap-in designer runtime
implements every method of every C++ interface defined by MMC. Calls into the object model either store information to be returned
later to MMC or make calls to one of MMC's interfaces.
Starting a Snap-in Project
To start a snap-in project
1. Start Visual Basic 6.0.
2. If the New Project dialog box is not open, on the File menu, click New Project. In the New Project dialog box select
SnapIn.
Note If the New Project dialog doesn't present a SnapIn project, then copy the files located in your C:\Program Files\Microsoft
Platform SDK\Samples\SysMgmt\MMC\Visual Basic\Template\ directory to your C:\Program Files\Microsoft Visual
Studio\VB98\Template\Projects\ directory. Additionally, for the snap-in designer to run properly, you must register the mmcproxy.dll,
mssnapd.ocx, and mssnapr.dll files. These files are in the C:\Program Files\Microsoft Platform SDK\bin folder, and they can be registered
by using the regsvr32 command. Substitute equivalent paths if your installation of the Platform SDK or Visual Basic did not use the paths
listed here.
3. Double-click SnapIn1 in the Project window to open the designer.
You may notice that in addition to the snap-in designer, the project also contains a user control called SnapInControl. This user control
does not contain any code or controls. It is used when adding property pages to your snap-in. Do not remove SnapInControl from your
project.
The Designer Window
The designer window displays a tree view in which each node represents a set of properties related to some aspect of your snap-in. It is
used to define the characteristics of your snap-in and also serves as documentation of the elements of your snap-in. Selecting any node
shows the related properties in Visual Basic's property browser window (usually in the lower-right portion of the IDE). Most nodes have
associated property sheets that can be invoked from the context menu or from the toolbar.
The structure of the tree view generally does not map to the nodes that your snap-in will add to MMC's scope pane. It is simply used as a
visual tool to organize the properties of the snap-in.
The root node of the tree view displays the name of your snap-in. When a new snap-in project is started it displays SnapIn1. You should
change SnapIn1 to your snap-in's name immediately after starting the project.
The Extensions node always has an entry for your snap-in. Using the context menu you can specify which features of the console your
snap-in implements (that is, which features of the console it extends). If your snap-in extends other snap-ins' node types, then they will
also appear along with the features extended.
The Nodes section describes nodes that your snap-in will add to MMC's scope pane at run time. The Auto-Create section describes nodes
that will automatically be added by the designer runtime. This section of the tree view does actually map to the appearance of the nodes
in MMC's scope pane at run time. The Other section describes nodes that will be added programmatically by your snap-in (for example, in
response to the user expanding an existing node). Any node can have result views and child nodes.
The Tools section contains entries for all of the image lists, menus, and toolbars used by your snap-in.
The Result Views section contains entries for every result view defined by your snap-in. Every result view that appears in the Nodes
section also appears in the Result Views section.
Building a Snap-in Project
To build a snap-in project
1. Start a snap-in project.
2. On the File menu, click Make SnapIn.ocx.
3. When prompted for the file name, change the extension to .dll. A snap-in project is derived from an ActiveX control project so
Visual Basic suggests an .ocx extension. There is no requirement to change the extension to .dll, but snap-ins generally use .dll
rather than .ocx.
4. After the DLL has been built, on the Project menu, click Properties.
5. Click the Component tab.
6. Select Binary Compatibility. This ensures that the snap-in will always use the same CLSID
Deploying a Snap-in
A snap-in created in Visual Basic needs the following components on a target computer:
1. The DLL created by Visual Basic
2. The snap-in designer runtime (mssnapr.dll)
3. The Visual Basic 6.0 runtime
You can use the Visual Basic Package and Deployment Wizard to create a setup program for your snap-in. If you would like to manually
deploy your snap-in on a computer that already has the Visual Basic 6.0 runtime installed, do the following:
1. Copy your snap-in's DLL to your target directory.
2. Copy mssnapr.dll to
\Program Files\Common Files\Microsoft Shared\SnapInDesigner.
3. Use Regsvr32 to register both DLLs. The designer runtime (mssnapr.dll) must be registered before your snap-in's DLL. If it is not
registered first then registration of your snap-in's DLL will fail.
Note that registering your snap-in's DLL adds all of the necessary entries to the MMC keys under
HKEY_LOCAL_MACHINE\Software\Microsoft\MMC.
The Package and Deployment Wizard places the designer runtime in \Program Files\Common Files\Microsoft
Shared\SnapInDesigner. If you create your own setup program you must install the designer runtime in the same directory. Failure to
do this could cause installation problems for future versions of the designer.
When using the Package and Deployment Wizard you can also add a saved console file (.msc) to the package using the following steps:
1. Start the Package and Deployment Wizard and proceed to the form entitled "Package and Deployment Wizard - Included Files"
and click Add.
2. Select "All Files" in the Files of type drop-down list box.
3. Move to the saved console file (.msc), and click Open to add the file.
4. Proceed to the form entitled "Package and Deployment Wizard - Start Menu Items" and click New Item.
5. In the Target drop-down list box, click to select the .msc file.
6. In the Name text box, enter the name you want for your icon, and click OK.
7. Finish the Package and Deployment Wizard.
When the application is installed, the icon for the console file will be created in the Programs submenu of the Start menu.

Debugging a Snap-in
A snap-in can be debugged like any other Visual Basic project. Set your breakpoints and press F5 or click the run button on the toolbar.
Visual Basic will prompt for the program to run for debugging. There are two options:
1. Click Wait for components to be created, click OK, and then start MMC manually. During subsequent debugging sessions
Visual Basic will not prompt for these options. After pressing F5 you will only need to start MMC.
2. Click Start program: and enter the path to mmc.exe. Visual Basic will start MMC when you close the dialog box. During
subsequent debugging sessions Visual Basic will start MMC when you press F5. You can also save a console file (.msc) when
running your snap-in and specify its name as a parameter following the mmc.exe path. Subsequent debugging sessions will then
start MMC with your snap-in loaded. To change the debugging settings click Project, click Properties, and then click the
Debugging tab.
There are some caveats particular to snap-ins because while your snap-in is running within the Visual Basic IDE, MMC is running in a
separate process. This can make things like selection events (for example, Views_Select or Views_UpdateControlbar) difficult to debug
because new events are being fired while you step through the initial event. In general, it is advisable to remove the breakpoint and
press F5 after stepping through one of these event handlers so that MMC has a chance to process the selection changes. If you do not
remove the breakpoint you may find that it is hit repeatedly and you never have a chance to interact with MMC.

You might also like