Hallo to everyone,
I have a dll called (picboot.dll) written in c++ that works in a vb6 project.
I'm trying to convert the vb project in c#.
PacketData is a byte array parameter, that reads and writes bytes to the
dll, calling the functions ReadPic and WritePic .
I've started with the new project in c#, and i've used dllimport directive
to use the dll in the project.
I've used the byte[] type to marshal the type of the dll.
The result is that ReadPIC function works fine, and I can get the PacketData
byte array.
The WRITEPIC doesn't return errors, but seems to write strange data.
The question is:
I know very little about unsafe code, and "fixed" statements, and I'd like
to know how is the right way to pass the value to the dll function.
Original in visual basic 6 (working):
Public Declare Function ReadPIC Lib "PICBOOT.dll" (ByVal hComPort As Long,
LPpic As PIC, PacketData As Byte) As Integer
Public Declare Function WritePIC Lib "PICBOOT.dll" (ByVal hComPort As Long,
LPpic As PIC, PacketData As Byte) As Integer
C++ declaration of the api entries defined in the dll:
INT APIENTRY ReadPIC(HANDLE hComPort, PIC *pic, BYTE PacketData[]);
INT APIENTRY WritePIC(HANDLE hComPort, PIC *pic, BYTE PacketData[]);
Declaration in VC#
[DllImport("PICBOOT.dll")]
private static extern int ReadPIC(int hComPort, ref PIC pic, byte[]
PacketData);
[DllImport("PICBOOT.dll")]
private static extern int WritePIC(int hComPort, ref PIC pic, byte[]
PacketData);
Any informations will be appreciated
Thanks in advance,
Marco Roello
Mattias Sjögren - 09 Sep 2005 19:59 GMT
>The question is:
>I know very little about unsafe code, and "fixed" statements, and I'd like
>to know how is the right way to pass the value to the dll function.
It looks like your current declarations should work, and you should
just be able to pass in the byte array as teh last argument.
What makes you think it writes "strange" data?
Mattias

Signature
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.