Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ VB.NET convert API
Hi, I need to convert some C++ code into Visual Basic code but have not been able to complete the task.
Can anyone help.
 
Here is the C++ code:
#include <windows.h>
#include <stdio.h>
 
DWORD UpdateDefaultPassword(WCHAR * pwszSecret)
{
 
    LSA_OBJECT_ATTRIBUTES ObjectAttributes;
    LSA_HANDLE LsaPolicyHandle = NULL;
 
    LSA_UNICODE_STRING lusSecretName;
    LSA_UNICODE_STRING lusSecretData;
    USHORT SecretNameLength;
    USHORT SecretDataLength;
 
    NTSTATUS ntsResult = STATUS_SUCCESS;
    DWORD dwRetCode = ERROR_SUCCESS;
 
    //  Object attributes are reserved, so initialize to zeros.
    ZeroMemory(&ObjectAttributes, sizeof(ObjectAttributes));
 
    //  Get a handle to the Policy object.
    ntsResult = LsaOpenPolicy(
        NULL,    // local machine
        &ObjectAttributes, 
        POLICY_CREATE_SECRET,
        &LsaPolicyHandle);
 
    if( STATUS_SUCCESS != ntsResult )
    {
        //  An error occurred. Display it as a win32 error code.
        dwRetCode = LsaNtStatusToWinError(ntsResult);
        wprintf(L"Failed call to LsaOpenPolicy %lu\n", dwRetCode);
        return dwRetCode;
    } 
 
    //  Initialize an LSA_UNICODE_STRING for the name of the
    //  private data ("DefaultPassword").
    SecretNameLength = (USHORT)wcslen(L"DefaultPassword");
    lusSecretName.Buffer = L"DefaultPassword";
    lusSecretName.Length = SecretNameLength * sizeof(WCHAR);
    lusSecretName.MaximumLength =
        (SecretNameLength+1) * sizeof(WCHAR);
 
    //  If the pwszSecret parameter is NULL, then clear the secret.
    if( NULL == pwszSecret )
    {
        wprintf(L"Clearing the secret...\n");
        ntsResult = LsaStorePrivateData(
            LsaPolicyHandle,
            &lusSecretName,
            NULL);
        dwRetCode = LsaNtStatusToWinError(ntsResult);
    }
    else
    {
        wprintf(L"Setting the secret...\n");
        //  Initialize an LSA_UNICODE_STRING for the value
        //  of the private data. 
        SecretDataLength = (USHORT)wcslen(pwszSecret);
        lusSecretData.Buffer = pwszSecret;
        lusSecretData.Length = SecretDataLength * sizeof(WCHAR);
        lusSecretData.MaximumLength =
            (SecretDataLength+1) * sizeof(WCHAR);
        ntsResult = LsaStorePrivateData(
            LsaPolicyHandle,
            &lusSecretName,
            &lusSecretData);
        dwRetCode = LsaNtStatusToWinError(ntsResult);
    }
 
    LsaClose(LsaPolicyHandle);
 
    if (dwRetCode != ERROR_SUCCESS)
        wprintf(L"Failed call to LsaStorePrivateData %lu\n",
            dwRetCode);
    
    return dwRetCode;
 
}
 
Also I need to know how to define the API call for:
LsaNtStatusToWinError
LsaOpenPolicy
LsaStorePrivateData
ZeroMemory
LsaNtStatusToWinError
 
So basically I need this function to work with Visual Basic 2010.
 
Regards
Rodney
Posted 18-Sep-12 13:29pm
Comments
Wes Aday at 18-Sep-12 20:12pm
   
Okay.... so what is it that you need help with? www.pinvoke.net should show you how to pinvoke those functions.
Sergey Alexandrovich Kryukov at 18-Sep-12 20:53pm
   
Your "not been able to complete the task" is not really informative. As the question is not asked and no problem is indicated, I doubt someone will try to dig into it. People have better ways of spending their time.
--SA
jkirkerx at 18-Sep-12 22:08pm
   
If it was simpler, not accessing the policy object, I would start you off, but help is voluntary, and I don't want to do research on the object requirements in vb. That could take me hours.
Sergey Alexandrovich Kryukov at 18-Sep-12 22:38pm
   
Agree. Moreover, if it was ten minutes, it would not be well spent minutes. :-)
--SA
jkirkerx at 19-Sep-12 0:11am
   
I have enough to do right now, and even if I did translate it, I would get like 20 more questions, like how do I use it now. It would probably condense down pretty small, since I don't have to measure any lengths.
 
Guess it serves 2 uses, one to set the password, and two to clear the password.
 
So what's up with that crater in Siberia, that's loaded with hardened diamonds, they say a trillion carats are in there. The molecule size of the diamonds are larger than normal, and 10 times harder, because of the heat and pressure from the meteor on top of the existing diamonds below.
 
Back tomorrow, 9PM here now.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Searching all over the place and found a bit of code just as I wanted it.
 
here
 
Thanks
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 398
1 Sergey Alexandrovich Kryukov 320
2 Uma Shankar Patel 80
3 CB Sharma 79
4 PhilLenoir 70
0 Sergey Alexandrovich Kryukov 6,532
1 OriginalGriff 5,976
2 CPallini 2,473
3 Richard MacCutchan 1,687
4 Abhinav S 1,550


Advertise | Privacy | Mobile
Web01 | 2.8.140821.2 | Last Updated 3 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100