My problem is that i have a method that i have to call in C#, that comes from C++ DLL, easy enough to call a method but what i cant get is that, i have to send a pointer to a struct as a parameter.
My second problem is that a few of the data type's have to change.
The code looks like this.
<<Struct>>
typedef struct{<<Here is the example used in C++>>
unsigned ID;
unsigned short reserved1;
unsigned short adminLevel;
unsigned short securityLevel;
unsigned short statusMask; // internally used by BIOSTATION
unsigned accessGroupMask;
char name[32];
char department[32];
char password[16];
unsigned short numOfFinger;
unsigned short duressMask;
unsigned short checksum[5];
} BSUserHdr;
BSUserHdr userHeader;<<this what i have attempted so far in C#>>
userHeader.ID = 1; // 0 cannot be assigned as a user ID.
userHeader.adminLevel = 240;
userHeader.securityLevel = 260;
userHeader.accessGroupMask = 0; // a member of Group 1 and Group 2;
strcpy( userHeader.name, “John” );
strcpy( userHeader.departments, “R&D” );
strcpy( userHeader.password, NULL ); // no password is enrolled. Password
// should be longer than 4 bytes.
userHeader.numOfFinger = 2;
unsigned char* templateBuf = (unsigned char*)malloc( userHeader.numOfFinger * 2 * BS_TEMPLATE_SIZE );
// fill template data
userHeader.duressMask = 0; // no duress finger
for( int i = 0; i < userHeader.numOfFinger * 2; i++ )
{
if( i % 2 == 0 )
{
userHeader.checksum[i/2] = 0;
}
unsigned char* templateData = templateBuf + i * BS_TEMPLATE_SIZE;
for( int j = 0; j < BS_TEMPLATE_SIZE; j++ )
{
userHeader.checksum[i/2] += templateData[j];
}
}
BS_RET_CODE result = BS_EnrollUser( handle, &userHeader, templateBuf );
public int EnrollUser(int id, String nme, String pswd, String dept, String adminLevel, String securityLevel)<<>>
{
int success = 0;
short BS_TEMPLATE_SIZE = 384;
try
{
BSUserHdr userHeader = new BSUserHdr();
userHeader.checksum = new short[5];
//userHeader.ID = 2;
userHeader.ID = id;
userHeader.numOfFinger = 1;
//password
int pwdSize = 16;
byte[] pwd = new byte[pwdSize];
//String password = "3456";
String password = pswd;
for (int index = 0; index < password.Length; index++)
{
pwd[index] = Convert.ToByte(password[(index)]);
}
userHeader.password = pwd;
//name
int nameSize = 32;
byte[] name = new byte[nameSize];
//String Name = "Regan";
String Name = nme;
for (int index = 0; index < Name.Length; index++)
{
name[index] = Convert.ToByte(Name[(index)]);
}
userHeader.name = name;
//Department
int depSize = 32;
byte[] dep = new byte[depSize];
//String department = "Development";
String department = dept;
for (int index = 0; index < department.Length; index++)
{
dep[index] = Convert.ToByte(department[(index)]);
}
userHeader.department = dep;
//Admin Level
if (adminLevel == "BS_USER_ADMIN")
{
userHeader.adminLevel = 240;
}
else
{
if (adminLevel == "BS_USER_NORMAL")
{
userHeader.adminLevel = 241;
}
else
{
throw new Exception("Incorrect user type");
}
}
//Access Group Mask
//userHeader.accessGroupMask = Convert.ToInt32(0xffffffff);
userHeader.accessGroupMask = Convert.ToInt32(0);
//security Level
userHeader.securityLevel = 260;
switch(securityLevel)
{
case "BS_USER_SECURITY_DEFAULT": userHeader.securityLevel = 260;
break;
case "BS_USER_SECURITY_LOWER": userHeader.securityLevel = 261;
break;
case "BS_USER_SECURITY_LOW": userHeader.securityLevel = 262;
break;
case "BS_USER_SECURITY_NORMAL": userHeader.securityLevel = 263;
break;
case "BS_USER_SECURITY_HIGH": userHeader.securityLevel = 264;
break;
case "BS_USER_SECURITY_HIGHER": userHeader.securityLevel = 265;
break;
default:
throw new Exception("Incorrect Security Level");
break;
}
//DuressMask
//userHeader.duressMask = Convert.ToInt32(0xff);
userHeader.duressMask = 0;
//Fingers
byte[] templateBuffer = new byte[userHeader.numOfFinger * BS_TEMPLATE_SIZE * 2];
for (int i = 0; i < (userHeader.numOfFinger * 2); i++)
{
byte[] finger = new byte[BS_TEMPLATE_SIZE];
BS_Disable(handle, 30);
success = ScanTemplate(ref finger);
BS_Enable(handle);
int cursorPosition = i * BS_TEMPLATE_SIZE;
int index = 0;
for (int x = cursorPosition; x < (cursorPosition + BS_TEMPLATE_SIZE); x++)
{
templateBuffer[x] = finger[index];
index++;
}
int k = 0;
int cursorPosition1 = i * BS_TEMPLATE_SIZE;
for (int j = cursorPosition1; j < BS_TEMPLATE_SIZE; j++)
{
userHeader.checksum[i / 2] += Convert.ToInt16(finger[k]);
k++;
}
}
success = BS_EnrollUser(handle, ref userHeader, templateBuffer);
}
catch (Exception err)
{
throw new Exception(err.Message);
}
return success;
}
It looks like a mess....
Any assistance will be greatly appreciated
Thanx every1.