将C ++转换为Visual Basic帮助

问题描述:

我需要将一些C ++代码转换为Visual Basic代码,但无法完成任务.
谁能帮忙.

这是C ++代码:

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;

}



我还需要知道如何为以下项定义API调用:
LsaNtStatusToWinError
LsaOpenPolicy
LsaStorePrivateData
ZeroMemory
LsaNtStatusToWinError

因此,基本上,我需要此功能才能与Visual Basic 2010一起使用.

问候
Rodney



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

请参阅msdn链接
http://social.msdn.microsoft.com/Forums/zh/Vsexpressvb/thread/131e6659-c995-4104-a81f-22dc0b1b490c [ http://msdn.microsoft.com/en-us/library/system. runtime.interopservices.dllimportattribute.aspx [ ^ ]

http://msdn.microsoft.com/en-us/library/4zey12w5.aspx [ ^ ]
Plz refer msdn links
http://social.msdn.microsoft.com/Forums/en/Vsexpressvb/thread/131e6659-c995-4104-a81f-22dc0b1b490c[^]

http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.dllimportattribute.aspx[^]

http://msdn.microsoft.com/en-us/library/4zey12w5.aspx[^]


在整个地方搜索,发现了一些我想要的代码.

此处

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

here

Thanks