473,394 Members | 1,828 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,394 software developers and data experts.

convert code snippet from VB6 to C#

13
Hello guys!

I have a code sample in VB6. I'd like to use this steps in my C# application.

The VB6 code snippet:
Expand|Select|Wrap|Line Numbers
  1. Public Declare Function MXReadFingerFromSensor Lib "MXOTDLL.dll" (ByRef FingerBuf As Byte) As Integer
  2.  
  3. Dim FingerBuf(256, 304) As Byte
  4.  
  5. MXReadFingerFromSensor(FingerBuf(0, 0))
  6.  
I know how to call the function from the dll but I don't know how to create a file buffer (is it a 2d array of type of byte or else) to put it in a reference for function call because I don't know exactly what the 3th line of code does. And I have a question:
In the MXReadFingerFromSensor is the FungerBuf variable a function argument. The 0, 0 arguments tell that the MXReadFingerFromSensor function should start to fill the buffer from the begining?

Please give me an explicit example for doing this in C# so I can recive the file buffer from the function.
Mar 20 '08 #1
6 2225
balabaster
797 Expert 512MB
Expand|Select|Wrap|Line Numbers
  1. [DllImport("MXOTDLL.dll")]
  2. static extern int32 MXReadFingerFromSensor(byte[] FingerBuf);
  3.  
  4. byte[256,304] FingerBuf;
  5. MXReadFingerFromSensor(FingerBuf[0, 0]);
  6.  
I don't have the DLL itself, so I've got no way to test it...but that should be along the right lines.
Mar 20 '08 #2
Funky
13
Thanks for the suggestion! I tried it but the 4th line have a wrong syntax for the csharp compiler. But I tried to modify the line with help of your suggestion and wrote this piece of code which was ok for the compiler:

Expand|Select|Wrap|Line Numbers
  1. [DllImport("MXOTDLL.DLL", EntryPoint = "MXReadFingerFromSensor")]
  2. public static extern int ReadFingerFromSensor(ref byte[,] FingerBuf);
  3.  
  4. byte[,] fingerBuf = new byte[256, 304];
  5. int ret = USBFingerprintReader.ReadFingerFromSensor(ref fingerBuf);
It's ok for the compiler but my application crashes. I think that's because I couldn't give to the funtion the argument fingerBuf like this: ref fingerBuf[0, 0]. The compiler spitts out this error explanation:

Error 1 The best overloaded method match for 'Docking.PrecitajOdtis.USBFingerprintReader.ReadFi ngerFromSensor(ref byte[*,*])' has some invalid arguments D:\My docs\Visual Studio 2008\Projects\Docking\Docking\PrecitajOdtis.cs 80 14 Docking
Error 2 Argument '1': cannot convert from 'ref byte' to 'ref byte[*,*]' D:\My docs\Visual Studio 2008\Projects\Docking\Docking\PrecitajOdtis.cs 80 60 Docking



But I still do not understand, what this type means: byte[,] :). So I think I just have a syntactical problem because I don't know how to use this kind of arrays. If you would like to test the dll you also must have the device for reading finger prints :|.

Regards.
Mar 21 '08 #3
Funky
13
Uh ... I just have to change the function argument definition so it is only a byte, not an array:

Expand|Select|Wrap|Line Numbers
  1. [DllImport("MXOTDLL.DLL", EntryPoint = "MXReadFingerFromSensor")]
  2. public static extern int ReadFingerFromSensor(ref byte FingerBuf);
  3.  
  4. byte[,] fingerBuf = new byte[256, 304];
  5. int ret = USBFingerprintReader.ReadFingerFromSensor(ref fingerBuf[0, 0]);
Now the app doesn't crash!

I'd still like to know what byte[,] means :). I thing it is kind of 2D array.
Mar 21 '08 #4
Plater
7,872 Expert 4TB
If your unmanaged function def took a byte array, I am surprised it works when only getting a single byte (which would be I guess an an array of "1")
How you tested it thoroughly? Seems like there would be memory corruption if it expects to be using an X by Y 2D array but only gets the memory allocated for it of a single byte.
Mar 21 '08 #5
balabaster
797 Expert 512MB
Sorry, the change you put is correct:
Expand|Select|Wrap|Line Numbers
  1. byte[,] FingerBuf = new byte[256,304];
I must be spending too much time writing VB instead of C#...eek.

byte[,] initializes a 2 dimensional array of type byte. A byte is really a numeric representation of some value in the system. For instance the character "A" might really be stored as numeric value 65 (I don't recall if that's the correct value off the top of my head).

new byte[256,304] assigns a size to the byte array - think of it like a spreadsheet with 256 cells across and 304 cells wide.

Each relevant co-ordinate (represented by a corresponding "cell" of your "spreadsheet") would hold a value pertaining to what the fingerprint reader sees at that co-ordinate. The byte array is really a numeric representation of your fingerprint.
Mar 21 '08 #6
Funky
13
I suspected it is a 2D array but I didn't knew that besides array[][] definition exists also array[,] definition :) maybe it isn't quite the same thing.

Plater: I tested the code for reading a finger print and store it to a bitmap image to disc. It works well. It seems that the function needs only the first pointer of the "spreadsheet" (like balabaster said) of the fingerprint picture grid - array[0, 0] or the pointer to the first cell. The function can then get all the other cells.

Regards.
Mar 21 '08 #7

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

Similar topics

4
by: Richard Hollenbeck | last post by:
I'm trying to write some code that will convert any of the most popular standard date formats twice in to something like "dd Mmm yyyy" (i.e. 08 Jan 1908) and compare the first with the second and...
1
by: Fritz Switzer | last post by:
With two controls a PictureBox and another "PictureBox like" , Pic2, a control from a dll, I'm stuck on cannot implicity convert System.Drawing.Image to System.Drawing.Bitmap error. How do I...
6
by: clintonG | last post by:
This code has to go into the global.asax Application_Start code block. I'm just not getting this one right and the web-based code converters choke on it. Can somebody rewrite this VB snippet to C#...
23
by: comp.lang.tcl | last post by:
I have a TCL proc that needs to convert what might be a list into a string to read consider this: ]; # OUTPUTS Hello World which is fine for PHP ]; # OUTPUT {{-Hello}} World, which PHP...
5
by: Learner | last post by:
Hello, Here is the code snippet I got strucked at. I am unable to convert the below line of code to its equavalent vb.net code. could some one please help me with this? static public...
17
by: Terry Jolly | last post by:
New to C# ---- How do I convert a Date to int? In VB6: Dim lDate as long lDate = CLng(Date) In C#
5
by: nil | last post by:
hello everyone can any one tell me how can i convert my grid data in to pdf?pls provide some code snippet or some link that contains the related topic.. Thanks & Regards, Nil
13
by: frk.won | last post by:
I am interested in learning how to use the VS 2005 code snippets. However, I wish to know what are the best ways to source control the code snippets? Are there any source safe/subversion...
4
by: tshad | last post by:
I am trying to convert a string character to an int where the string is all numbers. I tried: int test; string stemp = "5"; test = Convert.ToInt32(stemp); But test is equal to 53.
9
by: myotheraccount | last post by:
Hello, Is there a way to convert a DataRow to a StringArray, without looping through all of the items of the DataRow? Basically, I'm trying to get the results of a query and put them into a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
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...
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
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...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
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 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.