473,661 Members | 2,421 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_COOKI E As Short = 19778

Private Structure BITMAPFILEHEADE R '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 BITMAPINFOHEADE R '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.d ll" () As Integer
'handle

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

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

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

Private Const HEAP_ZERO_MEMOR Y As Integer = &H8S

Private m_memBits() As Byte
Private m_memBitmapInfo () As Byte
Private m_bih As BITMAPINFOHEADE R
Private m_bfh As BITMAPFILEHEADE R
'FUNCTION
Public Function CreateFromPacke dDIBPointer(ByR ef 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 BitmapInfoHeade r

Call CopyMemory(ByVa l VarPtr(m_bih.bi Size), ByVal pDIB, Len(m_bih))
If m_bih.biBitCoun t < 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.biSizeIma ge < 1 Then Exit Function 'return False
ReDim m_memBits(0 To m_bih.biSizeIma ge - 1)
Call CopyMemory(m_me mBits(0), ByVal pDIB + 40, m_bih.biSizeIma ge)

'and BitmapInfo variable-length UDT

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

'create a file header
With m_bfh
.bfType = BMP_MAGIC_COOKI E
.bfSize = 55 + m_bih.biSizeIma ge 'size of file as written to disk
.bfReserved1 = 0&
.bfReserved2 = 0&
.bfOffBits = 54 'BitmapInfoHead er + BitmapFileHeade r
End With

'and return True
CreateFromPacke dDIBPointer = True

End Function
Aug 27 '06 #1
4 4557
"Joao Tomas" <xx@xx.comwro te 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**********@r ogers.comwrote in message
news:Xn******** *************** ***********@127 .0.0.1...
"Joao Tomas" <xx@xx.comwro te 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**********@r ogers.comwrote in message
news:Xn******* *************** ************@12 7.0.0.1...
>"Joao Tomas" <xx@xx.comwro te 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.d ll" Alias "RtlMoveMem ory" _
(ByVal Destination As Byte(), ByVal Source As Int32, ByVal Length As Int32)

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

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

CopyMemory(bBlo b, bData, bSize)

GlobalUnlock(bD ata)
GlobalFree(bDat a)

Gene
Aug 28 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2515
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 unsigned char* buffer, size_t start_pos, size_t length) { char value = 0;
4
3619
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 of the type the object is instantiated with. In my test program I have Option<std::string> and Option<long>. Here's the code for OptionBase and Option along with a small helper function. In the code are comments describing my problem, look closely...
4
9260
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 a function and it gives me an option that I could write an extended stored procedure, but I don't have a clue of how to do it. To quickly fix the problem the only solution left in my case is to convert this recursive function into one recursive...
2
15860
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 MB, you get the picture. Both the GB and MB assorted values exist in both columns. Is there anyway to convert the GB or MB to 0's, or even better yet decimal places so I can look for values < or > to 6gb. I already tried a query, but it seems...
2
18480
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? What is the way you guys are checking for nulls on string parms and triming if they pass something other then null. I was thinking this would do in most cases, but does not because of "error above"
17
4361
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 problem writing VB Double values to the file so as the Pascal program can read them as Pascal Real values. I've managed to find the algorithm to read the Pascal Real format and convert it to a VB Double, but I cannot figure out the opposite...
7
29223
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
1407
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 declaration statments (first lines) e.g. Public Function ConvertCurrencyToEnglish(ByVal MyNumber As Double) As String Private Function ConvertHundreds(ByVal MyNumber As String) As String etc.
4
4514
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 it seems this convert is determined by the local settings and comma is indeed used as decimal separator. Is there another way to convert a dotted value to a double variable? Like 1234.5 and not 1234,5
4
118807
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 character into a number?????? In Oracle, it is:
0
8341
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8754
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7362
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6181
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5650
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4177
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4343
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2760
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.