Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Support Forum
Download Visual Studio Add-In

Terms of Use
Privacy Policy
credpackauthenticationbuffer (credui)
 
.
Summary
The CredPackAuthenticationBuffer function converts a string user name and password into an authentication buffer.

C# Signature:

    [DllImport("credui.dll", CharSet = CharSet.Unicode, SetLastError = true)]
    private static extern Boolean CredPackAuthenticationBuffer(
      int dwFlags,
      string pszUserName,
      string pszPassword,
      IntPtr pPackedCredentials,
      ref int pcbPackedCredentials);

VB Signature:

    ''' <summary>
    ''' Windows Platform function (called via pInvoke) which populates an authentication buffer with authentication details.
    ''' See http://msdn.microsoft.com/en-us/library/aa374802(v=vs.85).aspx
    ''' </summary>
    ''' <param name="dwFlags">RESERVED - must be zero.</param>
    ''' <param name="pszUserName">User Name.</param>
    ''' <param name="pszPassword">Password.</param>
    ''' <param name="pPackedCredentials">The buffer to be packed with credentials.</param>
    ''' <param name="pcbPackedCredentials">The the size of the buffer.</param>
    ''' <returns><c>True</c> on success; otherwise <c>False</c>. For extended error information, call the GetLastError() function.</returns>
    <DllImport("credui.dll", CharSet:=CharSet.Unicode, SetLastError:=True)> <CLSCompliant(False)> _
    Public Shared Function CredPackAuthenticationBuffer(ByVal dwFlags As UInt32, ByVal pszUserName As String, ByVal pszPassword As String, ByVal pPackedCredentials As IntPtr, ByRef pcbPackedCredentials As UInt32) As <MarshalAs(UnmanagedType.Bool)> Boolean
    End Function

User-Defined Types:

None.

Alternative Managed API:

Do you know one? Please contribute it!

Notes:

None.

Tips & Tricks:

To determine required buffer size, call first with pPackedCredentials = IntPtr.Zero. Should return error code 160, but pcbPackedCredentials will be populated with the expected buffer size. Use Marshal.AllocCoTaskMem() to allocate the appropriate buffer, then call again, this time passing the allocated buffer.

Sample Code:

C# Sample:

    string username = "User";
    string password = "";
    int inCredSize = 1024;
    IntPtr inCredBuffer = Marshal.AllocCoTaskMem(inCredSize);

    CredPackAuthenticationBuffer(0, username, password, inCredBuffer, ref inCredSize);

Documentation

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions