5 Replies - 7437 Views - Last Post: 24 March 2009 - 04:40 AM Rate Topic: -----

#1 ashish2patil  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 23-March 09

error LNK2019: unresolved external symbol in VS2008

Post icon  Posted 23 March 2009 - 10:49 PM

Hello All,
I am trying to retrieve information about each shared resource on a server using a call to the NetShareEnum function from msdn . I copy that code from MSDN and paste in VS2008 .cpp (file (empty project )).
I got the error like following

main.obj : error LNK2019: unresolved external symbol _NetApiBufferFree@4 referenced in function _wmain

main.obj : error LNK2019: unresolved external symbol _NetShareEnum@28 referenced in function _wmain



My Code Is:-

#define UNICODE
#include <windows.h>
#include <stdio.h>
#include <lm.h>

void wmain( int argc, TCHAR *lpszArgv[ ])
{
   PSHARE_INFO_502 BufPtr,p;
   NET_API_STATUS res;
   LPTSTR   lpszServer = NULL;
   DWORD er=0,tr=0,resume=0, i;

   switch(argc)
   {
   case 2:
	  lpszServer = lpszArgv[1];
	  break;
   default:
	  printf("Usage: NetShareEnum <servername>\n");
	  return;
   }
   //
   // Print a report header.
   //
   printf("Share:			  Local Path:				   Uses:   Descriptor:\n");
   printf("---------------------------------------------------------------------\n");
   //
   // Call the NetShareEnum function; specify level 502.
   //
   do // begin do
   {
	  res = NetShareEnum (lpszServer, 502, (LPBYTE *) &BufPtr, -1, &er, &tr, &resume);
	  //
	  // If the call succeeds,
	  //
	  if(res == ERROR_SUCCESS || res == ERROR_MORE_DATA)
	  {
		 p=BufPtr;
		 //
		 // Loop through the entries;
		 //  print retrieved data.
		 //
		 for(i=1;i<=er;i++)
		 {
			printf("%-20S%-30S%-8u",p->shi502_netname, p->shi502_path, p->shi502_current_uses);
			//
			// Validate the value of the 
			//  shi502_security_descriptor member.
			//
			if (IsValidSecurityDescriptor(p->shi502_security_descriptor))
			   printf("Yes\n");
			else
			   printf("No\n");
			p++;
		 }
		 //
		 // Free the allocated buffer.
		 //
		 NetApiBufferFree(BufPtr);
	  }
	  else 
		 printf("Error: %ld\n",res);
   }
   // Continue to call NetShareEnum while 
   //  there are more entries. 
   // 
   while (res==ERROR_MORE_DATA); // end do
   return;
}



** Edit ** :code:

Is This A Good Question/Topic? 0
  • +

Replies To: error LNK2019: unresolved external symbol in VS2008

#2 webmin  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 256
  • Joined: 21-May 08

Re: error LNK2019: unresolved external symbol in VS2008

Posted 23 March 2009 - 11:00 PM

#define UNICODE
#include <windows.h>
#include <stdio.h>
#include <lm.h>

void wmain( int argc, TCHAR *lpszArgv[ ])
{
PSHARE_INFO_502 BufPtr,p;
NET_API_STATUS res;
LPTSTR lpszServer = NULL;
DWORD er=0,tr=0,resume=0, i;

switch(argc)
{
case 2:
lpszServer = lpszArgv[1];
break;
default:
printf("Usage: NetShareEnum <servername>\n");
return;
}
//
// Print a report header.
//
printf("Share: Local Path: Uses: Descriptor:\n");
printf("---------------------------------------------------------------------\n");
//
// Call the NetShareEnum function; specify level 502.
//
do // begin do
{
res = NetShareEnum (lpszServer, 502, (LPBYTE *) &BufPtr, -1, &er, &tr, &resume);
//
// If the call succeeds,
//
if(res == ERROR_SUCCESS || res == ERROR_MORE_DATA)
{
p=BufPtr;
//
// Loop through the entries;
// print retrieved data.
//
for(i=1;i<=er;i++)
{
printf("%-20S%-30S%-8u",p->shi502_netname, p->shi502_path, p->shi502_current_uses);
//
// Validate the value of the 
// shi502_security_descriptor member.
//
if (IsValidSecurityDescriptor(p->shi502_security_descriptor))
printf("Yes\n");
else
printf("No\n");
p++;
}
//
// Free the allocated buffer.
//
NetApiBufferFree(BufPtr);
}
else 
printf("Error: %ld\n",res);
}
// Continue to call NetShareEnum while 
// there are more entries. 
// 
while (res==ERROR_MORE_DATA); // end do
return;
}



Ahhh, please use put your code between {code}{/code}, only use normal braces. Makes it easier on the eyes, and easier to spot your problem.
Putting this in the tags for you so I can look at it easier. Then I'll post again hopefully with an answer.

This post has been edited by webmin: 23 March 2009 - 11:07 PM

Was This Post Helpful? 0
  • +
  • -

#3 VenumX  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 21-February 09

Re: error LNK2019: unresolved external symbol in VS2008

Posted 23 March 2009 - 11:19 PM

make sure that you have included the proper lib's for the net api?
Was This Post Helpful? 0
  • +
  • -

#4 webmin  Icon User is offline

  • D.I.C Regular

Reputation: 4
  • View blog
  • Posts: 256
  • Joined: 21-May 08

Re: error LNK2019: unresolved external symbol in VS2008

Posted 23 March 2009 - 11:22 PM

If this is just copied and pasted, then of course it's not going to work. If you look here at this line of code:

res = NetShareEnum (lpszServer, 502, (LPBYTE *) &BufPtr, -1, &er, &tr, &resume);



This is trying to get information from a source that it can't connect to. Basically, your trying to connect to a pointer, not an actual server. It looks like you need a server name to set lpszServer = to instead of an element of an array. Hope this helps
Was This Post Helpful? 0
  • +
  • -

#5 ashish2patil  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 23-March 09

Re: error LNK2019: unresolved external symbol in VS2008

Posted 24 March 2009 - 02:16 AM

View Postwebmin, on 23 Mar, 2009 - 10:22 PM, said:

If this is just copied and pasted, then of course it's not going to work. If you look here at this line of code:

res = NetShareEnum (lpszServer, 502, (LPBYTE *) &BufPtr, -1, &er, &tr, &resume);



This is trying to get information from a source that it can't connect to. Basically, your trying to connect to a pointer, not an actual server. It looks like you need a server name to set lpszServer = to instead of an element of an array. Hope this helps



You are right but ur error will come at run time,my error come at compile time
Was This Post Helpful? 0
  • +
  • -

#6 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6091
  • View blog
  • Posts: 23,605
  • Joined: 23-August 08

Re: error LNK2019: unresolved external symbol in VS2008

Posted 24 March 2009 - 04:40 AM

webmin is correct.

Go to the MSDN page for NetShareEnum, scroll down to the bottom where it says requirements. There you'll see:
Library	Netapi32.lib

This means that the NetShareEnum call is defined in the netapi32.lib library. Therefore, you must add netapi32.lib to the project's linker options so that the linker can find it. Go to Project->Properties->Configuration Properties->Linker->Input->Additional Dependencies and add netapi32.lib.
Was This Post Helpful? 1

Page 1 of 1