|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Pass byte array from vb.net to unmanaged codeI am trying to read a buffer from a file and then pass that buffer to a C++ dll as follows. While debugging it tells me that byte array received is a Bad Ptr. Any help will be appreciated. VB code: Dim bytes(511) As Byte Dim stream As Stream Dim bytesReadFromStream As Integer stream = New FileStream("C:\abc.bak", FileMode.Open, FileAccess.Read) bytesReadFromStream = stream.Read(bytes, 0, 512) While bytesReadFromStream > 0 SendBytesToFn(bytesReadFromStream , bytes) bytesReadFromStream = stream.Read(bytes, 0, 512) End While stream.Close() <System.Runtime.InteropServices.DllImport("MyDll.dll", CharSet:=System.Runtime.InteropServices.CharSet.Auto)> _ Private Sub SendBytesToFn(ByVal bytesTransferred As Int64, ByVal bytes() As Byte) End Sub C++ Code: extern "C" MYDLL_API void SendBytesToFn(DWORD bytesTransferred, BYTE* bytes) { // bytes here come as Bad Ptr } > Private Sub SendBytesToFn(ByVal bytesTransferred As Int64, ByVal bytes() As Byte) ^^^^^Should be an Int32 (or UInt32). Mattias -- Mattias Sjögren [C# MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com Please reply only to the newsgroup.
Object reference not set to an instance of an object error
User Control c# to vb.net conversion Using VS 2005 my challenges with merging 2 Regex.Matches Authenticating to a service problem 1 - debugging guids Schema Information not found in web.config Printdocument.PrintPage cancel current printpage ASP.NET profile database |
|||||||||||||||||||||||