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.
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
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.
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.
i 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;
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:
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".
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.