What kind of screen image do you want to capture? Like just an application window?
If so, can explain how to do it without DirectX also if you like.
Main Topics
Browse All Topics I will like to know, is it better to capture the screen image using directX or BitBlt when I want it to store in the memory? I was trying the directX way to do this but the lock call is failing. Can anyone suggest what is wrong there? I am giving the code snippet below.
LPDIRECTDRAW4 g_pDD = NULL; // DirectDraw object
LPDIRECTDRAWSURFACE4 g_pDDSPrimary = NULL;// DirectDraw primary surface
int WINAPI Winmain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmdLine, int nCmd){
DDSURFACEDESC2 ddsd;
HRESULT hRet;
LPDIRECTDRAW pDD;
if(DirectDrawCreate(NULL, &pDD, NULL) == DD_OK){
pDD->QueryInterface(IID_ID
g_pDD->SetCooperativeLevel
ZeroMemory(&ddsd, sizeof(ddsd));
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
g_pDD->CreateSurface(&ddsd
DDSURFACEDESC2 DDSurfaceDesc;
ZeroMemory(&DDSurfaceDesc,
DDSurfaceDesc.dwSize = sizeof(DDSURFACEDESC2);
hRet = g_pDDSPrimary->Lock(NULL, &DDSurfaceDesc, DDLOCK_SURFACEMEMORYPTR, NULL); //FAILING??????????
if(hRet == DD_OK){
//how to proceed here ??????????????????????????
g_pDDSPrimary->UnLock()
}
else
retrurn FALSE; //Lock has failed
}
I have tried by assigning the various parameters with no success. Can anyone help me getting out of the problem.
Thanks,
Sachin
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
n8shadow I will try with the suggestions given by you today.
_corey_ I want to capture the given part of the screen periodically. Currently I am using BitBlt for that. I wanted to know if DirectX will be a better option(efficient with respect to time) for this or not. Am I using the right approach in my sample code? If yes, what is the problem there and if no then what is the correct approach.
Thanks,
Sachin
Storing to memory? not processing and then to file? BitBlt is actually decently fast. I don't know how much of an improvement DirectX would give vs coding complexity. I have not used it in that fasion before.
However, with DirectX you might get the different devices/surfaces in that area of the screen easier. I'm not sure what's going to be in that screen location.
I wish to see how n8's settings suggestion works out.
n8 even the flags suggested by you are not working. When I try with FAILED macro it returns failure. When I get the return value, it goes to the default statement in switch. I am checking for DD_OK, DDERR_INVALIDPARAMS, DDERR_INVALIDOBJECT, DDERR_SURFACEBUSY, DDERR_SURFACELOST, DDERR_WASSTILLDRAWING, DDERR_OUTOFMEMORY.
corey, I am not storing it in files. All are the memory processing only.
Business Accounts
Answer for Membership
by: n8shadowPosted on 2003-10-03 at 02:57:10ID: 9483473
maybe you can post the dx-errorcode from your failed lock.
an first suggestion is to use another lock flags. i lock my surfaces with the following:
DDLOCK_WAIT | DDLOCK_NOSYSLOCK | DDLOCK_SURFACEMEMORYPTR
where i had never problems.