|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
convert VB6 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 Define the struct with 'Sequential' Layout.
Functions would be simple DllImport's. What's the problem that you are facing? -- Show quoteHappy Hacking, Gaurav Vaish | http://www.mastergaurav.org http://www.edujini.in | http://webservices.edujini.in ------------------- "Joao Tomas" <x*@xx.com> wrote in message news:ecs85v$gd9$1@news.datemas.de... > > 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 > > > > CopyMemory> What's the problem that you are facing? > VB.net doesn't support it anymore vb.net is bad for memory pointers You may want to use 'memcpy' defined in 'user32.dll' (or 'kernel32.dll'...
just slipping from my mind).. -- Show quoteHappy Hacking, Gaurav Vaish | http://www.mastergaurav.com http://www.edujini.in | http://articles.edujini.in/webservices ------------------- "Joao Tomas" <x*@xx.com> wrote in message news:ecsua7$mce$1@news.datemas.de... > > >> What's the problem that you are facing? >> > > CopyMemory > > VB.net doesn't support it anymore > > vb.net is bad for memory pointers > |
|||||||||||||||||||||||