I want to integrate SecurID two-factor authentication system of the
RSASecurity.inc into our asp.net application,but I get into trouble when
trying to call the API functions of the ACE Agent,I got an error message
saying "Cannot marshal parameter #2: Invalid managed/unmanaged type
combination (this value type must be paired with Struct)" when calling
"AceGetPinParams(iHandle,ref sd_pin)" function,here's my test code:
[DllImport("aceclnt")]
private static extern bool AceInitialize();
[DllImport("aceclnt")]
private static extern int SD_Init(ref IntPtr iHandle);
[DllImport("aceclnt")]
private static extern int SD_Close(IntPtr iHandle);
[DllImport("aceclnt")]
private static extern int SD_Lock(IntPtr iHandle,string uname);
[DllImport("aceclnt")]
private static extern int SD_Check(IntPtr iHandle,string passwd,string
uname);
[DllImport("aceclnt")]
private static extern int SD_Pin(IntPtr iHandle,string pin);
[DllImport("aceclnt")]
private static extern int AceGetPinParams(IntPtr iHandle,ref SD_PinParams
pin);
private void button1_Click(object sender, System.EventArgs e)
{
AuthStatus aStatus=AuthStatus.InitFailed;
if(AceInitialize())//Initialize succeeded
{
int statusCode;
aStatus=AuthStatus.CommunicationFailed;
IntPtr iHandle=new IntPtr(0);
statusCode=SD_Init(ref iHandle);
if(statusCode==0)//Communication with the auth server succeeded
{
aStatus=AuthStatus.AccessDenied;
statusCode=SD_Lock(iHandle,uname.Text);//user has been locked
if(statusCode==0)
{
statusCode=SD_Check(iHandle,pwd.Text,uname.Text);
aStatus=(AuthStatus)statusCode;
if(aStatus==AuthStatus.NewPinRequired)
{
MessageBox.Show("New Pin Required£¡");
SD_PinParams sd_pin=new SD_PinParams();
int i=AceGetPinParams(iHandle,ref sd_pin);
if(i==1)
{
MessageBox.Show(sd_pin.Min.ToString());
MessageBox.Show(sd_pin.Selectable.ToString());
}
}
}
}
SD_Close(iHandle);
}
}
public const int LENPRNST = 16;
[StructLayout(LayoutKind.Sequential)]
public struct SD_PinParams
{
public byte Min;
public byte Max;
public byte Selectable;
public byte Alphanumeric;
[MarshalAs(UnmanagedType.LPArray, SizeConst=LENPRNST+2)]
public byte[] System;
}
public enum AuthStatus
{
InitFailed=1000,//Initialize Failed
CommunicationFailed=1001,//Communication failed
NextCodeRequired=2,//Next token code required
NewPinRequired=5,//New Pin required
Succeeded=0,//Authentication succeeded
AccessDenied=1,//Access denied
InvalidPassCode=902,//Invalid passcode
InvalidUserName901,//Invalid user name
InvalidHandle=101,//Invalid handle
}
public enum NewPinStatus
{
InvalidPin=800,//Invalid pin
Accepted=6,//new pin accepted
Rejected=7,//new pin rejected
InvalidHandle=101,//invalid handle
}
Here's the description of the ACEGetPinParams API function:
Description
int WINAPI AceGetPinParams(
SDI_HANDLE Sdi_handle,
SD_PIN *val)
typedef struct{
SD_CHAR Min;
SD_CHAR Max;
SD_CHAR Selectable;
SD_CHAR Alphanumeric;
SD_CHAR System[LENPRNST+2];
}SD_PIN
The AceGetPinParams function obtains all of the PIN-related parameters at
once. It is
helpful to retrieve this value when the result code from AceCheck is
ACM_NEW_PIN_REQUIRED and the Agent is designed to validate that the new PIN
entered by the user conforms to the required PIN characteristics set by the
RSA ACE/Server
administrator. Any such checking done by the Agent is simply as a
convenience to the user.
The PIN will be fully checked for correctness by the RSA ACE/Server.
Architecture
The caller of this synchronous function must supply, as the second argument,
a pointer to a
structure of type SD_PIN, into which the function will copy the PIN
parameters.
AceGetPinParams does not allocate storage for the data on its own.
Input Arguments
SdiHandle The value of a handle originally assigned by a call to AceInit.
Val A pointer to a structure of type SD_PIN that will contain
copies of the PIN parameters.
Outputs and Post Conditions
The function returns ACE_SUCCESS if the handle to the authentication data
was found and
the PIN value was provided by the function.
Error Handling
A value of ACE_ERR_INVALID_HANDLE is returned if the handle to the
authentication
data cannot be found.
//type definition
typedef int SDI_HANDLE, * LP_SDI_HANDLE;
typedef char SD_CHAR; /* ch or sz */
#define LENPRNST 16
How can I solve this problem,any help will be greatly appreciated! 3 4709 [StructLayout(LayoutKind.Sequential)] public struct SD_PinParams { public byte Min; public byte Max; public byte Selectable; public byte Alphanumeric; [MarshalAs(UnmanagedType.LPArray, SizeConst=LENPRNST+2)] public byte[] System; }
You can't use LPArray this way. If the member really is a pointer to
the array, use IntPtr as its type. If it's an inline array, use
UnmanagedType.ByValArray instead.
Mattias
--
Mattias Sjögren [MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Thank you very much,I changed byte[] to IntPtr and it works!!
Thanks again!!
"Mattias Sjögren" <ma********************@mvps.org>
??????:#U**************@TK2MSFTNGP10.phx.gbl... [StructLayout(LayoutKind.Sequential)] public struct SD_PinParams { public byte Min; public byte Max; public byte Selectable; public byte Alphanumeric; [MarshalAs(UnmanagedType.LPArray, SizeConst=LENPRNST+2)] public byte[] System; }
You can't use LPArray this way. If the member really is a pointer to the array, use IntPtr as its type. If it's an inline array, use UnmanagedType.ByValArray instead. Mattias
-- Mattias Sjögren [MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com Please reply only to the newsgroup.
Thank you very much,I changed type[] to IntPtr and it works!!
"Mattias Sjögren" <ma********************@mvps.org>
??????:#U**************@TK2MSFTNGP10.phx.gbl... [StructLayout(LayoutKind.Sequential)] public struct SD_PinParams { public byte Min; public byte Max; public byte Selectable; public byte Alphanumeric; [MarshalAs(UnmanagedType.LPArray, SizeConst=LENPRNST+2)] public byte[] System; }
You can't use LPArray this way. If the member really is a pointer to the array, use IntPtr as its type. If it's an inline array, use UnmanagedType.ByValArray instead. Mattias
-- Mattias Sjögren [MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com Please reply only to the newsgroup. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Stephen Gennard |
last post by:
Hello,
I having a problem dynamically invoking a static method that takes a
reference to a SByte*. If I do it directly it works just fine.
Anyone any ideas why?
I have include a example...
|
by: Rudy Velthuis |
last post by:
Hello,
Does anyone know how to create a struct that will marshal to the
following C++ struct A, containing an array of the user defined String10
type:
struct String10
{
char SLen;
char S;
|
by: Jeff |
last post by:
I am struggling with the following
How do I marshal/access a pointer to an array of strings within a structure
Than
Jef
----------------------------------------------------------------
|
by: Nadav |
last post by:
Hi
I am about to write a performance crutial system, I am considering writing this system based on native COM or unmanaged C++ exposed as CLI, Now, I Wonder... does exposing a native code through...
|
by: MarioSchymura |
last post by:
Hi Everybody.
I've got to use the following function of a C++ DLL:
CT_data (
unsigned short Ctn,
unsigned char *Dad,
unsigned char *Sad,
unsigned short Lc,
unsigned char *Cmd,
unsigned...
|
by: mirek |
last post by:
Hi,
I'm trying to import my old code to the .NET using managed wrappers.
I've read "Managed Extensions for C++ Migration Guide" document and was
trying to do what it stated in it. For example if...
|
by: bluewing |
last post by:
Hi, everybody!
I have to use Unmanaged Code DLL for my .Net Application.
This Dll has a few functions that returns BYTE* value.
but you know that C# does not have pointer type....
so, what data...
|
by: Aston Martin |
last post by:
Hi All,
********************** My Situation **********************
I am working on project that involves passing a structure to unmanaged
code from .Net world (well using C#). Perhaps an example...
|
by: Bjarne Nielsen |
last post by:
Hi all
From a C# program, I need to call an unmanaged (C++) dll. The dll fills an
array with variables and returns that to the C# program. When I have a
fixed sized array, this works fine by...
|
by: michelqa |
last post by:
Hi,
I need to call a lot of different native SendMessage to retreive
informations from non managed application.
Some win32 messages use struct pointer for lparam....how to create and...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |