Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/140.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ DHCP C++;错误LNK2019_C++_Dhcp - Fatal编程技术网

C++ DHCP C++;错误LNK2019

C++ DHCP C++;错误LNK2019,c++,dhcp,C++,Dhcp,考虑到下面的代码,如果有人能帮助我,我似乎无法理解为什么我会收到这个错误 代码: #include "StdAfx.h" #include "WINDOWS.H" #include "Dhcpcsdk.h" //#include "Dhcpcsvc.dll" #include <iostream> using namespace std; #define NUMBER_OF_OPTIONS 7 //#define NUMBER_OF_OPTIONS 4 enum Option

考虑到下面的代码,如果有人能帮助我,我似乎无法理解为什么我会收到这个错误

代码:

#include "StdAfx.h"
#include "WINDOWS.H"
#include "Dhcpcsdk.h"
//#include "Dhcpcsvc.dll"
#include <iostream>

using namespace std;

#define NUMBER_OF_OPTIONS 7


//#define NUMBER_OF_OPTIONS 4
enum OptionArrayPositions
{
   MASK,
   DNS,
   HOSTNAME,
   VENDOR,
   LEASE_TIME,
   MESSAGE_TYPE,
   SERVERIP
};

BOOL RetrieveDHCPInfo(LPWSTR pszAdapterName);
void PrintAsAscii(DHCPCAPI_PARAMS param);
void PrintAsIP(DHCPCAPI_PARAMS param);
void PrintAsInt(DHCPCAPI_PARAMS param);
void PrintMask(DHCPCAPI_PARAMS param);
void PrintDNS(DHCPCAPI_PARAMS param);
void PrintHostName(DHCPCAPI_PARAMS param);
void PrintVendor(DHCPCAPI_PARAMS param);
void PrintLeaseTime(DHCPCAPI_PARAMS param);
void PrintMessageType(DHCPCAPI_PARAMS param);
void PrintServerIP(DHCPCAPI_PARAMS param);

BOOL RetrieveDHCPInfo(LPWSTR pszAdapterName)
{
   DWORD dwError, dwSize;
   CHAR TmpBuffer[1000]; // host name won't be larger than this


   DHCPCAPI_PARAMS DhcpApiMaskParams = {0,
                                    OPTION_SUBNET_MASK,
                                    FALSE,
                                    NULL,
                                    0
                                    };
   DHCPCAPI_PARAMS DhcpApiDNSParams = {0,
                                    OPTION_DOMAIN_NAME_SERVERS,
                                    FALSE,
                                    NULL,
                                    0
                                    };
   DHCPCAPI_PARAMS DhcpApiHostNameParams = {0,                // Flags
                                       OPTION_HOST_NAME, // OptionId
                                       FALSE,            // vendor specific?
                                       NULL,             // data filled in on return
                                       0                 // nBytes
                                       }; 
   DHCPCAPI_PARAMS DhcpApiVendorParams = {0,
                                       OPTION_VENDOR_SPEC_INFO,
                                       FALSE,
                                       NULL,
                                       0
                                    };
   DHCPCAPI_PARAMS DhcpApiLeaseTimeParams = {0,
                                          OPTION_LEASE_TIME,
                                          FALSE,
                                          NULL,
                                          0
                                       };    
   DHCPCAPI_PARAMS DhcpApiMsgTypeParams = {0,
                                       OPTION_MESSAGE_TYPE,
                                       FALSE,
                                       NULL,
                                       0
                                       };

   DHCPCAPI_PARAMS DhcpApiServerNameParams = {0,
                                          OPTION_SERVER_IDENTIFIER,
                                          FALSE,
                                          NULL,
                                          0
                                          };

   DHCPCAPI_PARAMS paramArray[NUMBER_OF_OPTIONS] = { DhcpApiMaskParams, 
                                                DhcpApiDNSParams,
                                                DhcpApiHostNameParams, 
                                                DhcpApiVendorParams, 
                                                DhcpApiLeaseTimeParams,
                                                DhcpApiMsgTypeParams,
                                                DhcpApiServerNameParams
                                                };

   DHCPCAPI_PARAMS_ARRAY DhcpApiParamsArray = {NUMBER_OF_OPTIONS,  // only one option to request
                                          paramArray
                                          };
   DHCPCAPI_PARAMS_ARRAY SendParams = {0, NULL};

   dwSize = sizeof(TmpBuffer);
   dwError = DhcpRequestParams(DHCPCAPI_REQUEST_SYNCHRONOUS, // Flags
                           NULL,                         // Reserved
                           pszAdapterName,               // Adapter Name
                           NULL,                         // not using class id
                           SendParams,                   // nothing to send
                           DhcpApiParamsArray,           // requesting params
                           (PBYTE) TmpBuffer,            // buffer
                           &dwSize,                      // buffer size
                           NULL                          // Request ID
                           );

   cout << "Your Error Code from DhcpRequestParams is " << dwError << endl;
   if( ERROR_MORE_DATA == dwError ) 
   {
      //
      // dwSize is not large enough.
      //
   }

   int success = FALSE;
   if( NO_ERROR == dwError ) 
   {
      for(int i=0; i<NUMBER_OF_OPTIONS; i++)
      {
         if(paramArray[i].nBytesData != 0)
         {
            success = true;
            switch(paramArray[i].OptionId)
            {
               case OPTION_SUBNET_MASK:
                  PrintMask(paramArray[i]);
                  break;
               case OPTION_DOMAIN_NAME_SERVERS:
                  PrintDNS(paramArray[i]);
                  break;
               case OPTION_HOST_NAME:
                  PrintHostName(paramArray[i]);
                  break;
               case OPTION_VENDOR_SPEC_INFO:
                  PrintVendor(paramArray[i]);
                  break;
               case OPTION_LEASE_TIME:
                  PrintLeaseTime(paramArray[i]);
                  break;
               case OPTION_MESSAGE_TYPE:
                  PrintMessageType(paramArray[i]);
                  break;
               case OPTION_SERVER_IDENTIFIER:
                  PrintServerIP(paramArray[i]);
                  break;
            }
         }
      }
      cout << endl;
   }

   if(success == TRUE)
      return TRUE;
   else
      return FALSE;
}

void PrintAsAscii(DHCPCAPI_PARAMS param)
{
   unsigned char temp[260];
   CopyMemory(temp, 
   param.Data,
   param.nBytesData);

   temp[param.nBytesData] = '\0';
   cout << temp;
}

void PrintAsIP(DHCPCAPI_PARAMS param)
{
   unsigned char temp[260];
   CopyMemory(temp, 
   param.Data,
   param.nBytesData);

   temp[param.nBytesData] = '\0';
   for(unsigned int i=0; i<param.nBytesData; i++)
   { 
      if(i%4 == 0)
      {
         cout << endl;
      }
         cout << (int)temp[i]<< ".";
   }
}

void PrintAsInt(DHCPCAPI_PARAMS param)
{
   unsigned char temp[260];
   CopyMemory(temp, 
   param.Data,
   param.nBytesData);

   temp[param.nBytesData] = '\0';
   cout << (unsigned int)*temp;
}

void PrintMask(DHCPCAPI_PARAMS param)
{
   /* Print the subnet mask
   * This is stored as Option 1
   *
   *
   */
   cout << endl << "MASK" << endl;
   cout << "--------------------------------------------";
   PrintAsIP(param);
}

void PrintDNS(DHCPCAPI_PARAMS param)
{
   /* Print the DNS Servers
   * This is stored as Option 6
   *
   *
   */
   cout << endl << "\nDNS SERVERS" << endl;
   cout << "--------------------------------------------";
   PrintAsIP(param);
}

void PrintHostName(DHCPCAPI_PARAMS param)
{
   /* Print the Host name or IP address if 
   * that's what's stored in this option
   * This is stored as Option 12
   *
   */
   cout << endl << "\nHOST NAME" << endl;
   cout << "--------------------------------------------";
   cout << endl << "ANSI String" << endl;
   PrintAsAscii(param);
   cout << endl << "IP FORMAT";
   PrintAsIP(param);
}

void PrintVendor(DHCPCAPI_PARAMS param)
{
   /* Print the Vendor parameter
   * This is stored as Option 43
   *
   *
   */
   cout << endl << "\nVENDOR PARAMETER" << endl;
   cout << "--------------------------------------------";
   cout << endl << "ANSI String" << endl;
   PrintAsAscii(param);
}

void PrintLeaseTime(DHCPCAPI_PARAMS param)
{
   /* Print the Lease Time
   * This is stored as Option 51
   *
   *
   */
   cout << endl << "\nLEASE TIME" << endl;
   cout << "--------------------------------------------" << endl;
   PrintAsInt(param);
   cout << endl;
}

void PrintMessageType(DHCPCAPI_PARAMS param)
{
   /* Print the message type
   * This is stored as Option 53
   *
   *
   */
   cout << endl << "\nMESSAGE TYPE" << endl;
   cout << "--------------------------------------------" << endl;;
   PrintAsInt(param);
}

void PrintServerIP(DHCPCAPI_PARAMS param)
{
   /* Print the DHCP servers IP address
   * This is stored as Option 54
   *
   *
   */
   cout << endl << "\nDHCP SERVER" << endl;
   cout << "--------------------------------------------";
   PrintAsIP(param);
} 






int main(){

    struct DHCPAPI_PARAMS {
    ULONG  Flags;
    ULONG  OptionId;
    BOOL   IsVendor;
    LPBYTE Data;
    DWORD  nBytesData;
    };
    DHCPCAPI_PARAMS DhcpApiMaskParams = {0,
                                         OPTION_SUBNET_MASK,
                                         FALSE,
                                         NULL,
                                         0
                                         };



    char name[26];
    cout<<"Hello World"<< endl;
    cin>>name;  
    PrintAsIP(DhcpApiMaskParams);

    return 0;

}
#包括“StdAfx.h”
#包括“WINDOWS.H”
#包括“Dhcpcsdk.h”
//#包括“Dhcpcsvc.dll”
#包括
使用名称空间std;
#定义选项7的数量
//#定义选项4的数量
枚举选项数组位置
{
面具,
DNS,
主机名,
小贩,
租赁时间,
消息类型,
服务器IP
};
布尔检索HCPINFO(LPWSTR pszAdapterName);
无效打印ASASCI(DHCPCAPI_参数);
无效打印ASIP(DHCPCAPI_参数);
无效打印输入(DHCPCAPI_参数);
无效打印掩码(DHCPCAPI_参数);
void PrintDNS(DHCPCAPI_PARAMS param);
无效打印主机名(DHCPCAPI_PARAMS param);
作废打印供应商(DHCPCAPI_参数);
无效打印时间(DHCPCAPI_参数);
void PrintMessageType(DHCPCAPI_PARAMS param);
无效打印服务器IP(DHCPCAPI_参数);
布尔检索HCPINFO(LPWSTR pszAdapterName)
{
DWORD dwError,dwSize;
CHAR TmpBuffer[1000];//主机名不会大于此值
DHCPCAPI_参数DhcpApiMaskParams={0,
选项\u子网\u掩码,
假,,
无效的
0
};
DHCPCAPI_参数DhcpApiDNSParams={0,
选项\u域名\u服务器,
假,,
无效的
0
};
DHCPCAPI_参数DhcpApiHostNameParams={0,//标志
选项\u主机\u名称,//OptionId
FALSE,//特定于供应商?
NULL,//返回时填写的数据
0//n字节
}; 
DHCPCAPI_参数DhcpApiVendorParams={0,
选项\供应商\规格\信息,
假,,
无效的
0
};
DHCPCAPI_参数DhcpApiLeaseTimeParams={0,
选择租用时间,
假,,
无效的
0
};    
DHCPCAPI_参数DhcpApiMsgTypeParams={0,
选项\消息\类型,
假,,
无效的
0
};
DHCPCAPI_参数DhcpApiServerNameParams={0,
选项\u服务器\u标识符,
假,,
无效的
0
};
DHCPCAPI_参数paramArray[选项数]={DhcpApiMaskParams,
DHCPapindsparams,
dhcpapiphostnameparams,
DHCPapipvendorparams,
DHCPapilesTimeParams,
DhcpApiMsgTypeParams,
DhcpApiServerNameParams
};
DHCPCAPI_PARAMS_数组DhcpApiParamsArray={NUMBER_OF_OPTIONS,//只请求一个选项
参数数组
};
DHCPCAPI_PARAMS_数组SendParams={0,NULL};
dwSize=sizeof(TmpBuffer);
dwError=DhcpRequestParams(DHCPCAPI\u请求\u同步,//标志
NULL,//保留
pszAdapterName,//适配器名称
NULL,//未使用类id
SendParams,//没有要发送的内容
DhcpApiParamsArray,//请求参数
(PBYTE)TmpBuffer,//缓冲区
&dwSize,//缓冲区大小
空//请求ID
);

cout您需要链接列表底部列出的导入库


Dhcpcsvc.lib
添加到您的
附加库中

您应该链接到任何库吗?文档说您需要链接到
Dhcpcsvc.lib
。您正在这样做吗?尝试放置
#pragma注释(lib,“dhcpsvc.lib”)
在您的代码中。这将指示链接器针对特定的LIB文件进行链接,该文件是文档中说明您应该链接的库。您知道我添加了什么吗?#pragma comment(LIB,“dhcpcsvc.LIB”)“就像我昨天写的其他代码中一样,我已经把它添加到了项目中,因此不再需要那个项目,也不再需要这个项目。很好。