Solved

MMC Console Handle

Posted on 2004-04-05
8
462 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

730 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