|
Hi ,
As i know the data read and write from a hard disk in a file is bit a slow process,
So i want read a data from file and load it into a memory to do some operations on data and then i want to write that all data inot a file , so read and write will b only for once.
actualy i dont want the continoius read and write to a hard disk,
so how can i load the all file contents in a memry and read them from memoery , and how can i write a that memory data into a file
Thanks
Regards.
|
|
|
|
|
Create a file.
pass that handle as first parameter in the function CreateFileMapping()
now pass the hanle return from the function CreateFileMapping to the function
MapViewOfFile().
The function MapViewOfFile() returns a pointer to the buffer. u can do read and write to thst buffer. Finally u have to call UnMappviewoffile() when u exit.
nave
|
|
|
|
|
zahid_ash wrote: so how can i load the all file contents in a memry...
char buffer[2048];
DWORD dwBytesToRead = sizeof(buffer),
dwBytesRead;
ReadFile(hFile, &buffer, dwBytesToRead, &dwBytesRead, NULL);
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
Hi there,
i have written this function to draw a image held in raw pixel data in my own class to a window. It is not working as expected, say it doesn't draw a single pixel. Where is the fault? I am trying to solve this for days now and can't see where i made the mistake. Here comes the code.
void CImageViewerView::drawImage(CDC* pDC, CpilImage* pImage) {
CDC memDC;
memDC.CreateCompatibleDC(pDC);
CBitmap imageBitmap;
BITMAP bmp;
BYTE* imageBits;
BYTE* pImageBits;
imageBitmap.CreateBitmap(pImage->getWidth(), pImage->getHeight(), 1, 24, NULL);
imageBitmap.GetBitmap(&bmp);
imageBits = (BYTE*) GlobalAlloc(GPTR, bmp.bmHeight * bmp.bmWidthBytes);
for (unsigned int y = 0; y < pImage->getHeight(); y++) {
unsigned int* line = pImage->getPixelRegion(0, y, pImage->getWidth(), 1);
unsigned int* pLine = line;
pImageBits = imageBits + (bmp.bmWidthBytes * y);
for (unsigned int x = 0; x < pImage->getWidth(); x++) {
pImageBits[0] = getRedValue(pLine);
pImageBits[1] = getGreenValue(pLine);
pImageBits[2] = getBlueValue(pLine);
pImageBits += 3;
pLine++;
}
}
if (imageBitmap.SetBitmapBits(bmp.bmHeight * bmp.bmWidthBytes, imageBits) == 0) {
AfxMessageBox("Could not set bitmap bits.");
}
GlobalFree((HGLOBAL) imageBits);
CBitmap* pOldBitmap = memDC.SelectObject(&imageBitmap);
if (pDC->BitBlt(0, 0, pImage->getWidth(), pImage->getHeight(), &memDC, 0, 0, SRCCOPY) ==0) {
AfxMessageBox("BitBlt failed.");
}
memDC.SelectObject(pOldBitmap);
}
CpilImage is a class which stores a image plus the pixel data in rgb-quads. The getXXXValue() -functions are utility functions which extract the red, green and blue values from the quads. The class and functions are working, cause if i alter the function to work with CDC::SetPixelV() the image is drawn. But as this is very slow i tryed to speed it up with SetBitmapBits() and BitBlt() which seems to not work.
Walter
|
|
|
|
|
i am prety sure no one wants to read long code as in ur post.
1. bitmap width must be aligned with 2 or 4 bytes.
2. bottom-up or top-down bitmap is determined by BITMAPINFIHEADER.dbHeight.
A nice tool for optimizing your Microsoft html-help contents.
Includeh10
-- modified at 8:12 Wednesday 1st March, 2006
|
|
|
|
|
I tryed to cut it down, but i thought everything could be important. But your post shows that you haven't read the code, either. I use the calculated width from the bitmap info header bmWidthBytes. This is calculated by windows and 4 bytes aligned. I put traces in there and the height is calculated correct. If any of this values would be false there should be something on the screen at last and if it is only crap. But there is nothing, not a single pixel.
I try to break the code down a bit:
CDC memDC;
memDC.CreateCompatibleDC(pDC);
CBitmap imageBitmap;
BITMAP bmp;
BYTE* imageBits;
BYTE* pImageBits;
imageBitmap.CreateBitmap(pImage->getWidth(), pImage->getHeight(), 1, 24, NULL);
imageBitmap.GetBitmap(&bmp);
imageBits = (BYTE*) GlobalAlloc(GPTR, bmp.bmHeight * bmp.bmWidthBytes);
if (imageBitmap.SetBitmapBits(bmp.bmHeight * bmp.bmWidthBytes, imageBits) == 0) {
AfxMessageBox("Could not set bitmap bits.");
}
GlobalFree((HGLOBAL) imageBits);
CBitmap* pOldBitmap = memDC.SelectObject(&imageBitmap);
if (pDC->BitBlt(0, 0, pImage->getWidth(), pImage->getHeight(), &memDC, 0, 0, SRCCOPY) ==0) {
AfxMessageBox("BitBlt failed.");
}
memDC.SelectObject(pOldBitmap);
|
|
|
|
|
Instead of using CreateBitmap() , use CreateCompatibleBitmap() passing pDC as the DC parameter, and then use the contents of the BITMAP structure to determine what format the bitmap is in. You may very well find that it's a 32-bpp bitmap, not a 24-bpp bitmap. Remember BitBlt() only works if the source bitmap is monochrome or in the same format as the device context - hence the CreateCompatibleBitmap() function.
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"
|
|
|
|
|
Yeah! Just found out that this is the problem. It seems SelectObject() for the bitmap is returning an error, because of the bitmap is not compatible with the device context. I think i change my strategy and have a look into device independent bitmaps (DIB). Maybe this solves my problem.
Programming Windows API can be frustrating sometimes. The only thing i want to do is to put some raw 24bit RGB pixel data fast on to the screen. This can't be that difficult.
Thanks for your help!
|
|
|
|
|
I just noticed what you're trying to do
Have a look at CreateDIBitmap() and SetDIBitsToDevice() . They will work with any bitmap format and will convert between them when displaying the bitmap. Slower than BitBlt() , but the performance will be substantially quicker than what you are doing here.
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"
|
|
|
|
|
Looks like i am on the right way now. Thanks again.
|
|
|
|
|
How is it possible to correctly allign the seperate parts of a status bar under Win32? I know we have to create an array of ints each defining the right side of the part and send the SB_SETPARTS message. But what about alligning the parts on the right hand side?
I want my bar to look similar to this one http://www.codeproject.com/miscctrl/ProgressBar.asp[^]
The only method I can think of is by getting the status bar rect and setting the parts according to the width, but this kinda gets screwed up when it comes to resizing. Even so, in the picture there is a large space blank space before the parts which I am so far unable to reproduce.
|
|
|
|
|
waldermort wrote: I want my bar to look similar to this one http://www.codeproject.com/miscctrl/ProgressBar.asp[^]
<font color=blue>int</font> CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
<font color=green>
m_wndStatusBar.SetPaneInfo( 0, m_wndStatusBar.GetItemID( 0 ), SBPS_STRETCH, NULL );
<font color=green>
}
NOTE: Only one pane of the status bar can have this style set.
Nibu thomas
Software Developer
|
|
|
|
|
Hello
I want to ask how can i create a child process in Win32 as we do in linux with the help of fork().
Thank you.
We Believe in Excellence
|
|
|
|
|
CreateProcess(...)
Nibu thomas
Software Developer
|
|
|
|
|
|
I am not going to give you an answer, because you did no give an explanation of what fork() does. You have received a couple of answers about generating a child process.
What do you want to know precisely?
INTP
Every thing is relative...
|
|
|
|
|
I'm not a linux expert but I think fork() creates a new thread and not a new process. Am I right (not sure at all about that). The previous answers you get was how to create a process (so run another executable). If you want to run a thread in parallel, then you have to look for CreateThread[^]
|
|
|
|
|
fork() creates a new process - an exact duplicate of the current process, including the current code location. You can do this:
switch(fork())
{
case 0:
exit(0);
default:
break;
}
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"
|
|
|
|
|
Here is the discription of fork() function.
"fork creates a child process that differs from the parent process only in its PID and PPID, and in the fact that resource utilizations are set to 0."
I wanted to do the same thing in win32. I do not want operating system to allocate saperate resourses to new process. Infact i want the process to share the same resourses that it's parent is using. Are you getting my point?
Thank you.
We Believe in Excellence
|
|
|
|
|
Look at CreateThread() . It's exactly what you're after. But read up on multithreading, because you obviously don't know a lot about it. It can be quite tricky to learn...
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"
|
|
|
|
|
There is no fork equivalent under Windows. I suggest you consider using threads rather than processes - that is the Windows way of handling concurrency.
My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it.
|
|
|
|
|
Nemanja Trifunovic wrote: I suggest you consider using threads rather than processes - that is the Windows way of handling concurrency.
Actually, its becoming more and more the Linux way of concurrency.
NPTL is a stable working thread implementation.
"We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation."
-- Caius Petronius, Roman Consul, 66 A.D.
|
|
|
|
|
how would i go about that
martin reagan akula
|
|
|
|
|
|
your cyber cafe must have a VoIP client ( whtever the real name is ).
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|