AcquireCredentialsHandle interop

B

Bill

I am trying to call AcquireCredentialsHandle using Interop by I get a
notsupportexception. The MSDN docs say it is supported. Has anyone got
this working? I tried it with both the ce and pocketpc emulators and both
give the same error. I also tried linking to both secur32.dll and
security.dll and neither worked.

Here is the call:

status = AcquireCredentialsHandle(
0,
"NTLM",
SECPKG_CRED_OUTBOUND,
0, ref pAuthData,
0, 0,
m_Credentials,
ref Expiration);

//Def

[StructLayout(LayoutKind.Sequential)]
internal struct SEC_WINNT_AUTH_IDENTITY
{
public string User;
public int UserLength;
public string Domain;
public int DomainLength;
public string Password;
public int PasswordLength;
public int Flags;
}

[DllImport(@"secur32.dll", EntryPoint="InitializeSecurityContext")]

internal static extern int InitializeSecurityContext(IntPtr phCredential,
IntPtr phContext, string pszTargetName, int fContextReq, int Reserved1, int
TargetDataRep, IntPtr pInput, int Reserved2, IntPtr phNewContext, ref
SecBufferDesc pOutput, ref int pfContextAttr, IntPtr ptsExpiry);
 
P

Paul G. Tobey [eMVP]

If you look at the exports from the security DLL, you're *not* going to see
that function name, as it takes a string parameter. Most API functions
which take string parameters are actually named with either a "W" or an "A"
at the end of the function name, indicating whether the string parameter(s)
are wide-character (Unicode), or not (ANSI). In this case, there's a W
version of the call exported by secur32.dll, AcquireCredentialsHandleW().
Try that, instead...

Paul T.
 
C

Chris Tacke, eMVP

You also cannot directly marshal a struct with an interned string, so that's
a huge failure point in this case too.

--
Chris Tacke
Co-founder
OpenNETCF.org
Has OpenNETCF helped you? Consider donating to support us!
http://www.opennetcf.org/donate


Paul G. Tobey said:
If you look at the exports from the security DLL, you're *not* going to
see that function name, as it takes a string parameter. Most API
functions which take string parameters are actually named with either a
"W" or an "A" at the end of the function name, indicating whether the
string parameter(s) are wide-character (Unicode), or not (ANSI). In this
case, there's a W version of the call exported by secur32.dll,
AcquireCredentialsHandleW(). Try that, instead...

Paul T.

Bill said:
I am trying to call AcquireCredentialsHandle using Interop by I get a
notsupportexception. The MSDN docs say it is supported. Has anyone got
this working? I tried it with both the ce and pocketpc emulators and both
give the same error. I also tried linking to both secur32.dll and
security.dll and neither worked.

Here is the call:

status = AcquireCredentialsHandle(
0,
"NTLM",
SECPKG_CRED_OUTBOUND,
0, ref pAuthData,
0, 0,
m_Credentials,
ref Expiration);

//Def

[StructLayout(LayoutKind.Sequential)]
internal struct SEC_WINNT_AUTH_IDENTITY
{
public string User;
public int UserLength;
public string Domain;
public int DomainLength;
public string Password;
public int PasswordLength;
public int Flags;
}

[DllImport(@"secur32.dll", EntryPoint="InitializeSecurityContext")]

internal static extern int InitializeSecurityContext(IntPtr phCredential,
IntPtr phContext, string pszTargetName, int fContextReq, int Reserved1,
int TargetDataRep, IntPtr pInput, int Reserved2, IntPtr phNewContext, ref
SecBufferDesc pOutput, ref int pfContextAttr, IntPtr ptsExpiry);
 
A

Alex Feinman [MVP]

Actually "W" conversion is done automatically for you. That's why you can
declare GetWindowText instead of GetWindowTextW and it'll work. The proof is
the exception type. If it were function name, he'd get
MissingMethodException. NotSupportedException is a clear sign of something
fishy in the P/Invoke type definition, like Long or string in the structure
or something. In his case it's of course string pointers as Chris poinrts
out. Those need to be marshalled by hand as IntPtr

--
Alex Feinman
---
Visit http://www.opennetcf.org
Paul G. Tobey said:
If you look at the exports from the security DLL, you're *not* going to
see that function name, as it takes a string parameter. Most API
functions which take string parameters are actually named with either a
"W" or an "A" at the end of the function name, indicating whether the
string parameter(s) are wide-character (Unicode), or not (ANSI). In this
case, there's a W version of the call exported by secur32.dll,
AcquireCredentialsHandleW(). Try that, instead...

Paul T.

Bill said:
I am trying to call AcquireCredentialsHandle using Interop by I get a
notsupportexception. The MSDN docs say it is supported. Has anyone got
this working? I tried it with both the ce and pocketpc emulators and both
give the same error. I also tried linking to both secur32.dll and
security.dll and neither worked.

Here is the call:

status = AcquireCredentialsHandle(
0,
"NTLM",
SECPKG_CRED_OUTBOUND,
0, ref pAuthData,
0, 0,
m_Credentials,
ref Expiration);

//Def

[StructLayout(LayoutKind.Sequential)]
internal struct SEC_WINNT_AUTH_IDENTITY
{
public string User;
public int UserLength;
public string Domain;
public int DomainLength;
public string Password;
public int PasswordLength;
public int Flags;
}

[DllImport(@"secur32.dll", EntryPoint="InitializeSecurityContext")]

internal static extern int InitializeSecurityContext(IntPtr phCredential,
IntPtr phContext, string pszTargetName, int fContextReq, int Reserved1,
int TargetDataRep, IntPtr pInput, int Reserved2, IntPtr phNewContext, ref
SecBufferDesc pOutput, ref int pfContextAttr, IntPtr ptsExpiry);
 
B

Bill

Are there samples anywhere that show the way to perform a StringToBSTR
manually since it is not available in the Compact framework? Also what is
the MarshalEx class that I see everywhere?


Alex Feinman said:
Actually "W" conversion is done automatically for you. That's why you can
declare GetWindowText instead of GetWindowTextW and it'll work. The proof
is the exception type. If it were function name, he'd get
MissingMethodException. NotSupportedException is a clear sign of something
fishy in the P/Invoke type definition, like Long or string in the
structure or something. In his case it's of course string pointers as
Chris poinrts out. Those need to be marshalled by hand as IntPtr

--
Alex Feinman
---
Visit http://www.opennetcf.org
Paul G. Tobey said:
If you look at the exports from the security DLL, you're *not* going to
see that function name, as it takes a string parameter. Most API
functions which take string parameters are actually named with either a
"W" or an "A" at the end of the function name, indicating whether the
string parameter(s) are wide-character (Unicode), or not (ANSI). In this
case, there's a W version of the call exported by secur32.dll,
AcquireCredentialsHandleW(). Try that, instead...

Paul T.

Bill said:
I am trying to call AcquireCredentialsHandle using Interop by I get a
notsupportexception. The MSDN docs say it is supported. Has anyone got
this working? I tried it with both the ce and pocketpc emulators and
both give the same error. I also tried linking to both secur32.dll and
security.dll and neither worked.

Here is the call:

status = AcquireCredentialsHandle(
0,
"NTLM",
SECPKG_CRED_OUTBOUND,
0, ref pAuthData,
0, 0,
m_Credentials,
ref Expiration);

//Def

[StructLayout(LayoutKind.Sequential)]
internal struct SEC_WINNT_AUTH_IDENTITY
{
public string User;
public int UserLength;
public string Domain;
public int DomainLength;
public string Password;
public int PasswordLength;
public int Flags;
}

[DllImport(@"secur32.dll", EntryPoint="InitializeSecurityContext")]

internal static extern int InitializeSecurityContext(IntPtr
phCredential, IntPtr phContext, string pszTargetName, int fContextReq,
int Reserved1, int TargetDataRep, IntPtr pInput, int Reserved2, IntPtr
phNewContext, ref SecBufferDesc pOutput, ref int pfContextAttr, IntPtr
ptsExpiry);
 
C

Chris Tacke, eMVP

The SDF is replete with examples of just about every type of marshaling you
can think of.

www.opennetcf.org/sdf

--
Chris Tacke
Co-founder
OpenNETCF.org
Has OpenNETCF helped you? Consider donating to support us!
http://www.opennetcf.org/donate


Bill said:
Are there samples anywhere that show the way to perform a StringToBSTR
manually since it is not available in the Compact framework? Also what is
the MarshalEx class that I see everywhere?


Alex Feinman said:
Actually "W" conversion is done automatically for you. That's why you can
declare GetWindowText instead of GetWindowTextW and it'll work. The proof
is the exception type. If it were function name, he'd get
MissingMethodException. NotSupportedException is a clear sign of
something fishy in the P/Invoke type definition, like Long or string in
the structure or something. In his case it's of course string pointers as
Chris poinrts out. Those need to be marshalled by hand as IntPtr

--
Alex Feinman
---
Visit http://www.opennetcf.org
Paul G. Tobey said:
If you look at the exports from the security DLL, you're *not* going to
see that function name, as it takes a string parameter. Most API
functions which take string parameters are actually named with either a
"W" or an "A" at the end of the function name, indicating whether the
string parameter(s) are wide-character (Unicode), or not (ANSI). In
this case, there's a W version of the call exported by secur32.dll,
AcquireCredentialsHandleW(). Try that, instead...

Paul T.

I am trying to call AcquireCredentialsHandle using Interop by I get a
notsupportexception. The MSDN docs say it is supported. Has anyone got
this working? I tried it with both the ce and pocketpc emulators and
both give the same error. I also tried linking to both secur32.dll and
security.dll and neither worked.

Here is the call:

status = AcquireCredentialsHandle(
0,
"NTLM",
SECPKG_CRED_OUTBOUND,
0, ref pAuthData,
0, 0,
m_Credentials,
ref Expiration);

//Def

[StructLayout(LayoutKind.Sequential)]
internal struct SEC_WINNT_AUTH_IDENTITY
{
public string User;
public int UserLength;
public string Domain;
public int DomainLength;
public string Password;
public int PasswordLength;
public int Flags;
}

[DllImport(@"secur32.dll", EntryPoint="InitializeSecurityContext")]

internal static extern int InitializeSecurityContext(IntPtr
phCredential, IntPtr phContext, string pszTargetName, int fContextReq,
int Reserved1, int TargetDataRep, IntPtr pInput, int Reserved2, IntPtr
phNewContext, ref SecBufferDesc pOutput, ref int pfContextAttr, IntPtr
ptsExpiry);
 
A

Alex Feinman [MVP]

In most cases passing a string to the API that expects BSTR just works. FOr
some special occasions you can P/Invoke SysAllocString

--
Alex Feinman
---
Visit http://www.opennetcf.org
Bill said:
Are there samples anywhere that show the way to perform a StringToBSTR
manually since it is not available in the Compact framework? Also what is
the MarshalEx class that I see everywhere?


Alex Feinman said:
Actually "W" conversion is done automatically for you. That's why you can
declare GetWindowText instead of GetWindowTextW and it'll work. The proof
is the exception type. If it were function name, he'd get
MissingMethodException. NotSupportedException is a clear sign of
something fishy in the P/Invoke type definition, like Long or string in
the structure or something. In his case it's of course string pointers as
Chris poinrts out. Those need to be marshalled by hand as IntPtr

--
Alex Feinman
---
Visit http://www.opennetcf.org
Paul G. Tobey said:
If you look at the exports from the security DLL, you're *not* going to
see that function name, as it takes a string parameter. Most API
functions which take string parameters are actually named with either a
"W" or an "A" at the end of the function name, indicating whether the
string parameter(s) are wide-character (Unicode), or not (ANSI). In
this case, there's a W version of the call exported by secur32.dll,
AcquireCredentialsHandleW(). Try that, instead...

Paul T.

I am trying to call AcquireCredentialsHandle using Interop by I get a
notsupportexception. The MSDN docs say it is supported. Has anyone got
this working? I tried it with both the ce and pocketpc emulators and
both give the same error. I also tried linking to both secur32.dll and
security.dll and neither worked.

Here is the call:

status = AcquireCredentialsHandle(
0,
"NTLM",
SECPKG_CRED_OUTBOUND,
0, ref pAuthData,
0, 0,
m_Credentials,
ref Expiration);

//Def

[StructLayout(LayoutKind.Sequential)]
internal struct SEC_WINNT_AUTH_IDENTITY
{
public string User;
public int UserLength;
public string Domain;
public int DomainLength;
public string Password;
public int PasswordLength;
public int Flags;
}

[DllImport(@"secur32.dll", EntryPoint="InitializeSecurityContext")]

internal static extern int InitializeSecurityContext(IntPtr
phCredential, IntPtr phContext, string pszTargetName, int fContextReq,
int Reserved1, int TargetDataRep, IntPtr pInput, int Reserved2, IntPtr
phNewContext, ref SecBufferDesc pOutput, ref int pfContextAttr, IntPtr
ptsExpiry);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top