Solved

MMC Console Handle

Posted on 2004-04-05
8
455 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
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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 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.

777 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