468,548 Members | 1,906 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,548 developers. It's quick & easy.

convert function from VB.6 to VB.NET


Please, can someone help me to translate this single function to VB.NET ?
' DECLARATIONS
Private Const BMP_MAGIC_COOKIE As Short = 19778

Private Structure BITMAPFILEHEADER '14 bytes
Dim bfType As Short
Dim bfSize As Integer
Dim bfReserved1 As Short
Dim bfReserved2 As Short
Dim bfOffBits As Integer
End Structure

Private Structure BITMAPINFOHEADER '40 bytes
Dim biSize As Integer
Dim biWidth As Integer
Dim biHeight As Integer
Dim biPlanes As Short
Dim biBitCount As Short
Dim biCompression As Integer
Dim biSizeImage As Integer
Dim biXPelsPerMeter As Integer
Dim biYPelsPerMeter As Integer
Dim biClrUsed As Integer
Dim biClrImportant As Integer
End Structure
Private Structure RGBQUAD
Dim Red As Byte
Dim Green As Byte
Dim Blue As Byte
Dim Reserved As Byte
End Structure

Private Structure BITMAP
Dim bmType As Integer
Dim bmWidth As Integer
Dim bmHeight As Integer
Dim bmWidthBytes As Integer
Dim bmPlanes As Short
Dim bmBitsPixel As Short
Dim bmBits As Integer
End Structure
Private Const BI_RGB As Integer = 0

Private Declare Function GetProcessHeap Lib "kernel32.dll" () As Integer
'handle

Private Declare Function HeapAlloc Lib "kernel32.dll" (ByVal hHeap As
Integer, ByVal dwFlags As Integer, ByVal dwBytes As Integer) As Integer

Private Declare Function HeapFree Lib "kernel32.dll" (ByVal hHeap As
Integer, ByVal dwFlags As Integer, ByVal lpMem As Integer) As Integer

Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByRef
dest As IntPtr, ByVal fromAddress As String, ByVal bytesToCopy As Long)

Private Const HEAP_ZERO_MEMORY As Integer = &H8S

Private m_memBits() As Byte
Private m_memBitmapInfo() As Byte
Private m_bih As BITMAPINFOHEADER
Private m_bfh As BITMAPFILEHEADER
'FUNCTION
Public Function CreateFromPackedDIBPointer(ByRef pDIB As Long) As Boolean

Debug.Assert pDIB <0

'Creates a full-color (no palette) DIB from a pointer to a full-color memory
DIB

'get the BitmapInfoHeader

Call CopyMemory(ByVal VarPtr(m_bih.biSize), ByVal pDIB, Len(m_bih))
If m_bih.biBitCount < 16 Then
Debug.Print "Error! DIB was less than 16 colors."
Exit Function 'only supports high-color or full-color dibs
End If

'now get the bitmap bits

If m_bih.biSizeImage < 1 Then Exit Function 'return False
ReDim m_memBits(0 To m_bih.biSizeImage - 1)
Call CopyMemory(m_memBits(0), ByVal pDIB + 40, m_bih.biSizeImage)

'and BitmapInfo variable-length UDT

ReDim m_memBitmapInfo(0 To 39) 'don't need first 14 bytes (fileinfo)
Call CopyMemory(m_memBitmapInfo(0), m_bih, Len(m_bih))

'create a file header
With m_bfh
.bfType = BMP_MAGIC_COOKIE
.bfSize = 55 + m_bih.biSizeImage 'size of file as written to disk
.bfReserved1 = 0&
.bfReserved2 = 0&
.bfOffBits = 54 'BitmapInfoHeader + BitmapFileHeader
End With

'and return True
CreateFromPackedDIBPointer = True

End Function
Aug 27 '06 #1
4 4397
"Joao Tomas" <xx@xx.comwrote in news:ec**********@news.datemas.de:
Please, can someone help me to translate this single function to VB.NET ?
Which part are you having trouble with?
Aug 27 '06 #2

"Spam Catcher" <sp**********@rogers.comwrote in message
news:Xn**********************************@127.0.0. 1...
"Joao Tomas" <xx@xx.comwrote in news:ec**********@news.datemas.de:
>Please, can someone help me to translate this single function to VB.NET ?

Which part are you having trouble with?

CopyMemory

VB.net doesn't support it anymore

vb.net is bad for memory pointers
Aug 28 '06 #3
Joao,

I am not a VB6 guy, however why do you need, it or in other words do you
known the memorystream?

http://msdn.microsoft.com/library/de...classtopic.asp

I hope this helps,

Cor
>

Aug 28 '06 #4
On Mon, 28 Aug 2006 05:13:47 +0100, "Joao Tomas" <xx@xx.comwrote:
>
"Spam Catcher" <sp**********@rogers.comwrote in message
news:Xn**********************************@127.0.0 .1...
>"Joao Tomas" <xx@xx.comwrote in news:ec**********@news.datemas.de:
>>Please, can someone help me to translate this single function to VB.NET ?

Which part are you having trouble with?


CopyMemory

VB.net doesn't support it anymore

vb.net is bad for memory pointers
Maybe this might be helpful.

(VB2005)
I have an app that uses this declare for CopyMemory:

Public Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" _
(ByVal Destination As Byte(), ByVal Source As Int32, ByVal Length As Int32)

I use it in conjunction with the API's "GlobalLock", "GlobalSize", "GlobalFree", "GlobalUnlock"

Dim bBlob() As Byte
Dim hBuffer As System.Int32 = sHandle 'handle to a memory buffer
Dim bData As Int32 = GlobalLock(hBuffer)
Dim bSize As Int32 = GlobalSize(hBuffer)
ReDim bBlob(bSize)

CopyMemory(bBlob, bData, bSize)

GlobalUnlock(bData)
GlobalFree(bData)

Gene
Aug 28 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Sam Smith | last post: by
2 posts views Thread by William Stacey | last post: by
17 posts views Thread by David Scemama | last post: by
7 posts views Thread by patang | last post: by
6 posts views Thread by patang | last post: by
4 posts views Thread by Edwin Knoppert | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by UniDue | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.