?
Solved

netshareenum problem

Posted on 2005-04-08
5
Medium Priority
?
310 Views
Last Modified: 2010-07-27
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;
}
0
Comment
Question by:Pber
  • 3
  • 2
5 Comments
 
LVL 12

Accepted Solution

by:
andrewjb earned 2000 total points
ID: 13738172
Quick guess.

SInce you've UNICODE defined, does it want a unicode name rather than an ascii one?

? Make sure the whole project is unicode

? Shove the #define UNICODE above the stdafx (though I don't know if that'll help..)

0
 
LVL 26

Author Comment

by:Pber
ID: 13738217
Thanks... it was the #define UNICODE not being at the top. !@#$!@
0
 
LVL 12

Expert Comment

by:andrewjb
ID: 13738269
Cool. That was a lucky guess, then!
0
 
LVL 26

Author Comment

by:Pber
ID: 13738417
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.
0
 
LVL 12

Expert Comment

by:andrewjb
ID: 13738501
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.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
The viewer will learn how to implement Singleton Design Pattern in Java.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
Suggested Courses
Course of the Month16 days, 15 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question