Difficulties with Dll import C#

Asked

Viewed 334 times

1

I’m having a hard time rewriting a method of a dll in C#, we bought a price checker from a manufacturer, in case it provides a dll and an example code in Delphi.

This dll has some functions between them start the service with the reader, read the data, check which devices are connected, etc. In case I want to transform this method:

function bReceiveBarcode(var stAddress; var BarCode: PChar): Boolean; 
stdcall; 

In a method available in C#, so I tried to create this method:

[DllImport("VP.dll", EntryPoint = "bReceiveBarcode")]
private static extern Boolean bReceiveBarcode(ref stAddress, ref string barcode);

In the case stAddress is a struct, I am trying to use this method in my application, but error appears Identificador esperando it is as if the first parameter is wrong.

  • has to have a type in the parameter... ref stAddress try ref object stAddress

1 answer

2


it is as if the first parameter is wrong.

It is wrong, you need to set the parameter type.

[DllImport("VP.dll", EntryPoint = "bReceiveBarcode")]
private static extern Boolean bReceiveBarcode(ref object stAddress, ref string barcode);
  • Thank you, but now I am trying to use this method, but it appears that arguments 1 and argument 2 should not be transmitted with the ref keyword. stBarcode is a variable of the struct stAddress and Barcode is a string variable, I tried to get them to receive the value by reference. I also tried to put ref before arguments, but it didn’t work. if (bReceiveBarcode(stBarcode, Barcode)) { Messagebox.Show("Barcode number:" + Barcode); }

  • @Flávionavesjr If the problem of this question has been solved, open a new question with the new problem. So we keep the site organized. By the way, if the answer helped you you can mark it as correct using the on the left side of the response.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.