Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / September 2005

Tip: Looking for answers? Try searching our database.

dllimport Byte array Marshal

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
abunet - 07 Sep 2005 16:10 GMT
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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.