DHCP C++ error LNK2019 -
given follow code cannot seem figure out why receiving error if help.
code:
#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 larger 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, // 1 option 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 send dhcpapiparamsarray, // requesting params (pbyte) tmpbuffer, // buffer &dwsize, // buffer size null // request id ); cout << "your error code dhcprequestparams " << dwerror << endl; if( error_more_data == dwerror ) { // // dwsize 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 subnet mask * stored option 1 * * */ cout << endl << "mask" << endl; cout << "--------------------------------------------"; printasip(param); } void printdns(dhcpcapi_params param) { /* print dns servers * stored option 6 * * */ cout << endl << "\ndns servers" << endl; cout << "--------------------------------------------"; printasip(param); } void printhostname(dhcpcapi_params param) { /* print host name or ip address if * that's what's stored in option * stored 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 vendor parameter * stored option 43 * * */ cout << endl << "\nvendor parameter" << endl; cout << "--------------------------------------------"; cout << endl << "ansi string" << endl; printasascii(param); } void printleasetime(dhcpcapi_params param) { /* print lease time * stored option 51 * * */ cout << endl << "\nlease time" << endl; cout << "--------------------------------------------" << endl; printasint(param); cout << endl; } void printmessagetype(dhcpcapi_params param) { /* print message type * stored option 53 * * */ cout << endl << "\nmessage type" << endl; cout << "--------------------------------------------" << endl;; printasint(param); } void printserverip(dhcpcapi_params param) { /* print dhcp servers ip address * stored 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; }
this error code receive when running this, hello world , enter cin name there starter purposes.
here errors receive.
errors:
error 1 error lnk2019: unresolved external symbol _dhcprequestparams@44 referenced in function "int __cdecl retrievedhcpinfo(wchar_t *)" (?retrievedhcpinfo@@yahpa_w@z)
error 2 error lnk1120: 1 unresolved externals
you need link import library listed @ bottom of manual page.
add dhcpcsvc.lib
additional libraries
.
Comments
Post a Comment