Pber
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_netn ame);
}
//
// 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;
}
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_netn
}
//
// 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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Cool. That was a lucky guess, then!
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.
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.
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.
ASKER