|
use CreateThread instead of AfxBeginThread
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and you
|
|
|
|
|
are you sure that you working on MFC application!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and you
|
|
|
|
|
Hello,
I have a c++ application that I develop. I use Performance Counters in order to check its system usage. The HANDLES used are continuously increasing when I perform the following operations:
Open file – using fopen (I always close the files with fclose)
String operations – using standard c functions like strcmp, sprintf and so on
If anyone can point me a good article or solution (to check why the handles are increasing) I would highly appreciate it.
Thanks.
|
|
|
|
|
Hi all,
I want to create a bitmap by the function CreateDIBSection, and share the bitmap with other process.
HBITMAP CreateDIBSection(
HDC hdc, // handle to DC
CONST BITMAPINFO *pbmi, // bitmap data
UINT iUsage, // data type indicator
VOID **ppvBits, // bit values
HANDLE hSection, // handle to file mapping object
DWORD dwOffset // offset to bitmap bit values
);
Following MSDN, hSection is handle that created by CreateFileMapping.
Now I want ask that: in the shared-memory that hold by handle hSection: what is shared data? it is ppvBits?. If not, what is relating between ppvBits and data shared in the memory. I don't see any word in MSDN about this.
That is good if anyone give me a sample code.
Thank you.
The world is not enough!
|
|
|
|
|
|
phieu wrote: what is shared data? it is ppvBits?.
If you've provided a file mapping (hSection) then the data pointed to by ppvBits can be shared
through the file mapping. To do that, refer to the links suggested above
Mark
"If you can dodge a wrench, you can dodge a ball."
|
|
|
|
|
Thanks Mark.
OK, Now I see the data pointed to by ppvBits can be shared
through the file mapping.
But now I don’t know why: error code = 87 (ERROR_INVALID_PARAMETER) when
I call CreateDIBSection thought out but bitmap is valid.
Someone can tell me why?
Thank you.
Here is my code:
#define BITMAP_MMF_NAME "Global\\PRJ_IMS"
HANDLE m_hMMF;
HBITMAP m_hBitmap;
void CBitmapMMFDlg::OnButton3()
{
// TODO: この位置にコントロール通知ハンドラ用のコードを追加してください
int nWidth = 100, nHeight = 100;
long nSize = nWidth*nHeight*3;
// Create a file-mapping
m_hMMF = ::CreateFileMapping(
(HANDLE)0xFFFFFFFF,
NULL,
PAGE_READWRITE,
0,
nSize,
BITMAP_MMF_NAME);
DWORD dw = GetLastError();
if (m_hMMF)
{
// Create bitmap and map this bitmap to File-mapping
m_hBitmap = NULL;
HDC hdc = ::GetDC(NULL); // entire screen
//off-screen bitmap/image size - width must be DWORD aligned (multiples of 4)
LONG sizeImage = ((nWidth * 3 + 3) & 0xfffffffc) * nHeight;
BITMAPINFO bmpInfo;
memset(&bmpInfo,0,sizeof(bmpInfo));
bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmpInfo.bmiHeader.biWidth = nWidth;
bmpInfo.bmiHeader.biHeight = -nHeight;
bmpInfo.bmiHeader.biPlanes = 1;
bmpInfo.bmiHeader.biBitCount = 24;
bmpInfo.bmiHeader.biCompression = BI_RGB;
bmpInfo.bmiHeader.biSizeImage = sizeImage ;
bmpInfo.bmiHeader.biXPelsPerMeter = 0;
bmpInfo.bmiHeader.biYPelsPerMeter = 0;
bmpInfo.bmiHeader.biClrUsed = 0;
bmpInfo.bmiHeader.biClrImportant = 0;
//Create DIB Section - off screen bitmap
void* pBits = NULL;
DWORD dwOffset = 0;
m_hBitmap = CreateDIBSection(hdc, &bmpInfo, DIB_RGB_COLORS, &pBits, m_hMMF, dwOffset);
TRACE("Error code = %d \n", GetLastError());
// change bitmap bit data -> to test output
if(pBits != NULL)
{
for (int i = 0; i < 30000; i ++)
{
*((char*)(pBits) +i) = i%255;
}
}
/////////////////////////////////////////////////
// display bitmap
if (m_hBitmap != NULL)
{
CDC* pDC = GetDlgItem(IDC_STATIC)->GetDC();
if (pDC)
{
CDC dcMem;
dcMem.CreateCompatibleDC(pDC);
CBitmap* pBmp = CBitmap::FromHandle(m_hBitmap);
CBitmap* pOldBmp= dcMem.SelectObject(pBmp);
pDC->BitBlt(0,0, 100, 100, &dcMem, 0, 0, SRCCOPY);
}
}
}
}
|
|
|
|
|
I don't see anything right away...
Try changing to
bmpInfo.bmiHeader.biSizeImage = 0;
Also you calculate your file mapping size like this:
long nSize = nWidth*nHeight*3;
and your bmpInfo.bmiHeader.biSizeImage like this
LONG sizeImage = ((nWidth * 3 + 3) & 0xfffffffc) * nHeight;
Both should use the same calculation and the second method is better since DIB rows should be
aligned to a 4-byte boundary. In this case it's ok with a rowsize of 100
Mark
"If you can dodge a wrench, you can dodge a ball."
|
|
|
|
|
Is m_hBitmap NULL after the CreateDIBSection call?
"If you can dodge a wrench, you can dodge a ball."
|
|
|
|
|
m_hBitmap is not NULL, and I can display it ok, but GetLastError() = 87, INVALID_PARAMETER. I don't know why?
|
|
|
|
|
If it's not NULL then it was successful and calling GetLastError() isn't necessarily valid.
You only need to call that on failure.
From the docs:
"Most functions that set the thread's last-error code set it when they fail. However, some
functions also set the last-error code when they succeed. If the function is not documented to
set the last-error code, the value returned by this function is simply the most recent last-error
code to have been set; some functions set the last-error code to 0 on success and others do not."
Generally errors are checked for and handled something like:
m_hBitmap = CreateDIBSection(hdc, &bmpInfo, DIB_RGB_COLORS, &pBits, m_hMMF, dwOffset);
if (NULL == m_hBitmap)
{
TRACE("Error code = %d \n", GetLastError());
...do appropriate error handling/cleanup here
}
"If you can dodge a wrench, you can dodge a ball."
|
|
|
|
|
|
I am trying to write a GINA, but am faced with a problem... I need to retrieve some info over the internet/intranet. Does anyone know if this is possible, if so how would I go about it?
I have samples of writing a GINA, but all point to simply adding the password either from biometric readers or smartcards, I need to fetch a template over the net, scramble it and present it to the logon user (in a webpage).
Any ideas?
Thank you,
SeaSol
|
|
|
|
|
Hi,
I want to read RTF file in Chunk by chunk.
And I want to append in StreamIn i.e. RichEditCtrl.
But Chunk by chunk upending is not working. If I read
whole file in buffer and append/insert, it works fine.
I set SF_RTF and SFF_SELECTION flags for StreamIn.
If anyone knows about RTF & RichEdit control,
please help me.
Ashok
|
|
|
|
|
Is there a reason you are using SFF_SELECTION? Are you reading an entire file/stream to fill
the richtext control or appending/replacing existing text in the control?
What isn't working? Does your callback get called?
Mark
"If you can dodge a wrench, you can dodge a ball."
|
|
|
|
|
|
Programm3r wrote: I can use to get all the sub-directories of a directory.
Use WIN32_FIND_DATA,FindFirstFile(),FindNextFile(), you can write a recursive function.
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
Like this ??
WIN32_FIND_DATA mystruct;
mystruct.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY;
HANDLE myHandle = FindFirstFile("C:\\<dirMain>\\subdir", &mystruct);
BOOL myBOOL = FindNextFile(myHandle, &mystruct);
DWORD bw = GetLastError();
18 There are no more files. ERROR_NO_MORE_FILES
It doesn't work ??
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
My Blog: ^_^
|
|
|
|
|
Set up the search with ::FindFirstFileEx() and limit the search to directories.
Call ::FindNextFile() until the call fails, i.e. returns FALSE and ::GetLastError() returns ERROR_NO_MORE_FILES .
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
I have tried the following, but I can't seem to get it right.
All I want is to get all the names of directories and not the files.
Can someone please help me???
HANDLE Handle;
WIN32_FIND_DATA FindData;
char Temp[256];
char tempBuffer[100];
sprintf((char *)Temp, "C:\\dirMain\\subDir");
Handle = FindFirstFile((char *)Temp, &FindData);
while(1)
{
if(FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
printf("Dir Name : %s\n",FindData.cFileName);
}
else
{
break;
}
if(!FindNextFile(Handle, &FindData))
break;
}
Many Thanx
Regards,
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
My Blog: ^_^
|
|
|
|
|
This works:
void ChangeDirectoryAttribute(TCHAR* m_szFdPath)
{
HANDLE hFile;
WIN32_FIND_DATA FileInformation;
TCHAR m_szPath[MAX_PATH];
TCHAR m_szFolderInitialPath[MAX_PATH];
TCHAR wildCard[MAX_PATH] = "\\*.*";
strcpy(m_szPath,m_szFdPath);
strcpy(m_szFolderInitialPath,m_szFdPath);
strcat(m_szFolderInitialPath,wildCard);
hFile = ::FindFirstFile(m_szFolderInitialPath, &FileInformation);
if(hFile != INVALID_HANDLE_VALUE)
{
do{
if(FileInformation.cFileName[0] != '.')
{
strcpy(m_szPath,m_szFdPath);
strcat(m_szPath,"\\");
strcat(m_szPath,FileInformation.cFileName);
if(FileInformation.dwFileAttributes &
FILE_ATTRIBUTE_DIRECTORY)
{
::SetFileAttributes(m_szPath,FILE_ATTRIBUTE_NORMAL);
printf("Dir name: %s\n", m_szPath);
ChangeDirectoryAttribute(m_szPath);
}
else
{
::SetFileAttributes(m_szPath,FILE_ATTRIBUTE_NORMAL);
}
}
}while(::FindNextFile(hFile, &FileInformation) == TRUE);
::FindClose(hFile);
DWORD dwError = ::GetLastError();
if(dwError == ERROR_NO_MORE_FILES)
{
}
}
}
int _tmain(int argc, _TCHAR* argv[])
{
TCHAR m_szFolderPath[MAX_PATH] = "C:\\Program Files\\MyFolder";
ChangeDirectoryAttribute(m_szFolderPath);
return 0;
}
Source: CodeGuru How to Change the Attributes of a Directory Through Visual C++
[^]
Regards,
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
My Blog: ^_^
|
|
|
|
|
Programm3r wrote: This works:
I should hope so, since it uses the two functions mentioned twice already.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
DavidCrow wrote: since it uses the two functions mentioned twice already.
Kinda hard to get those functions working like one wants too.
The only programmers that are better than C programmers are those who code in 1's and 0's.....
Programm3r
My Blog: ^_^
|
|
|
|
|
Programm3r wrote:
Kinda hard to get those functions working like one wants too.
Only if you live in a cave with no Internet access. Googling for FindFirstFile() yields more examples than you can shake a stick at.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|