last day (15 days later) » 

08:38
Hope you dont mind me starting a room
but I thought it might be more efficient so as not to fill the comments section
I dont see face template buff
dbc
dbc
In the new version of your pastie, the last line now reads
result = BS_EnrollUserBioStation2( handle, &userHeader, templateBuf, faceTemplateBuf );
What's that last argument "faceTemplateBuf"?
New version is here: pastie.org/9882964
oh okay
it is an additional optional paramter
to capture face templates
If I change this part
for (int i = 0; i < userHdr.numOfFinger * 2; i++)
I get array out of bounds index error
dbc
dbc
Did you see #5 I added?
userHdr.checksum = new ushort[] { 0 }; looks wrong. Shouldn't it be something like userHdr.checksum = new ushort[userHdr.numOfFinger];
aha
changing that
dbc
dbc
Also for (int j = 0; j < 2000 - 1; j++) could generate an out of bounds error.
c++ code does for( int j = 0; j < BS_TEMPLATE_SIZE; j++ ) which looks reasonable.
08:46
@dbc It was generating an out of array bounds error before so I did that but that ws b4 u cleaned it up
let me try that as well
@dbc this also I cooked up ->byte[] templateData = templateBuf;
dbc
dbc
I think you want
            for (int j = 0; j < BS_TEMPLATE_SIZE; j++)
            {
                userHdr.checksum[i / 2] += templateData[i * BS_TEMPLATE_SIZE + j];
            }\
in C++ was this-> unsigned char* templateData = templateBuf + i * BS_TEMPLATE_SIZE;
but dint make sense to concatenate a byte[] to an int
dbc
dbc
The c++ code is doing trivial optimization of pointer arithmetic. Speeds it up a little but makes it harder to understand and convert to c#
Woops I meant
            for (int j = 0; j < BS_TEMPLATE_SIZE; j++)
            {
                userHdr.checksum[i / 2] += templateBuf[i * BS_TEMPLATE_SIZE + j];
            }
you are very good at it though
dbc
dbc
Get rid of the variable templateData it's just caching some pointer arithmetic.
Thanks.
08:51
And thanks for not ignoring or downvoting my question
I couldnt figure out any other way to ask it
also I think the error am getting maybe is because am not using some pointer to userhdr
result = BSSDK.BS_EnrollUserBioStation2(m_Handle, ptr1, templateBuf);
which their using result = BS_EnrollUserBioStation2( handle, &userHeader, templateBuf, faceTemplateBuf );
dbc
dbc
Downvotes were probably because your question didn't include any code, and people don't like having to chase down code on a foreign side. Suggest including at least come of the code in future questions.
there was too much code there I was afraid they'd just look at it and assume am just sitting back and assuming people will work through it for me
Is my declaration and initialising of intpointer wrong?
dbc
dbc
Yes, your DllImport looks off, hold on a second...
Think it should be public static extern int BS_EnrollUserBioStation2(int handle, ref BSUserHdrEx userHdr, byte[] templateData);
okay
dbc
dbc
Then call it like BSSDK.BS_EnrollUserBioStation2(m_Handle, ref userHdr, templateBuf);
OK, I'm looking at BS2UserHdr in webhard.suprema.co.kr//ExFd/8730/9186.zip.
09:02
problem is it gives me best overloaded method wants an intptr
okay there is the \SDK\Example\CSharp
dbc
dbc
You have omitted some of the fields from BSUserHdrEx, e.g. numOfFace.
This will mess up marshalling since the subsequent fields will not be in the correct location in memory in the unmanaged struct.
You need to have exactly the same fields, with exactly the same types and sizes, for marshalling to work.
@Gotalove - you need to change your dllimport declaration also.
    [DllImport("BS_SDK.dll",
               CharSet = CharSet.Ansi,
               EntryPoint = "BS_EnrollUserBioStation2")]
    public static extern int BS_EnrollUserBioStation2(int handle, ref BSUserHdrEx userHdr, byte[] templateData);
why would it say unassigned variable?
dbc
dbc
Suggest updating your question (or your pastie) with code. I can't guess what your unassigned variable is.
its saying userhdr is unassigned
dbc
dbc
Can you show your current version of btngetUserInfo_Click?
09:12
here or create pastier?
@dbc
dbc
dbc
Wherever convenient.
  private void btngetUserInfo_Click(object sender, EventArgs e)
        {
            BSSDK.BSUserHdrEx userHdr;
            userHdr.ID = 2; // 0 cannot be assigned as a user ID
            userHdr.startDateTime = 0; // no check for start date
            userHdr.expireDateTime = 0; // no check for expiry date
            userHdr.adminLevel = BSSDK.BS_USER_NORMAL;
            userHdr.securityLevel = BSSDK.BS_USER_SECURITY_DEFAULT;
            userHdr.authMode = BSSDK.BS_AUTH_MODE_DISABLED; // use the authentication mode of the device
dbc
dbc
I can't compile your code because I'm missing definitions for all of your constants and some of your extern declarations:
Error 1 'Scratch.BSSDK' does not contain a definition for 'BS_USER_NORMAL'
Error 2 'Scratch.BSSDK' does not contain a definition for 'BS_USER_SECURITY_DEFAULT'
Error 3 'Scratch.BSSDK' does not contain a definition for 'BS_AUTH_MODE_DISABLED'
Error 4 The name 'BS_TEMPLATE_SIZE' does not exist in the current context
Error 5 The name 'BS_TEMPLATE_SIZE' does not exist in the current context
Error 6 'Scratch.BSSDK' does not contain a definition for 'BS_ScanTemplate'
Error 7 The name 'BS_TEMPLATE_SIZE' does not exist in the current context
If you can update public static class BSSDK in your pastie maybe I can see if I get the same error.
do you have the following dlls libusb0
dbc
dbc
No.
Also, I'm not going to be able to actually install the SDK on my computer.
09:20
okay
dbc
dbc
But I can try to walk you through the struct definition and dllimport call.
I did
Just a question?do you work for suprema?
Your very quick in spotting the errors
dbc
dbc
No, I don't work for them. I've just read lots of legacy code over the years.
You are very good at it then
We can do a teamviewer
Since I have the device plugged in here
dbc
dbc
Sorry, don't have teamviewer installed.
I'm not seeing any "unassigned variable" errors. Can you update your code with the dllimport declarations for BS_ScanTemplate and BS_GetUserInfoBioStation2?
BSSDK.BS_ScanTemplate( and BSSDK.BS_GetUserInfoBioStation2 are undefined for me still.
09:34
I got rid of the error by :
BSSDK.BSUserHdrEx userHdr = new BSSDK.BSUserHdrEx();
In the BSSDK class?
Error am getting is about length due to marshalling error now
Additional information: Type could not be marshaled because the length of an embedded array instance does not match the declared length in the layout.
[DllImport("BS_SDK.dll",
            CharSet = CharSet.Ansi,
            EntryPoint = "BS_ScanTemplate")]
        public static extern int BS_ScanTemplate(int handle, byte[] templateData);
 [DllImport("BS_SDK.dll",
            CharSet = CharSet.Ansi,
            EntryPoint = "BS_GetUserBioStation2")]
        public static extern int BS_GetUserBioStation2(int handle, uint userID, IntPtr userHdr, byte[] templateData);
I think these are the ones your talking about ^
dbc
dbc
I think I need BS_GetUserInfoBioStation2 not BS_GetUserBioStation2.
Let me think about the embedded array error for a bit.
[DllImport("BS_SDK.dll",
CharSet = CharSet.Ansi,
EntryPoint = "BS_GetUserInfoBioStation2")]
public static extern int BS_GetUserInfoBioStation2(int handle, uint userID, IntPtr userHdr);
okay
dbc
dbc
09:54
See here for your array length error:
1
Q: Error : Type could not be marshaled because the length of an embedded array instance does not match the declared length in the layout

user662285i am using a COM dll in my C# Project. I have one USERINFO Structure in my COM dll which looks like : struct USERINFO { BYTE UserID[USER_ID_SIZE];//42 BYTE FirstName[NAME_SIZE];//66 BYTE LastName[NAME_SIZE]; //66 long Pin; BYTE TimeGroupIDList[IDLIST_SIZE]...

The struct you are trying to marshal is BSUserHdrEx defined on page 129 of "BioStar SDK Manual V1.8.pdf", yes?
OK, your latest marshalling error arises because your arrays name, department, password and checksum are declared to be UnmanagedType.ByValArray, SizeConst = some value.
You need make sure these arrays are allocated to this exact size.
For instance
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct BSUserHdrEx
{
public static BSUserHdrEx CreateDefaultBSUserHdrEx()
{
var userHdr = new BSUserHdrEx();
userHdr.name = new byte[BSSDK.BS_MAX_NAME_LEN + 1];
userHdr.department = new byte[BSSDK.BS_MAX_NAME_LEN + 1];
userHdr.password = new byte[BSSDK.BS_MAX_PASSWORD_LEN];
userHdr.checksum = new ushort[5];
return userHdr;
}

public uint ID;
public ushort reserved1;
public ushort adminLevel;
public ushort securityLevel;
public ushort statusMask; // internally used by BioStation
Well that paste didn't work very well.
How do I paste code?
OK let's try that paste again
` [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public struct BSUserHdrEx
{
public static BSUserHdrEx CreateDefaultBSUserHdrEx()
{
var userHdr = new BSUserHdrEx();
userHdr.name = new byte[BSSDK.BS_MAX_NAME_LEN + 1];
userHdr.department = new byte[BSSDK.BS_MAX_NAME_LEN + 1];
userHdr.password = new byte[BSSDK.BS_MAX_PASSWORD_LEN];
userHdr.checksum = new ushort[5];
return userHdr;
}

public uint ID;
public ushort reserved1;
public ushort adminLevel;
public ushort securityLevel;
By simply referencing the BSUserHdrEx in BSSDK do I not get the arrays in the exact size?
dbc
dbc
OK, 1) I modified your struct BSUserHdrEx a little to match the definition from the PDF 2) I added CreateDefaultBSUserHdrEx(). Then use the arrays as follows:
Encoding.UTF8.GetBytes("Madman").CopyTo(userHdr.name, 0);
Encoding.UTF8.GetBytes("INC").CopyTo(userHdr.department, 0);
Encoding.UTF8.GetBytes("").CopyTo(userHdr.password, 0);
The code isn't getting formatted in this chat, let me update my answer.
Still there?
Updated answer.
10:16
past marshall error
back to Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
dbc
dbc
In which call?
result = BSSDK.BS_EnrollUserBioStation2(m_Handle, ref userHdr, templateBuf);
let me update ur changes 1st
dbc
dbc
The struct you are marshalling is BSUserHdrEx.
BS_EnrollUserBioStation2 does not take this as an argument. BS_EnrollUserBioStation2 takes a BS2UserHdr as an argument.
Page 158 of "BioStar SDK Manual V1.8.pdf".
BSUserHdrEx is an argument to BS_EnrollUserEx. Page 129.
BS_EnrollUserEx "Enrolls a user to BioStation. Maximum 5 fingers can be enrolled per user."
BS_EnrollUserBioStation2 "Enrolls a user to BioStation T2. Maximum 10 fingers per user."
Either you need to switch to the former function, or use the latter data structure.
you are right
dbc
dbc
OK, I'm looking at the code in "UserManagement.cs" in "BioStar 1.8 SDK\Example\CSharp\BioStarCSharp".
They are marshalling things in a slightly convoluted way.
Rather than declaring their structures on the stack and then passing them directly to the BioStation API by adding a ref BS2UserHdr in the dllimport statement, they do the marshalling locally by calling Marshal.AllocHGlobal(Marshal.SizeOf(typeof(BSSDK.BS2UserHdr)));, then filling in the c# struct, then doing Marshal.StructureToPtr(userHdr, userInfo, true);, then calling BSSDK.BS_EnrollUserBioStation2 with the unmanaged pointer, then doing Marshal.FreeHGlobal(userInfo);.
Honestly, this is more convoluted than necessary.
But, it should work.
I'd suggest following more closely the code that calls BS_EnrollUserBioStation2 in "UserManagement.cs".
10:33
Am feeling really stupid now coz I just realised i have never opened this class file
I will go through it
dbc
dbc
I need to step away now. I'd suggest trying to follow the examples from the SDK file "UserManagement.cs". If you have any specific problems, feel free to ask another question. If you add a bit more detail to the question, you're likely to get more responses.
Good bye for now.
11:05
thanks alot man
youve been a great help

  last day (15 days later) »