首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

显示:无法打开包含文件:“wincred.h”: No such file or directory ,如何解决

2012-02-28 
显示:无法打开包含文件:“wincred.h”: No such file or directory ,怎么解决?编译的时候,遇到这个问题:无法

显示:无法打开包含文件:“wincred.h”: No such file or directory ,怎么解决?
编译的时候,遇到这个问题:

无法打开包含文件:“wincred.h”:   No   such   file   or   directory   ,怎么解决?

怎么解决?

代码如下:
===============================================================
//   WMIS.cpp   :   定义控制台应用程序的入口点。
//

#include   "stdafx.h "

#define   _WIN32_DCOM
#include   <iostream>
using   namespace   std;
#include   <comdef.h>
#include   <Wbemidl.h>
#   pragma   comment(lib,   "wbemuuid.lib ")
#   pragma   comment(lib,   "credui.lib ")
#include   <wincred.h>

int   _tmain(int   argc,   _TCHAR*   argv[])
{
HRESULT   hres;

        //   Step   1:   --------------------------------------------------
        //   Initialize   COM.   ------------------------------------------

        hres   =     CoInitializeEx(0,   COINIT_MULTITHREADED);  
        if   (FAILED(hres))
        {
                cout   < <   "Failed   to   initialize   COM   library.   Error   code   =   0x "  
                        < <   hex   < <   hres   < <   endl;
                return   1;                                     //   Program   has   failed.
        }

        //   Step   2:   --------------------------------------------------
        //   Set   general   COM   security   levels   --------------------------
        //   Note:   If   you   are   using   Windows   2000,   you   need   to   specify   -
        //   the   default   authentication   credentials   for   a   user   by   using
        //   a   SOLE_AUTHENTICATION_LIST   structure   in   the   pAuthList   ----
        //   parameter   of   CoInitializeSecurity   ------------------------

        hres   =     CoInitializeSecurity(
                NULL,  
                -1,                                                     //   COM   authentication
                NULL,                                                 //   Authentication   services
                NULL,                                                 //   Reserved


                RPC_C_AUTHN_LEVEL_DEFAULT,       //   Default   authentication  
                RPC_C_IMP_LEVEL_IMPERSONATE,   //   Default   Impersonation    
                NULL,                                                 //   Authentication   info
                EOAC_NONE,                                       //   Additional   capabilities  
                NULL                                                   //   Reserved
                );

                                           
        if   (FAILED(hres))
        {
                cout   < <   "Failed   to   initialize   security.   Error   code   =   0x "  
                        < <   hex   < <   hres   < <   endl;
                CoUninitialize();
                return   1;                                         //   Program   has   failed.
        }
       
        //   Step   3:   ---------------------------------------------------
        //   Obtain   the   initial   locator   to   WMI   -------------------------

        IWbemLocator   *pLoc   =   NULL;

        hres   =   CoCreateInstance(
                CLSID_WbemLocator,                          
                0,  
                CLSCTX_INPROC_SERVER,  
                IID_IWbemLocator,   (LPVOID   *)   &pLoc);
 
        if   (FAILED(hres))
        {
                cout   < <   "Failed   to   create   IWbemLocator   object. "
                        < <   "   Err   code   =   0x "
                        < <   hex   < <   hres   < <   endl;
                CoUninitialize();


                return   1;                                   //   Program   has   failed.
        }


[解决办法]
在VS 2005 没问题。
#include <wincred.h>
改成:#include "wincred.h "试试。
[解决办法]
顶楼上

热点排行