|
I dont think you need to delete pDest ... only SafeArrayUnaccessData and SafeArrayDestroy is sufficient. Please correct me if I am mistaking ... Hope this helps.
- tareq
|
|
|
|
|
hi frnds..
i got the code for SCREEN CAPTURE..Its working well..
now wat i need is HOW TO TRANSFER THAT CODE TO SOME OTHER MACHINE IN A LAN..
so plz frnds if u any cdoe for that send me..or if u have any suggestion plz tell me..
i will be looking forward for ur replies..
thank u
with luv
kar
Karmegakumar.A B.Tech IT
Amrita Institutions
Coimbatore
|
|
|
|
|
Look at the code below you can get the CxImage class from An article from Davide Pizzolato. Use some Transfer function to transfer the buffer to the client and decode the image and show it.
BYTE* MyIOCP::GetJPGCompressedDesktopCapture(UINT &nArraySize, int nWidth, int nHeight, BYTE nquality)
{
// get the desired window from dialog box
HWND hwnd=::GetDesktopWindow();
// get window size
CRect r;
::GetWindowRect(hwnd,&r);
int nX, nY, nX2, nY2; // coordinates of rectangle to grab
int xScrn, yScrn; // screen resolution
nArraySize=-1;
BYTE* retbuffer=NULL;
// prepare the DCs
HDC dstDC = ::GetDC(NULL);
HDC srcDC = ::GetWindowDC(hwnd); //full window (::GetDC(hwnd); = clientarea)
HDC memDC = ::CreateCompatibleDC(dstDC);
nX = r.left;
nY = r.top;
nX2 = r.right;
nY2 = r.bottom;
// get screen resolution
xScrn = GetDeviceCaps(srcDC, HORZRES);
yScrn = GetDeviceCaps(srcDC, VERTRES);
//make sure bitmap rectangle is visible
if (nX < 0)
nX = 0;
if (nY < 0)
nY = 0;
if (nX2 > xScrn)
nX2 = xScrn;
if (nY2 > yScrn)
nY2 = yScrn;
// nWidth = nX2 - nX;
// nHeight = nY2 - nY;
// create a bitmap compatible with the screen DC
HBITMAP bm =::CreateCompatibleBitmap(dstDC, nWidth, nHeight);
HBITMAP oldbm = (HBITMAP)::SelectObject(memDC,bm);
// copy the screen and resize to the bitmap
//TRACE("%i,%i",nWidth,nHeight);
// Set Correct Stretchmode
::SetStretchBltMode(memDC,HALFTONE);
::StretchBlt(memDC,0,0,nWidth,nHeight,srcDC,nX,nY,nX2,nY2,SRCCOPY);
//::BitBlt(memDC, 0, 0, nWidth, nHeight, srcDC, nX,nY , SRCCOPY);
// Create a JPG image From the bitmap..
CxImage newimage(CXIMAGE_FORMAT_JPG);
newimage.CreateFromHBITMAP(bm);
// free objects
DeleteObject(SelectObject(memDC,oldbm));
DeleteObject(memDC);
// Encode the image to the memory
CxMemFile MemFile;
//newimage.SetCodecOption(0x10,CXIMAGE_FORMAT_JPG);
// Change so that we dont have a transparent background.
newimage.SetTransIndex(-1);
// If Color change it to 24 bit bitmap.
if (!newimage.IsGrayScale())
newimage.IncreaseBpp(24);
newimage.SetJpegQuality(nquality);
MemFile.Open();
// You have to encode and decode it to compress it in reality.
// ?? Very very strange..
BOOL bRet=FALSE;
if(newimage.Encode(&MemFile,CXIMAGE_FORMAT_JPG))
{
if(MemFile.Seek(0,SEEK_SET))
bRet=newimage.Decode(&MemFile,CXIMAGE_FORMAT_JPG);
}
nArraySize=(UINT)MemFile.Size();
if(bRet)
retbuffer=MemFile.GetBuffer();
// Close & Clean up
MemFile.Close();
newimage.Destroy();
return retbuffer;
}
|
|
|
|
|
Hi. I am having problems with deleting objects from a CObArray not freeing up the memory.
NB: The code has been simplified to show only the key points.
In the header
class CBelFileDetails : public CObject
{
public:
CBelFileDetails ()
{
};
~CBelFileDetails () {};
};
In the Implementation
void RemoveArray (CObArray *pA)
{
int j, Count;
Count = pA -> GetSize ();
for (j = 0; j < Count; j++)
{
CObject* P = pA -> GetAt (j);
if (P)
{
TRY
{
delete P;
P = NULL;
}
CATCH_ALL (e)
{
e->ReportError ();
}
END_CATCH_ALL
}
}
pA -> RemoveAll ();
}
void CMainFrame::OnTimer(UINT nIDEvent)
{
int j;
CObArray FileDetailsArray;
for (j = 0; j < NumOfFiles; j++)
{
CBelFileDetails *pFD = new CBelFileDetails ();
FileDetailsArray.Add (pFD);
}
RemoveArray (&FileDetailsArray);
}
The problem is, if I watch the 'Mem Usage' in TaskManager it forever goes up. As if the memory is not being released. I run it in debug mode, and same thing happens. But when I close the application, no memory leaks are reported.
I am wondering if any of you have encountered the same problem and if so, how did you fix it?
|
|
|
|
|
Have you stepped through this code to see if it does what you expect ?
I've never used CObjArray, so I can't comment directly. The Microsoft containers were only provided as a stopgap until the STL arrived. You really should just use a vector. You'd still have to delete pointers held in it, but you could easily write a functor and use for_each to do so.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
I've walked through the code and it 'works' perfectly. The problem seems (well to me at least and a fellow workmate) that the problem is when I call delete . I watched the memory using the Visual C++ Memory debug window, and it all got killed to EE EF's as if the object was deleted fine. But in taskmanager, the mem usage did not shrink.
|
|
|
|
|
I am attempting to use GetOpenFileName from a service on W2K and WXP. The service is set to interact with the desktop. The problem is that when the open dialog appears and the user selects the "Desktop" icon on the left panel of the open file dialog, it complains about "C:\Documents and Settings\LocalSystem\desktop" not existing. Note the "LocalDesktop" in that string. I want it to be the name of the current user.
So, how do I tell GetOpenFileName to use the currently logged-on user's context when using the open file dialog? Do I need to impersonate the logged-on user before calling GetOpenFileName? If so, how do I do impersonation WITHOUT asking for user credentials?
Some rudimentary example will suffice, you don't have to right the whole she-bang.
Thank you in advance.
ahz
|
|
|
|
|
After some research, I answered my own question:
OPENFILENAME op;
ZeroMemory(&op, sizeof(op));
op.lStructSize = sizeof(op);
op.hwndOwner = m_hWnd;
op.lpstrFilter = L"JavaScript Files (*.js)\0*.js\0VBScript Files (*.vbs)\0*.vbs\0All Files (*.*)\0*.*\0\0\0";
op.lpstrFile = m_wsFilePathBuf;
op.nMaxFile = cPathSize;
op.lpstrFileTitle = m_wsFileNameBuf;
op.nMaxFileTitle = cNameSize;
op.lpstrTitle = title.Length() ? title : L"Product Name Title";
op.Flags = OFN_DONTADDTORECENT | OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_ENABLESIZING | OFN_EXPLORER | OFN_HIDEREADONLY;
bool impersonated = false;
DWORD processID;
if (ProcessIsRunning(L"someuserprocess.exe", processID))
{
HANDLE processHandle;
HANDLE token = 0, duptoken = 0;
BOOL result;
DWORD size = 0;
processHandle = ::OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_DUP_HANDLE, FALSE,processID);
result = ::OpenProcessToken(processHandle, TOKEN_QUERY | TOKEN_IMPERSONATE | TOKEN_DUPLICATE, &token);
result = result ? ::DuplicateToken(token, SecurityImpersonation, &duptoken) : FALSE;
impersonated = (result ? ::ImpersonateLoggedOnUser(duptoken) : FALSE) == TRUE;
}
BOOL result = GetOpenFileName(&op);
if (impersonated)
{
RevertToSelf();
impersonated = false;
}
|
|
|
|
|
Thanks for your sharing...
I studied more by this issue.
thanks very much ,i will remember this.
but do you have msn acount?
You are the best!Me too!
|
|
|
|
|
Good solution, just remember to close your handles when you're done. Also, a couple of points...- What if there is no user running the process you're checking for?
- What if more than one user is running the process you're checking for? Do you use the right one?
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Ryan Binns wrote:
Good solution, just remember to close your handles when you're done.
yes, caught that and did it.
Also, a couple of points...
What if there is no user running the process you're checking for?
First, in the product I'm developing is an endpoint security product, so if the process queried is not running, the product considers that a fatal error and causes user's machine to reboot.
What if more than one user is running the process you're checking for? Do you use the right one?
Second the product I'm developing is not supported on FUS or TSERVER or CITRIX metaframe. wouldn't make sense in those environments.
Thanks for the comments.
|
|
|
|
|
i know this is easy, but i can't find or remember it right now....
my program is whatever.exe. from inside that program, how can i get the full path that this exe is running?
so, something that returns c:\program files\....\whatever.exe
Any ideas? my brain and search skills appear to be shot tonight...
Thanks!
Marcus Spitzmiller
"Why must life be so hard? Why must I fail at every attempt at masonry?" - Homer
|
|
|
|
|
Pretty sure this is in the FAQ
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
yeah - you were right. thanks for the info.
Marcus Spitzmiller
"Why must life be so hard? Why must I fail at every attempt at masonry?" - Homer
|
|
|
|
|
have you tried :
GetModuleFileNameEx(GetCurrentProcess(),GetModuleHandle(0),szExe,sizeof(szExe));
or GetFilePath() function which requires the handle of the file .
gabby
|
|
|
|
|
I'm trying to implement mergesort in C++ but I've grown blind to my code and can't seem to spot the error. It sorts my vector partly, but not entirely. Anyway here's the relevant code:
<br />
void merge_sort( std::vector<int> &d, int lb, int ub )<br />
{<br />
if( lb < ub )<br />
{<br />
int q = ( lb + ub ) / 2;<br />
merge_sort( d, lb, q );<br />
merge_sort( d, q + 1, ub );<br />
merge( d, lb, q, ub );<br />
}<br />
}<br />
void merge( std::vector<int> &d, int lb, int sp, int ub )<br />
{<br />
int l1 = sp - lb;<br />
int l2 = ub - sp;<br />
std::vector<int> vL(d.begin() + lb ,d.begin() + lb + l1);<br />
std::vector<int> vR(d.begin() + sp , d.begin() + sp + l2);<br />
<br />
<br />
vL.push_back(INT_MAX);<br />
vR.push_back(INT_MAX);<br />
int i = 0;<br />
int j = 0;<br />
for( int k = lb; k < ub; k++ )<br />
{<br />
if( vL[i] < vR[j] )<br />
d[k] = vL[i++];<br />
else <br />
d[k] = vR[j++];<br />
}<br />
}<br />
<br />
Any help appriciated
|
|
|
|
|
I would like to call methods that are written in visual c++ 6.0 from the .NET environment.
If you know how to do this, please explain in the most simple way.
And if you can also send me a sample I will be glad and thankful!
thanks in advance
sheli
|
|
|
|
|
|
I am running my application and expecting its main frame to come up. However, it does not come up and when I try to step through the code, it comes to a stop at CMainFrame* pMainFrame = new CMainFrame and will not let me step any further. Therefore, it doesn't get to call the code to bring up the main frame. Any ideas why it has stopped at the creation of pMainFrame??
|
|
|
|
|
Take a look at CMainFrame's constructor. Is there an infinite loop?
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
I've got a bit of trouble figuring out the proper way to include classes and headers. Now as I've always been taught, you should type out a class declaration in a header file and leave the definition for the cpp file. Then when that's completed, you should only #include header files. That's the "etiquette" I've been taught anyway so that's what I'm employing here. Though I'm beginning to think some of my professors who cling to that are rather daft.
Now on to the problem. I have Class A that is required for Class B. Now Classes C and D both require Class B. Class E requires Classes A and C. Finally Class F requires D and E. Lost you yet? Maybe this will help:
Class A
/ \
Class B \
| \ \
Cls D Cls C |
| \ |
\ Class E
\ /
Class F
Now each individual cpp compiles lovely, the problem comes when linking. The errors always point to Class A so I'm pretty sure that it's getting included twice somehow. I'm using blocks like this at all include points, on cpp and h files, to try to keep something from including twice:
#ifndef CLASS_A_INC<br />
#define CLASS_A_INC<br />
#include "CLASS_A.h"<br />
#endif
Despite all this I can't get the linking errors to go away. Help please?
The question "Do computers think?" is the same as "Can submarines swim?"
Signature Red Studios
Jeryth
|
|
|
|
|
At the top of each .h file should be something along the lines of:
#if !defined(AFX_<code>filenamehere</code>_H__E944DC11_3852_4390_BA89_40C4B5867CB2__INCLUDED_)
#define AFX_<code>filenamehere</code>_H__E944DC11_3852_4390_BA89_40C4B5867CB2__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#endif
Jeryth wrote:
The question "Do computers think?" is the same as "Can submarines swim?"
The correct quote is from Dijkstra:
"The question of whether computers can think is like the question of whether submarines can swim."
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
DavidCrow wrote:
The correct quote is from Dijkstra:
"The question of whether computers can think is like the question of whether submarines can swim."
I know where it comes from, I just didn't care to type the whole thing. But you're the first to recognize it, at least the first to comment.
Anyway, I didn't catch all that code you typed. Looked up the pragma pre-processor keyword and understand that coupled with the "once". That is I understand the point of it but not necessarily the implementation. Mind explaining it a bit?
I take it _MSC_VER is built in, correct? As for the defining tags, does that whole line of AFX_blah_blah_blah have to be there or can it be my own tag?
The question "Do computers think?" is the same as "Can submarines swim?"
Signature Red Studios
Jeryth
|
|
|
|
|
I might give a shot at an explanation.
#pragma once (according to MSDN) instructs the compiler to include the header file only once in the compilation. This works from VC++ version 4 (I'm not sure about this, but VC++6.0 has _MSC_VER=1200, so I guess 5.0 is 1100 and 4.0 is 1000). If you use VC++ 6.0 then _MSC_VER is 1200 and #pragma once should be sufficient for you. You just have to put #pragma once in ALL your header files (and only the header files).
All AppWizard-generated MFC projects come with header files that looks like this:
<br />
<br />
#if !defined(AFX_EX2_H__9190AD6B_F3D4_4DC8_B8DF_C4F8460B0306__INCLUDED_)<br />
#define AFX_EX2_H__9190AD6B_F3D4_4DC8_B8DF_C4F8460B0306__INCLUDED_<br />
<br />
#if _MSC_VER > 1000<br />
#pragma once<br />
#endif // _MSC_VER > 1000<br />
<br />
......<br />
<br />
#endif // !defined(AFX_EX2_H__9190AD6B_F3D4_4DC8_B8DF_C4F8460B0306__INCLUDED_)<br />
The #if - #define - #endif constructs implements the same idea as you do with your "own tags", but here the whole header file text is surrounded by the #if/#endif statements. I really can't see why that should be much different from putting #if/#endif around the #include statements instead, but maybe that's why it doesn't work for you. Anyway, as I see it the #if/#endif is redundant to #pragma once. In any event, the AFX_blah_blah_blah is just MFC's way of making a unique tag (AFX + filename + guid), if your tags are unique then they should work equally well.
Are you absolutely sure that your problems stems from multiple inclusions of the classA header? You can trace the parsing of your header files by putting a #pragma message (see MSDN) in the header file.
Cheers
Steen.
"To claim that computer games influence children is ridiculous. If Pacman had influenced children born in the 80'ies we would see a lot of youngsters running around in dark rooms eating pills while listening to monotonous music"
|
|
|
|
|
Steen Krogsgaard wrote:
Are you absolutely sure that your problems stems from multiple inclusions of the classA header?
I'll say I'm 95% sure that's the cause. All the linking errors mentioned Class A name in the error field. But now I have a new problem. I took Dave Crow's advice and redid my #ifndef statements. Now I'm testing in the class header file if an appropriate preprocessor tag has been defined, if not then it defines it and it continues to have the class declared. If it already has, it skips it. After the initial #ifndef I use separate ones to test for any required includes for that class. For example, Class A looks like this:
<br />
#ifndef CLASS_B_INC<br />
#define CLASS_B_INC<br />
#pragma once<br />
<br />
#ifndef CLASS_A_INC<br />
#include "CLASS_A.h"<br />
#endif<br />
<br />
<br />
#endif<br />
I think part of my problem was that I was possibly defining the pre-processor tags multiple times. This way, they only get defined in that class' header file. Note here that Class B won't try to define CLASS_A_INC ( that's left to Class A to do ) it will just include it and when that does Class A will define it on its own.
Now something like that written above is in all .h files. The .cpp files only have
<br />
#ifndef CLASS_A_INC<br />
#include "CLASS_A.h"<br />
#endif<br />
for their own classes, so above would be the Class A .cpp file. Now I'm getting errors that certain elements can't be found such as "cout : undeclared identifier" and "Class E : undeclared identifier" so some of my #include statements aren't being processed and I don't know why.
________________________________________________________________________
The question "Do computers think?" is the same as "Can submarines swim?"
Signature Red Studios
Jeryth
|
|
|
|
|