描述:
想调用这样的一个方法INetSharingConfiguration::DisableInternetFirewall,作用是在Xp或以后的操作系统中弹出一个对话框,作用是询问用户是否关闭系统的防火墙,该方法是基于COM的。
头文件有NetCon.h和NetCon.idl,
请我在我的应用程序里面该如何调用该方法?!
小弟对COM知之甚少,请说的详细一点,谢谢!
MSDN的描述:
The DisableInternetFirewall method disables Internet Connection Firewall on this connection.
……
Use the INetSharingManager::get_INetSharingConfigurationForINetConnection method to obtain an INetSharingConfiguration interface for a particular connection.
Client: Included in Windows XP.
Header: Declared in Netcon.idl.
Library: Included as a resource in HNetCfg.dll.
解决方案1:
#import "D:\\Windows\\system32\\HNetCfg.dll" rename_namespace("HNC")
==========================================================================
void main()
{
::CoInitialize(NULL);
{
HNC::INetSharingManagerPtr pNSM;
HRESULT hr = pNSM.CreateInstance(__uuidof(HNC::NetSharingManager));
HNC::INetSharingEveryConnectionCollectionPtr pNSECC = pNSM->EnumEveryConnection;
if (pNSECC != NULL)
{
IEnumVARIANTPtr pEnum = pNSECC->_NewEnum;
if (pEnum != NULL)
{
HNC::INetConnectionPtr pNC;
HNC::INetSharingConfigurationPtr pNSC;
ULONG fetched;
VARIANT rg;
do
{
pEnum->Next(1UL, &rg, &fetched);
if (fetched != 0)
{
pNC = rg.pdispVal;
pNSC = pNSM->GetINetSharingConfigurationForINetConnection(pNC);
// pNSC->DisableInternetFirewall();
// pNSC->EnableInternetFirewall();
}
} while (fetched != 0);
}
}
}
::CoUninitialize();
}
============================================================================