473,396 Members | 1,961 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Using C++ dll with C#

3
Hi there every1, i've been stuck on a problem for longer then any1 could of expected...

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{
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;
<<Here is the example used in C++>>
BSUserHdr userHeader;
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 );
<<this what i have attempted so far in C#>>
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.
May 28 '07 #1
2 2714
weaknessforcats
9,208 Expert Mod 8TB
There's something about interoperability here.

Check out the C# DLL class that extends Object.

I assume the C++ dll works in C++. Yes?
May 28 '07 #2
DaZeD
3
There's something about interoperability here.

Check out the C# DLL class that extends Object.

I assume the C++ dll works in C++. Yes?
Yea the c++ DLL works. The C# dll is also working because im using other methods from the dll and they work. it is just this method, i think im doing some thing wrong with the convertion of data types.

the code runs but when i call the method from the dll i get a error saying
that there is a memory problem, but i do not see where they require pointers and memory allocation.
May 29 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Enos Meroka | last post by:
Hallo, I am a student doing my project in the university.. I have been trying to compile the program using HP -UX aCC compiler, however I keep on getting the following errors. ...
3
by: Mike L | last post by:
Should the command call "using" be before or after my namespace? **AFTER** namespace DataGridBrowser { using System; using System.Drawing; using System.Drawing.Drawing2D; using...
3
by: xzzy | last post by:
I was wondering why we have to have using System.Data using System.Configuration using etc.... why are they not all lumped into one 'using'? In other words, is there a best way to use...
14
by: pmud | last post by:
Hi, I need to use an Excel Sheet in ASP.NET application so that the users can enter (copy, paste ) large number of rows in this Excel Sheet. Also, Whatever the USER ENETRS needs to go to the...
8
by: acb | last post by:
Hi, I wrote a DLL Component (using Visual Studio 2005) and managed to include it into a C# Console application. I am now trying to include this component into a Web project. I copy the DLL...
0
by: Metal2You | last post by:
I'm working on an ASP.NET 2.0 application in Visual Studio 2005 that accesses a Sybase database back end. We're using Sybase SQL Anywhere 9.0.2.3228. I have installed and registered the Sybase...
10
by: mg | last post by:
I'm migrating from VB6 and have a question about using 'Using' and the best way to use it. Here is a example of a small bit of code: dbConx("open") Using CN Dim CMD As New OleDbCommand(sSQL,...
0
by: Eugene Anthony | last post by:
The problem with my coding is that despite removing the records stored in the array list, the rptPages repeater control is still visible. The rptPages repeater control displayes the navigation...
3
by: JDeats | last post by:
I have some .NET 1.1 code that utilizes this technique for encrypting and decrypting a file. http://support.microsoft.com/kb/307010 In .NET 2.0 this approach is not fully supported (a .NET 2.0...
6
by: =?Utf-8?B?U2hhd24gU2VzbmE=?= | last post by:
Greetings! I was researching AJAX to provide a solution to displaying status messages while a long process executed. I found several examples online and was able to use their code to get a quick...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
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,...
0
jinu1996
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.