Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / July 2007

Tip: Looking for answers? Try searching our database.

Visual C++ question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
yellowblueyellow@gmail.com - 16 Jul 2007 16:01 GMT
Hi All,

I am creating a class library project for VC++ in VS 2005. On
compilation, the following error is returned

error C2664: 'LookupAccountNameW' : cannot convert parameter 1 from
'char *' to 'LPCWSTR'
the line of concern is :

if ( ! LookupAccountName( argv[1], argv[2], userSid, &sidSize, refDom,
&domSize, &sidUse ) )
        err( "LAN()", gle, false );

I think the problem lies in the fact that the .h file has a main
function which is as follows

int main( int argc, char *argv[] )
{
    if ( argc != 3 )
    {
        puts( "Usage: lsa_lear <system name> <account name>" );
        puts( "Enumerates privileges for the named account on the named
machine." );
        puts( "<system name> is the machine where the lookup will
execute." );
        puts( "<account name> is the account to examine, e.g. \"FOO\\felixk
\" or \"Administrators\"." );
        return 1;
    }

    // open the policy object on the target computer

    static SECURITY_QUALITY_OF_SERVICE sqos = { sizeof
SECURITY_QUALITY_OF_SERVICE, SecurityImpersonation,
SECURITY_DYNAMIC_TRACKING, FALSE };
    static LSA_OBJECT_ATTRIBUTES lsaOA = { sizeof LSA_OBJECT_ATTRIBUTES,
NULL, NULL, 0, NULL, &sqos };
    NTSTATUS nts;
    LSA_HANDLE polHandle;
    LsaUnicodeString systemName;

    systemName = argv[1];

    nts = LsaOpenPolicy( systemName, &lsaOA, GENERIC_READ |
GENERIC_EXECUTE, &polHandle );
    err( "LOP()", nts );

    // translate the account name to a RID plus associated domain SID

    SID *userSid;
    char refDom[MAX_PATH];
    SID_NAME_USE sidUse;
    DWORD sidSize, domSize;
    const char *acctTypeString;

    userSid = (SID *) malloc( MAX_PATH );
    sidSize = domSize = MAX_PATH;

    if ( ! LookupAccountName( argv[1], argv[2], userSid, &sidSize,
refDom, &domSize, &sidUse ) )
        err( "LAN()", gle, false );

    acctTypeString = NULL;
    switch ( sidUse )
    {
        case SidTypeAlias:
        case SidTypeUser:
        case SidTypeGroup:
        case SidTypeWellKnownGroup:
            break;
        case SidTypeDomain:
            if ( acctTypeString == NULL )
                acctTypeString = " domain";
            // fall-through
        case SidTypeInvalid:
            if ( acctTypeString == NULL )
                acctTypeString = "n invalid";
            // fall-through
        case SidTypeUnknown:
            if ( acctTypeString == NULL )
                acctTypeString = "n unknown";
            // fall-through
        case SidTypeDeletedAccount:
            if ( acctTypeString == NULL )
                acctTypeString = " deleted";
            printf( "Don't know how to handle a%s account.\n",
acctTypeString );
            return 1;
    }

    LsaUnicodeString *userRights;
    ULONG count;

    userRights = NULL;
    count = 0;
    nts = LsaEnumerateAccountRights( polHandle, userSid,
(LSA_UNICODE_STRING **) &userRights, &count );
    err( "LEAR()", nts );

    DWORD i;
    char *p;

    printf( "%d privileges for user \"%s\" in domain \"%s\":\n", count,
argv[2], refDom );
    for ( i = 0; i < count; ++ i )
    {
        p = (char *) userRights[i]; // must free() later
        printf( "priv %u: %s\n", i, p );
        free( p );
    }

    LsaClose( polHandle );
    free( userSid );

    return 0;
}

Could someone assist me in getting rid of this problem.

Thanks
Sheng Jiang[MVP] - 16 Jul 2007 18:08 GMT
Ask it in the microsoft.public.vc.language group. This question has nothing
to do with .net framework.

Signature

Sheng Jiang
Microsoft MVP in VC++

> Hi All,
>
[quoted text clipped - 116 lines]
>
> Thanks
yellowblueyellow@gmail.com - 16 Jul 2007 19:54 GMT
..never mind .... figured itout :D

actually it does have to do with the framework.

On Jul 16, 1:08 pm, "Sheng Jiang[MVP]"
<sheng_ji...@hotmail.com.discuss> wrote:
> Ask it in the microsoft.public.vc.language group. This question has nothing
> to do with .net framework.
[quoted text clipped - 127 lines]
>
> - Show quoted text -
Larry Smith - 17 Jul 2007 00:55 GMT
> ..never mind .... figured itout :D
>
> actually it does have to do with the framework.

Based on what you posted it has nothing to do with .NET whatsoever. You
likely had the UNICODE and/or _UNICODE constants #defined.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.