Link to home
Start Free TrialLog in
Avatar of Pber
PberFlag for Canada

asked on

netshareenum problem

Why is it that the code below (slightly modified from MSDN http://msdn.microsoft.com/library/default.asp?url=/library/en-us/netmgmt/netmgmt/netshareenum.asp) gives the following error:

error C2664: 'NetShareEnum' : cannot convert parameter 1 from 'unsigned short *' to 'char *'

how do I pass a server name to netsharenum?

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

void wmain( int argc, TCHAR *lpszArgv[])
{
   PSHARE_INFO_1 BufPtr,p;
   NET_API_STATUS res;
   LPTSTR   lpszServer = NULL;

   DWORD er=0,tr=0,resume=0, i;

   //
   do // begin do
   {
      res = NetShareEnum (lpszServer, 1, (LPBYTE *) &BufPtr, MAX_PREFERRED_LENGTH, &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("%s\n",p->shi1_netname);

         }
         //
         // 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;
}
ASKER CERTIFIED SOLUTION
Avatar of andrewjb
andrewjb
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Pber

ASKER

Thanks... it was the #define UNICODE not being at the top. !@#$!@
Cool. That was a lucky guess, then!
Avatar of Pber

ASKER

Is #define UNICODE the same as placing _UNICODE, UNICODE in the the preprocessor definitions?

the reason I ask is not that I add the working code to my master project, it fails with the same error and I have UNICODE defined in the preprocessor definitions.
What compier / build environment.

I think that answer ought to be 'yes', but it'll depend what you're using. I'm not a VC++ user if that's where you are :-(


.. you might also have to link to differnet versions of libraries? Isn't there a 'Make a unicode project' wizard somewhere that should set everything up for you.