Solved

MMC Console Handle

Posted on 2004-04-05
8
463 Views
Last Modified: 2010-05-18
Hi,

I wrote a MMC Extentin snapin. It launches a worker thread which checks periodically the existance of a file. When the file is deleted some nodes from the result pane have to be removed.

So, I call SelectScopeItem(...) to set the focus to an item which will not be deleted and then I call DeleteItem(...) to remove the nodes.

This works fine under Win2K (MMC1.20) but not under XP (MMC2.0) where SelectScopeItem fails.

I assume, that the ConsoleHandle(IConsole) I use is not longer valid when using from a worker thread.

Has anyone experiences with such a constellation ??

How can console handles be used from a thread ?
Or:
How can Messages be posted into Notify() as if the user has selected "Delete" from the context menue.
And:
Does anyone know how to disable the "New Window from here" feature for a Snapin ??

THANX a lot

   TheGasmann

0
Comment
Question by:TheGasmann
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
8 Comments
 
LVL 3

Accepted Solution

by:
akalmani earned 500 total points
ID: 10755881
>>Does anyone know how to disable the "New Window from here" feature for a Snapin ??
There is a way for this. I do not know how to do it via the snap-in code. But another way which I used in my application.

Add only your snap-in to MMC and in the File->Options
Specify the title for the window. In the console mode use "User mode - Limited access, single window"

Save your file by closing the snap-in window as "MySnapIn.sys"

That's it. You need to distribute *.sys file along with your snap-in.
You need to save for Win2K and WinXP these *.sys files separately as the file format has been changed by Microsoft in respective OS.
0
 
LVL 3

Assisted Solution

by:akalmani
akalmani earned 500 total points
ID: 10755943
>>>How can console handles be used from a thread ?
Well you can make the console pointer as global variable and use it in worker thread.
I had used earlier in my snap-in as a global variable but of IConsole2 not IConsole.

In the class which derives from IComponent, there is an Initialize method which will be called. So make sure you store the IConsole2 * global variable in this function.

IConsole2 *g_pIConsole2;//Declare this in any one of the header files.

HRESULT CComponent::Initialize(/* [in] */ LPCONSOLE r_lpConsole)
{
  //Get the IConsole2 interface and store it
  r_lpConsole->QueryInterface(IID_IConsole2, (void **)&g_pIConsole2);
}

Make sure you release the interface in the end.
0
 
LVL 3

Assisted Solution

by:akalmani
akalmani earned 500 total points
ID: 10755985
>>>>How can Messages be posted into Notify() as if the user has selected "Delete" from the context menue ??

You also need a global pointer to IConsoleNameSpace2 * g_pIConsoleNameSpace2;

//In your CComponentData which implements IComponentData store the IConsoleNameSpace2* something like this
HRESULT CComponentData::Initialize(/* [in] */ LPUNKNOWN r_lpUnknown)
{
   //Get pointer to name space interface
    hResult = r_lpUnknown->QueryInterface(IID_IConsoleNameSpace,
                     (void **)&g_pIConsoleNameSpace2);
}

In your worker thread using this pointer you can directly delete the item.
g_pIConsoleNameSpace2->DeleteItem(ParentScopeItem, FALSE);


Make sure you release the interface in the end.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:akalmani
ID: 10756006
0
 

Author Comment

by:TheGasmann
ID: 10756398
Well, the topic with the .sys file is new to me.
Quite a bit hard to distribute ...

But the other problems:
This is exactly what I do. But it doesn't work under XP (fine under 2000)
Especially when you select "new Window from here" and the new window shows nodes which are to be removed I get an Access violation :-(
0
 
LVL 3

Assisted Solution

by:akalmani
akalmani earned 500 total points
ID: 10984240
Even though the the asker does not like the answer, an answer was provided for 1 question.
0
 

Author Comment

by:TheGasmann
ID: 10984367
Sorry, I was on vacation and I forgot about this question.

So, the answer did not solve my problem, but as akalmani was the only one who answered I will give her/him the points for the effort she/he took.

Final comments:

* Sharing console handles with worker threads is NOT safe!
Calling Delete() from a worker thread might lead to a crash of the MMC :-(

* Some things got worse under XP (compared to Win2000).

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question