Solved

How do I read video-memory under Windows ?

Posted on 2002-05-23
20
202 Views
Last Modified: 2010-04-02
Hello,

I have just a simple question:

I would like to do FAST screen-captures under Windows.
Therefore I need access directly to the video-ram to
get frame buffer data quickly.

Can you please let me know how that can be done
both on Win9x and WinNT/2000/XP  ?

Thank you VERY much for your help !

Reinhard
0
Comment
Question by:rhoepperger
  • 7
  • 5
  • 5
  • +2
20 Comments
 
LVL 86

Expert Comment

by:jkr
Comment Utility
Unfortunately, you can't - access to the video card is restricted to device drivers...
0
 
LVL 3

Expert Comment

by:Crius
Comment Utility
Well, the fastest way to access video memory is to use DirectX. It'll work on all platforms, but it'll be a lot faster on Win9x and WinXP than it will on WinNT and 2000.

It might be worth detecting the OS, and if it's an NT based system, do a BitBlt SRCCOPY of the entire screen into a bitmap. You can't get much faster than that, and it's pretty simple too...

A third solution, though more complicated is to simulate the Print Scrn key being hit, then access the clipboard and drag the contents out into a bitmap...

I don't know which of these 3 methods would be fastest though.
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 100 total points
Comment Utility
Capturing a screen image using simple/normal bitblt is virtually instantaneous.

Your post-processing, and/or file-creation and/or data transfer is going to be the bottleneck.  

-- Dan
0
 
LVL 8

Expert Comment

by:fl0yd
Comment Utility
@Crius:
Could you please tell us where you got the information that DirectX is so much faster on win9x and xp than on winnt and 2k? As far as I know, win2k is winnt 5.0 and winxp is winnt 5.01
To those that do care about actual knowledge versus those that like to believe: a BitBlt does use the fastest method available on ALL systems.
I know, you only wanted to help. But please, make sure you know what you're talking about when helping out next time...
0
 

Author Comment

by:rhoepperger
Comment Utility
Thanks a lot everybody.  BitBlt is fairly easy to use and if you say there's no faster method, I'll accept that gracefully :)

Thanks for your help !
Reinhard
0
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
>>and if you say there's no faster method, I'll accept that gracefully :)

Thanks for the points.
However, I did *not* say that there's no faster method.

My point was that, lacking a detailed description of the reason why you want the fast screen captures, it is very likely that any speed differential gained by using some exotic technique is likely to be lost in the noise of processing and handling the image data.

-- Dan
0
 
LVL 3

Expert Comment

by:Crius
Comment Utility
I know BitBlt is *about* the fastest you can get. I mentioned that. If you are just taking a single screenshot, BitBlt is the fastest because it requires no loading/initialization. If you are doing constant screen shots, or painting, DirectX is actually faster because it avoids the GDI (which is slow in comparison) and *has* direct access to hardware on Win9X and WinXP systems.

If it were true that BitBlt were always the fastest way to access video memory on any system, we would we have DirectX at all. Why was DirectX made (DirectDraw specifically)? DirectX is based in direct access to hardware, whereas a BitBlt uses the GDI, and views things through a device context.

The reason DirectX is slower on WinNT and Win2000 is because neither WinNT nor Win2000 allow direct access to hardware. So, directX running on either of those system is *not* allowed to access the hardware directly either, and basically tricks the software trying to use DirectX into *thinking* it has direct access to hardware, when it actually doesn't.
0
 
LVL 3

Expert Comment

by:Crius
Comment Utility
I guess I didn't answer the question of how I know. If you are really interested, I've been making DirectX apps for a few years now, and tested and used them on Win95, WinNT, Win2000, and WinXP. In fact, I currently code on a WinXP system. I know WinNT and Win2000 don't allow direct access to the hardware, because that's how they were designed to work. That's why WinNT and Win2000 are considered such stable OSes - because they don't allow direct access.

Win9X systems do allow direct access, and very strangely, WinXP does too. I admit that I do not understand *how* WinXP is allowing the direct access to hardware - I have heard that it was based on WinNT code too, but I *know* it does. Run any DirectX program and check the framerate.

In fact, a framerate checker running on any OS will tell you the relative speeds if you want an easy way to find out.

Let me know if it turns out I'm wrong. I'd be *very* interested.
0
 

Author Comment

by:rhoepperger
Comment Utility
Crius, thank you for your answer too.
An additional question:

If I managed to write a device-driver for NT/2K/XP (which is no easy task :)) ), would that driver have direct access to video-ram ?  Or is this something exclusively reserved for the kernel ?  

0
 
LVL 3

Expert Comment

by:Crius
Comment Utility
Yes, a device driver, naturally, has direct hardware access to the device. That is the purpose of the device driver.

The device driver communicates with the hardware, and translates calls from the device into a standard format that is understood by whatever is making the calls to the device driver.
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

Author Comment

by:rhoepperger
Comment Utility
Crius, thank you for your answer too.
An additional question:

If I managed to write a device-driver for NT/2K/XP (which is no easy task :)) ), would that driver have direct access to video-ram ?  Or is this something exclusively reserved for the kernel ?  

0
 
LVL 8

Expert Comment

by:fl0yd
Comment Utility
@ rhoepperger:
Code in any device driver has ring-0-access, i.e. you *CAN* do anything you want. Access chipset-features, any pci-card, any agp-card, privileged cpu commands. In short, you can access almost any piece of hardware there is in your computer. And, yes, you can directly access video-ram. Now for the bad news, you'd have to write a driver for nvidia's tnt, one for tnt2, one for the geforce256, one for ati radeon, one for matrox g400, .... You'd have to write different code to access video-ram for every card there is.
@ Crius:
When you did your 'benchmarking' did you make abolutely sure that you were comparing apples to apples? Also, you never answered the question as to where you got the information that dx is slower/faster on whatever os. Did the info-provider's paper have some sort of ms-logo on it? And please read my profile if you need to put my postings into perspective.
0
 
LVL 8

Expert Comment

by:fl0yd
Comment Utility
@ Crius:
p.s.: While BitBlt *WILL* take the DirectX-codepath even on win2k-systems as does most of the GDI, there is still reason to have DirectX. First of all, DirectX doesn't allow you, as the programmer, to access the hardware directly. No, not even on win9x-systems. It is solely a hardware-abstraction-layer [i'm sure you've heard this one before] that gives you the possibility to take advantage of hardware features in a homogenous fashion. Don't get this mixed up.
0
 
LVL 3

Expert Comment

by:Crius
Comment Utility
It seems you are most concerned with direct hardware access/speeds on the different various OSes, so I hopped onto the web to look for proof of what I am saying.

It seems you may be right about Windows XP not allowing direct access to hardware too. Maybe DirectX, having been integrated directly into XP does something to get around it. I don't know enough about XP to prove or disprove it one way or another, except that from personal experience, and the mutterings I hear from  fellow programmers, that somehow DirectX on XP does have direct hardware access.

Here are a couple sites that showed up in google when I asked for: windows access hardware direct


http://www.cnet.com/software/0-6688749-8-7004399-8.html
http://searchwin2000.techtarget.com/tip/1,289483,sid1_gci812237,00.html

0
 
LVL 8

Expert Comment

by:fl0yd
Comment Utility
@ Crius:
Thanks for the url's, they are absolutely unrelated... And of course I'm right about XP since it *IS* WinNT v5 just like Win2k is and thus uses the WDM.
Since you don't seem to get it: DirectX does *NOT* access hardware directly. Period. Drivers do, that's for sure, and DirectX accesses those, but never ever has DX touched a piece of hardware.
So until you get me an url - preferably a sublevel-domain of microsoft.com - that clearly states that DirectX sucks on win2k and why it does so I'll just have to call it an opinion.
0
 
LVL 3

Expert Comment

by:Crius
Comment Utility
I have now searched the internet for benchmarks and information regarding the speed of DirectX on various operating systems, and have come up with a total blank. I'm trying to be as polite as possible with you Floyd, and it feels like you are being quite rude to me in return. Please provide URLs that prove your point since I seem unable to. I am willing to admit I'm wrong, but I'd like to read a place, preferable a microsoft web site, where it says DirectX runs just as fast/well on Win2000 and WinNT.

I do know that DirectX 3.0A is the last version supported by WinNT, and thus is likely the slowest OS DirectX runs on since it can't make use of new features/speed improvements in newer versions:
http://www.microsoft.com/windows/directx/productinfo/overview/faq.asp

And, from what I did find on the web, it seems versions before DirectX 8.1 did run fairly poorly on Win2000 machines. It may be just that Win2000 was so new, proper drivers were not provided with the OS.

I'm trying here, and a lot of my information I did hear from other programmers/people who work/are around me. They may not be correct, so I'd like to find out. My roommate who works at Dell in fact told me that the Win2000 version of DirectX was a neutered version that didn't have access to the drivers.

Yes, I do understand DirectX does not directly access the hardware itself. I have gotten used to saying access the hardware when I mean access the drivers - a problem on my part. DirectX would be a device driver otherwise, which it is not. Give me some credit here, and some mutual respect as a programmer would be nice too.
0
 
LVL 8

Expert Comment

by:fl0yd
Comment Utility
Mutual respect as a programmer is a fair demand. However, I need to see that you are someone that deserves to be called a programmer. Don't get this wrong, I don't know you, so there is no reason for me to just take your word for it -- I've seen too many people who think of themselves as programmers; yet mostly those that felt they weren't good at programming actually were *REAL* programmers. That's just my experience, though.
As for DX on win2k: I've been using win2k ever since rc2 and didn't find that DX was noticably slower than on win9x systems. Still using DX7 at the time, maybe even DX6, don't remember. Bare in mind though, that WDM did give some of the big names in the business a hard time. ATI's drivers for win2k sucked big time and they still do to this day. On the other hand, nVidia did have great drivers for win2k ever since their first release. Believe it or not, it's mainly the quality of drivers that makes DX run fast or slow.
Now on to the next point: You're view as to what WinNT is, is very narrow minded. You are unwilling to see that WinNT didn't die after version 4.0. It's still alive and better known as Win2K and WinXP. Although there are quite some improvements in win2k and xp over winnt4.0 the underlying architecture wasn't changed all that much. For one thing, the driver-model didn't change a lot.
Next, why do you want me to prove my point? Weren't you the one that did throw in some statements into the whole debate without ever thinking about proving them. Weren't those the 'i heard from fellow programmers'-type? Nevertheless, I will tell you why I'm all that sure about what I'm saying. In the games industry customers aren't about half as forgiving as in any other field of the consumer software market. That's why we NEED to be sure about the experience any given hardware-software-combination will be able to deliver. Thus we did do a lot of PROPER benchmarking, i.e. using drivers that were derived from the same code-base to check what's going on across different OS's. I doubt that you have the same possibilities when talking to hardware manufacturers.
About the DX-Version within win2k not having access to drivers altogether: How in the world is it supposed to be a HAL if it can't access drivers?!? And what is it connected to at the 'other end'? I don't mean to insult your roommate, but we have a lot of hardware from Dell, so I'm used to talking to them on the phone. All in all they don't seem to know all that much about what they are saying. Could be the wrong department, the wrong time of calling or just the wrong person I was talking to. But getting viable information that is correct down to the detail seems to be impossible with Dell.
I hope I have clarified things. My apologies if I did sound rude or impolite. That just happens if I read stuff that seems so inaccurate -- I'll try to watch my temper next time though.
0
 
LVL 3

Expert Comment

by:Crius
Comment Utility
I stand corrected then. The "other end" I always figured DirectX connected to on NT based systems was the GDI, although I never knew for certain.

My testing was actually done with an nVidia TNT2 model 64 card that performed quite poorly, but it does sound like you've tested a lot more combinations.

I admit, I had formed my opinion based on what other programmers have told me, mainly because they knew more about their specific fields than I figured I did. Nothing wrong there - I do it all the time. Being able to contact the people who wrote DirectX was not an available option for me.

I have programmed in DirectX for a few years, but that doesn't impart a whole lot of knowledge about the inner workings of DirectX.

Thank you then for pointing out my mistake. :) I will correct my opinion for the future since I couldn't actually find any information supporting my previous opinion when pressed about it, and I really should have found someone somewhere whining about DirectX and Win2000 if there really was an issue.

I don't know you either, but if you say you've benchmarked and tested, and you are sure, I'll believe you.
0
 

Author Comment

by:rhoepperger
Comment Utility
Thank you folks for your discussion. Even if it was a hot one occasionally, I still think I learned from it.

As writing a device-driver will probably not be an option for me I will look into the DirectX path or simply stick with the simple BitBlt-solution.  

As Dan pointed out earlier, the actuall screen-capture will not be the bottleneck as I need to transfer the data anyway.

Thank you all for helping me with my problem !

Reinhard
0
 

Author Comment

by:rhoepperger
Comment Utility
Thank you folks for your discussion. Even if it was a hot one occasionally, I still think I learned from it.

As writing a device-driver will probably not be an option for me I will look into the DirectX path or simply stick with the simple BitBlt-solution.  

As Dan pointed out earlier, the actuall screen-capture will not be the bottleneck as I need to transfer the data anyway.

Thank you all for helping me with my problem !

Reinhard
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now