// JP opened flex table

Click to See Complete Forum and Search --> : netshareenum()


maya123
February 14th, 2007, 05:00 PM
The following code compiled find and when I run it, I am getting error 1113
which means the following
No mapping for the Unicode character exists in the target multi-byte code.

I dont know what is wrong with the parameters being passed to the
NetShareEnum () function.

I am using VS.net 2003 to compile.
---------------------------

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

#include <Lm.h>
#include <LMShare.h>
#include <aclapi.h>






int main( )
{
PSHARE_INFO_502 BufPtr,p;
NET_API_STATUS res;
LPWSTR lpszServer = NULL;
DWORD er=0,tr=0,resume=0, i;
char *name = "core";

//
// 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 ((LPSTR)name, 502, (LPBYTE *) &BufPtr, -1, (LPDWORD)&er, (LPDWORD)&tr, (LPDWORD)&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 0;
}

alex_gusev
February 14th, 2007, 07:08 PM
NetShareEnum (http://msdn2.microsoft.com/en-us/library/aa380481.aspx) takes UNICODE string as the 1st parameter, so if you pass ASCII, it is wrong

maya123
February 15th, 2007, 09:45 AM
Yes, I fixed the problem using the following code,

char name[] = "moscow";
wchar_t SomeUnicodeStr[1024];
MultiByteToWideChar(CP_ACP, 0, name, -1, SomeUnicodeStr, 1024);
When I run, I get 1326, logon failure, should I pass any other value in the first paramter?


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

alex_gusev
February 15th, 2007, 11:06 AM
well, actually I've confused you with that UNICODE parameter, it depends on SDK version you use. simply have a look in appropriate header file to be sure. and you should cast the 1st parameter to LPTSTR to be consistent with your SDK.

I guess you run the code under correct permissions (e.g. levels 2 and 502 require Administrator, Power User, Print Operator, or Server Operator group membership)

//JP added flex table