?
Solved

MMC Console Handle

Posted on 2004-04-05
8
Medium Priority
?
487 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
  • 5
  • 2
7 Comments
 
LVL 3

Accepted Solution

by:
akalmani earned 1500 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 1500 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 1500 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 1500 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

615 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