PC Review


Reply
Thread Tools Rate Thread

AcquireCredentialsHandle interop

 
 
Bill
Guest
Posts: n/a
 
      17th May 2005
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);



 
Reply With Quote
 
 
 
 
Paul G. Tobey [eMVP]
Guest
Posts: n/a
 
      17th May 2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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);
>
>
>



 
Reply With Quote
 
Chris Tacke, eMVP
Guest
Posts: n/a
 
      17th May 2005
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 [eMVP]" <ptobey no spam AT no instrument no spam DOT com>
wrote in message news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>>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);
>>
>>
>>

>
>



 
Reply With Quote
 
Alex Feinman [MVP]
Guest
Posts: n/a
 
      18th May 2005
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 [eMVP]" <ptobey no spam AT no instrument no spam DOT com>
wrote in message news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>>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);
>>
>>
>>

>
>


 
Reply With Quote
 
Bill
Guest
Posts: n/a
 
      18th May 2005
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 [MVP]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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 [eMVP]" <ptobey no spam AT no instrument no spam DOT com>
> wrote in message news:(E-Mail Removed)...
>> 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" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>>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);
>>>
>>>
>>>

>>
>>

>



 
Reply With Quote
 
Chris Tacke, eMVP
Guest
Posts: n/a
 
      18th May 2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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 [MVP]" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> 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 [eMVP]" <ptobey no spam AT no instrument no spam DOT com>
>> wrote in message news:(E-Mail Removed)...
>>> 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" <(E-Mail Removed)> wrote in message
>>> news:(E-Mail Removed)...
>>>>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);
>>>>
>>>>
>>>>
>>>
>>>

>>

>
>



 
Reply With Quote
 
Alex Feinman [MVP]
Guest
Posts: n/a
 
      19th May 2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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 [MVP]" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> 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 [eMVP]" <ptobey no spam AT no instrument no spam DOT com>
>> wrote in message news:(E-Mail Removed)...
>>> 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" <(E-Mail Removed)> wrote in message
>>> news:(E-Mail Removed)...
>>>>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);
>>>>
>>>>
>>>>
>>>
>>>

>>

>
>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Interop.CDO uses Interop.ADODB which has a higher version... muriwai Microsoft C# .NET 7 27th Oct 2011 08:00 PM
Interop Ira Davis Microsoft Dot NET 1 29th Oct 2008 09:46 PM
Using .NET 1.1 via interop from .Net 2.0 schaf Microsoft C# .NET 0 9th Jun 2008 12:07 PM
vb6 and c# interop Mohan Ekambaram Microsoft C# .NET 0 28th Jan 2004 11:00 PM
Is there a published COM Interop Wrapper for Interop.MSDASC.dll? Burton G. Wilkins Microsoft ADO .NET 0 10th Nov 2003 01:57 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:36 PM.