473,385 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 4548
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Sam Smith | last post by:
Hi, I wan't a function to take a const char*, a start bit position and number of bits and convert that bit-stream into a primitive of desired type. I.e. something like: char convert(const...
4
by: Eric Lilja | last post by:
Hello, I've made a templated class Option (a child of the abstract base class OptionBase) that stores an option name (in the form someoption=) and the value belonging to that option. The value is...
4
by: Rodusa | last post by:
I am having problem to apply updates into this function below. I tried using cursor for updates, etc. but no success. Sql server keeps telling me that I cannot execute insert or update from inside...
2
by: Bubba | last post by:
I know it's possible, just don't know how to do it. I have a spreadsheet that I imported into access. Two of the columns in the table have Hard Drive space values listed for example 2.45 GB and 453...
2
by: William Stacey | last post by:
Example line: string temp = Convert.ToString(null); Convert.ToString() says it will return empty string if null is passed as parm. This returns a null. Is this oversight in the Convert method?...
17
by: David Scemama | last post by:
Hi, I'm writing a program using VB.NET that needs to communicate with a DOS Pascal program than cannot be modified. The communication channel is through some file databases, and I have a huge...
7
by: patang | last post by:
I want to convert amount to words. Is there any funciton available? Example: $230.30 Two Hundred Thirty Dollars and 30/100
6
by: patang | last post by:
Could someone please tell me where am I supposed to put this code. Actually my project has two forms. I created a new module and have put the following code sent by someone. All the function...
4
by: Edwin Knoppert | last post by:
In my code i use the text from a textbox and convert it to a double value. I was using Convert.ToDouble() but i'm used to convert comma to dot. This way i can assure the text is correct. However...
4
by: dba_222 | last post by:
Dear Experts, Ok, I hate to ask such a seemingly dumb question, but I've already spent far too much time on this. More that I would care to admit. In Sql server, how do I simply change a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.