-
Re: you are all stupid, example for my problems, realtime video compression
'typedef struct {
' DWORD dwFlags; 'byval
' LPBITMAPINFOHEADER lpbiOutput; 'needs a pointer to a bitmapinfoheader
' LPVOID lpOutput; 'this i can handle with Global/Heap
memory function
' LPBITMAPINFOHEADER lpbiInput; 'needs a pointer to a bitmapinfoheader
' LPVOID lpInput; 'this i can handle with Global/Heap
memory function
' LPDWORD lpckid; 'not used now, but needs a ptr to a 2
byte array
' LPDWORD lpdwFlags; 'needs a pointer to vb long
' LONG lFrameNum; 'byval
' DWORD dwFrameSize;'byval
' DWORD dwQuality; 'byval
' LPBITMAPINFOHEADER lpbiPrev; 'needs a pointer to a bitmapinfoheader
' LPVOID lpPrev; 'this i can handle with Global/Heap
memory function
'} ICCOMPRESS;
make this work in VB.NET
Option Explicit
Private Type BITMAPINFOHEADER
biSize As Long
biWidth As Long
biHeight As Long
biPlanes As Integer
biBitCount As Integer
biCompression As Long
biSizeImage As Long
biXPelsPerMeter As Long
biYPelsPerMeter As Long
biClrUsed As Long
biClrImportant As Long
End Type
Private Type ICCompress
dwFlags As Long
lpbiOutput As Long
lpOutput As Long
lpbiInput As Long
lpInput As Long
lpckid As Long
lpdwFlags As Long
lFrameNum As Long
dwFrameSize As Long
dwQuality As Long
lpbiPrev As Long
lpPrev As Long
End Type
Private m_ICCompress as ICCompress
Private m_bmHdrTarget as BitmapInfoHeader
Private m_bmHdrCompressed as BitmapInfoHeader
Private m_ICCompressReturnFlag As Long
Sub Main
m_ICCompress.lpbiInput = VarPtr(m_bmHdrTarget)
m_ICCompress.lpbiOutput = VarPtr(m_bmHdrCompressed)
m_ICCompress.lpInput = m_lpBits
m_ICCompress.lpOutput = HeapAlloc(GetProcessHeap(), 0,
m_bmHdrCompressed.biSizeImage)
m_ICCompress.lpbiPrev = VarPtr(m_bmHdrTarget)
m_ICCompress.lpPrev = HeapAlloc(GetProcessHeap(), 0,
m_bmHdrPrevious.biSizeImage)
m_ICCompress.lpdwFlags = VarPtr(m_ICCompressReturnFlag)
Msgbox "I am really ****ed up because i cannot fill the ICCompress
Structure anymore", vbOKOnly + vbExclamation,"VB is dead"
End Sub
-
Re: you are all stupid, example for my problems, realtime video compression
OK, I'm sick of this crap.
Discussing something to learn about it is one thing, but discussing something
just to complain and be hard-headed is stupid.
Therefore, I will do YOUR homework for you and hopefully shut your whining
along with the others who are springboarding their complaints off your post.
Let's get some *facts* straight first.
The reason you can't use VarPtr is that in managed memory, the garbage collector
can come along and wipe unused memory, then shift variables around to compress
the unused space. This changes the address of a variable. OK, do you see
that now?
Next...
This does NOT mean you can't pass an address to unmanaged code (like C API
functions). But you must do one of two things:
1) Pin the variable so that the GC doesn't move it (you can only pin value
types, not objects)
2) If you can't pin, you must define a marshalling scheme. Marshalling tells
the compiler how to pass your managed data to unmanaged code. Sometimes you
must copy the data to an unmanaged memory block, then pass the address of
the unmanaged memory block to the API.
Got that so far? OK, let's move on...
If I have an Integer (Integers are 32-bit in VB.NET and replace Long in VB
6) called "X", and I want a pointer to X, then I can use the following, which
implements pinning:
Dim X as Integer = 255
Dim gh As GCHandle
' Create a GC Handle to X and Pin X in memory
gh = GCHandle.Alloc(X, GCHandleType.Pinned)
' Display the Address of X
messagebox.Show(Convert.ToString(gh.AddrOfPinnedObject()))
' Free the pinned handle
gh.Free()
MessageBox.Show("Do your homework and stop crying.", "VB is alive and well.",
MessageBox.IconInformation)
Using this method, you can obtain addresses for most of your variables. As
we already mentioned, there are certain things you can't pin. Instead, you
must marshal the data to unmanaged code. Sometimes, this means you must copy
the information to the unmanaged heap and pass a pointer to that unmanaged
memory. You can do this using the Marshal class, which incidently gives you
way more control of memory than VB6 ever did.
' Note that BitmapInfoHeader is already defined for you in .NET under
' the Microsoft.Win32.Interop namespace
Dim X As BITMAPINFOHEADER = New Microsoft.Win32.Interop.BitmapInfoHeader
Dim AddressOfX As Integer
AddressOfX = Marshal.AllocHGlobal(SizeOfX)
Marshal.StructToInt(StructureToPtr, AddressOfX, True)
m_ICCompress.lpbiInput = AddressOfX
So now you have two completely different ways of handling the scenario. And
I assure you there are more. For example, when you define a structure in
VB.NET, you can also define how the members are passed to unmanaged code
functions. I believe you can also do the following, though I haven't actually
tried it:
Friend Structure <StructLayout(LayoutKind.Sequential)> ICCOMPRESS
Friend dwFlags As Integer
Friend <MarshalAs(UnmanagedType.LPStruct)> lpbiOutput As BITMAPINFOHEADER
-
Re: you are all stupid, example for my problems, realtime video compression
Crap, looks like my prev post got chopped.
Ammend this to the last post:
-
Re: you are all stupid, example for my problems, realtime video compression
This allows you to use the lpbiOutput member directly in managed code, and
at the same time, pass a pointer to that structure when you pass ICCOMPRESS
to unmanaged code. At least, that's how I read it, I might be wrong. You
have far more flexibility with the <MarshalAs> attribute when you declare
API functions (as opposed to defining structures).
Let me dispell one HUGE myth of VB.NET right now:
While it's true that you can't create code that runs under unmanaged memory,
you *CAN* interact extremely well with unmanaged code (much better than VB6)
and you have far more control of unmanaged memory. People should be happy
about that. Instead, you all complain pointlessly.
Also, remember one other important thing:
The minute you revert to using unmanaged code and unmanaged memory, your
code will no longer be verifiable, meaning that it won't be able to run under
certain security contexts. However, your VB6 isn't verafiable either, in
case you want to complain about that.
Now then, let me get back to my original point:
In .NET, you can avoid many of the API pointer issues to begin with. You
have an Image class, and a Bitmap class that derives from it. You can do
all your standard image manipulation without using any API functions. Along
with the BitMapData class, you have all the information from the old BitmapInfoHeader
structure, and even more.
When you want to change image formats, you have Encoder and Decoder classes
that abstract CODECs among other things. There is a Compression Encoder class.
All this without ONE single API call.
The documentation is still a little weak in Beta 1 in respect to Encoding,
and I'll have to wait for Beta 2 before I see what's actually been implemented
for AVI files.
So once again:
Stop *****ing/complaining, and start reading/using. You'll look a lot less
stupid in the end, not to mention saving me the headaches.
-Rob
-
Re: you are all stupid, example for my problems, realtime video compression
On 10 Apr 2001 10:28:11 -0700, "Rob Teixeira" <RobTeixeira@@msn.com>
wrote:
>Stop *****ing/complaining, and start reading/using. You'll look a lot less
>stupid in the end, not to mention saving me the headaches.
You have the patience of a saint. I thought about replying but was so put
off by the tone of the post that I decided I wouldn't waste my time with
him. However, your post was informative and I'm sure others will profit
from it.
---
Ice Z - Straight Outta Redmond
-
Re: you are all stupid, example for my problems, realtime video compression
zane@mabry.com (Zane Thomas) wrote:
>
>You have the patience of a saint.
It only *looks* that way. I figured this was my choice:
a) completely deal with one issue, even if it's a pain
b) continue to hear whining for months to come
>I thought about replying but was so put
>off by the tone of the post that I decided I wouldn't waste my time with
>him.
That's precisly why I chose this issue to deal with. It was one of the worst
"problems" I'd seen, and the comlainer was worse than most. I figured if
I could put this one to rest, the others wouldn't look so bad.
>However, your post was informative and I'm sure others will profit
>from it.
Well I'll be...
Zane handed out a compliment!
I'm not picking on you or anything, but that doesn't happen very often 
-Rob
-
Re: you are all stupid, example for my problems, realtime video compression
On 10 Apr 2001 13:57:47 -0700, "Rob Teixeira" <RobTeixeira@@msn.com>
wrote:
>Zane handed out a compliment!
>I'm not picking on you or anything, but that doesn't happen very often 
Hahah, well my lofty standards prevent me from handing out compliments
casually. Consider yourself special. :-)
---
Ice Z - Straight Outta Redmond
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks