|
|
Hi,
I created an application which creates a folder in the temp directory to store the temporary output files, at program startup. When I exit my application I want to delete the files as well as the folder. My application successfully deletes the files( I used DeleteFile() API), but not the directory. The RemoveDirectory() always fails. Why is it so? I have also tried using _rmdir() method.
void RemoveTempFolder(LPCTSTR dirName)
{
basic_string<TCHAR> stFolder;
BOOL bFinish = TRUE;
HANDLE hFind;
WIN32_FIND_DATA pFindData;
stFolder.assign(dirName);
stFolder.append(_T("\\*.*"));
if((hFind = FindFirstFile (stFolder.c_str(), &pFindData))== INVALID_HANDLE_VALUE)
{
return ;
}
while(bFinish)
{
if(_tcsicmp(pFindData.cFileName,_T(".")) != 0 && _tcsicmp(pFindData.cFileName,_T("..")) != 0)
{
basic_string<TCHAR> sTemp;
sTemp.assign(dirName);
sTemp.append( _T("\\"));
sTemp.append(pFindData.cFileName);
DeleteFile(sTemp.c_str());
}
bFinish = FindNextFile(hFind,&pFindData);
}
int nRet = RemoveDirectory(dirName);
if(!nRet)
DWORD dErr = GetLastError();
}
I also tried calling RemoveDirectory()from outside the function. Still the same result. Is there anything I am missing here?? Pls help.
Thanks,
Vini
|
|
|
|
|
Try after closing the search handle with FindClose().
suhredayan There is no spoon.
|
|
|
|
|
Thanks. But it didn't work. Still my temporary folder is not deleted.
Vini
|
|
|
|
|
Vinaya wrote:
DWORD dErr = GetLastError();
What is the value of dErr ? That would be a big clue as to why RemoveDirectory() is not working.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
|
Better Forum for ask this type of question is LOUNGE
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
I find that my pointers are less likely to generate access violations if I use Courier.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
|
6 point Terminal
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" mYkel - 21 Jun '04
Within you lies the power for good - Use it! Honoured as one of The Most Helpful Members of 2004
|
|
|
|
|
In my VS IDE, I use Lucinda Console - usually 10pt but if the resolution is higher I'll go up to 14pt
Michael
CP Blog [^] Development Blog [^]
|
|
|
|
|
Finding a good font is the first milestone in the journey of becoming a master craftsman. I don't think I was even a programmer till I spent a day making my own programming font in Softy 3 years ago. I still use it and it's still awesome.
|
|
|
|
|
Fixedsys 9.
I want a clean proportional font - found it to be the best.
More important is the colour scheme:
Background - light grey
Normal test - black
Comment text - dark grey (comments blend with background - don't detract from reading code)
Selection margin - light grey
Keyword - dark blue
Number/string - dark red
Operator - dark green
Wizard code - black
User keyword - light blus
Highlight values - black on whatever
...cmk
Save the whales - collect the whole set
|
|
|
|
|
I am using Visual Studio 6 to create my simple dialog-based program. In the setting, I have selected to "use MFC as a static library". After building, I get my Released version of my EXE program. This executiable file does run well on the PC on which I developed the program. However, for the PC without Visual Studio, I found the following problems
1. The EXE does not run at all on many Win XP or Win 2000 platforms where Visual Studio has never been installed before;
2. It seems that it is not because of the missing of certain DLLs. Usually when some DLLs are missing, there pops up a error message box saying which missing DLL is required, but in my case, just nothing happens when I double-click to invoke the program. I also downloaded dependancy analyzer software to see what system file is missing and try to add and register the missing system files manually, it is not useful at all.
If you have experienced the same problem and happens to know the solution, appreciate if you can share me with it.
|
|
|
|
|
Hello Dear
Can u tell me how to detact multiple VGA cards in Visual C++ or in Visual Basic.
Thanks a Lot
I will very thank ful to you for this consideration
Regards
Touqeer
Touqeer_khan@yahoo.com
|
|
|
|
|
but you are you shouting ????
|
|
|
|
|
but you are you shouting ????
|
|
|
|
|
Anonymous wrote:
but you are you shouting ????
Welcome Moderator!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
Check out EnumDisplayDevices() .
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Hey, so I am having a lot of trouble with DirectDraw surfaces.
I set up my surfaces like this
LPDIRECTDRAWSURFACE7 lpdds;
LPDIRECTDRAWSURFACE7 lpddsBack;
DDSURFACEDESC2 ddsd;<br />
<br />
INIT_DDRAW_STRUCT(ddsd);
ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;<br />
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;<br />
ddsd.dwBackBufferCount = 1;<br />
<br />
if (FAILED(lpdd->CreateSurface(&ddsd, &lpdds, NULL)))<br />
return 105;<br />
<br />
ddsd.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER;<br />
<br />
if (FAILED(lpdds->GetAttachedSurface(&ddsd.ddsCaps, &lpddsBack)))<br />
return 106;
Now I attach a clipper to the back buffer. I then Blt() some pictures from a LPDIRECTDRAWSURFACE7 (created using the dwCaps value DDSCAPS_OFFSCREENPLAIN) to the back buffer. Next, I call:
if (FAILED(lpdds->Flip(NULL, DDFLIP_WAIT)))<br />
return 201;
When I do that, the images I Blitted are displayed, and everything is fine. I then Blt() some more images onto the back buffer for the next frame of animation. When I call the flip command, my screen turns black. It's as if I cannot Blt() anything to the memory originally associated with lpdds (primary surface).
The really odd thing though, is that I have error checking on all my DirectDraw calls(With FAILED()) and nothing is returning an error.
Also, a few other pieces of misc data that might be useful, the LPDIRECTDRAWSURFACE7's are actually members of a class called GraphicsEngine. This class is in a .h file I am writing, but I am making the Flip() and Blt() calls from the main .cpp file. (I made everything public until I fix this problem)
If anyone can help me with fixing this, I'd really appricate it.
|
|
|
|
|
what does the membership function make?
help me.
thanks.
|
|
|
|
|
Hi all! I'm a newbie to this site, and very new to Vis. C++. I am trying to write a program wich will display an incomming Binary Waveforms from a data file (yet to be determined). The Data file is eight bits wide. I'm not quite sure how to begin this. I plan on using GDI+ to handle the graphic operations. Looking at some other GDI+ functions, using the DrawString function seemed too teidous, to me, for waveforms that may be up to 1.5 MBits long. When the program is completed there will be a display of eight of these Graphs each from a column in the data file. Any suggestions, or code would be grately appreciated.
|
|
|
|
|
Please be aware that I am a hack a total newbie to C++. I'm using Visual C++ 6.0
I have written a program to process a rectangular 2D data set and then output the 2D result
as a graphic. I have created a bitmap type structure with the resulting data. I can
currently write the created bitmap out to a BMP file, then re-load the same file and
finally display the graphic. I want to be able to just display the graphic, instead of
first going to/from disk. I've got something that displays a black rectangle instead of
the graphic. For several weeks I've been searching for a good example and have yet to find
something that works for me. I think that I'm just a line or two of code away from getting
this to work, I was hoping someone out here could help. Here's what I have:
------------- The following code works fine ----------------
// MaxArrayDim = a const value defined earlier
BYTE aBitmapBits[MaxArrayDim * MaxArrayDim * 3];
//... a bunch of code is omitted where:
// - Raw 2D data is processed and mapped to RGB data and stored in aBitmapBits
// - Physical values (NumOfBytes, NumCols, NumRows) are determined
//
BITMAPFILEHEADER BitmapFileHeader;
BITMAPINFOHEADER BitmapInfoHeader;
RGBQUAD aColors[4];
BitmapFileHeader.bfType = 0x4d42; // = 'BM'
BitmapFileHeader.bfSize = NumOfBytes + 54;
BitmapFileHeader.bfReserved1 = 0;
BitmapFileHeader.bfReserved2 = 0;
BitmapFileHeader.bfOffBits = 54;
BitmapInfoHeader.biSize = 40;
BitmapInfoHeader.biWidth = NumCols;
BitmapInfoHeader.biHeight = NumRows;
BitmapInfoHeader.biPlanes = 1;
BitmapInfoHeader.biBitCount = 24;
BitmapInfoHeader.biCompression = 0;
BitmapInfoHeader.biSizeImage = NumCols * NumRows * 3;
BitmapInfoHeader.biXPelsPerMeter = 3780;
BitmapInfoHeader.biYPelsPerMeter = 3780;
BitmapInfoHeader.biClrUsed = 0;
BitmapInfoHeader.biClrImportant = 0;
// Not needed. No color map necessary for 24-bit.
aColors->rgbBlue = 0;
aColors->rgbGreen = 0;
aColors->rgbRed = 0;
aColors->rgbReserved = 0;
//Output as a BMP file
char FileName[] = "junk.bmp";
FILE *output_file; // output file pointer
// Open the data file for output
if ((output_file = fopen(FileName, "wb")) != NULL)
{
// Output the File Header, Info Header and data bytes.
fwrite(&BitmapFileHeader.bfType, sizeof(short int), 1, output_file);
fwrite(&BitmapFileHeader.bfSize, sizeof(long int), 1, output_file);
fwrite(&BitmapFileHeader.bfReserved1, sizeof(short int), 1, output_file);
fwrite(&BitmapFileHeader.bfReserved2, sizeof(short int), 1, output_file);
fwrite(&BitmapFileHeader.bfOffBits, sizeof(long int), 1, output_file);
fwrite(&BitmapInfoHeader.biSize, sizeof(long int), 1, output_file);
fwrite(&BitmapInfoHeader.biWidth, sizeof(long int), 1, output_file);
fwrite(&BitmapInfoHeader.biHeight, sizeof(long int), 1, output_file);
fwrite(&BitmapInfoHeader.biPlanes, sizeof(short int), 1, output_file);
fwrite(&BitmapInfoHeader.biBitCount, sizeof(short int), 1, output_file);
fwrite(&BitmapInfoHeader.biCompression, sizeof(long int), 1, output_file);
fwrite(&BitmapInfoHeader.biSizeImage, sizeof(long int), 1, output_file);
fwrite(&BitmapInfoHeader.biXPelsPerMeter, sizeof(long int), 1, output_file);
fwrite(&BitmapInfoHeader.biYPelsPerMeter, sizeof(long int), 1, output_file);
fwrite(&BitmapInfoHeader.biClrUsed, sizeof(long int), 1, output_file);
fwrite(&BitmapInfoHeader.biClrImportant, sizeof(long int), 1, output_file);
// write out the data bits
fwrite(&aBitmapBits[0], sizeof(char), NumOfBytes, output_file);
fclose(output_file);
}
bool ReadGraphicFromFile = true; // set manually to test different methods
if (ReadGraphicFromFile)
{
// The code below works fine, but it displays the bitmap by reading
// it from the Junk.bmp file that was written.
CString szFilename("junk.bmp");
hBmp = (HBITMAP)::LoadImage(NULL,szFilename,IMAGE_BITMAP,0,0,
LR_LOADFROMFILE|LR_CREATEDIBSECTION);
}
else
{
// ***** Here's where the problem lies *****
// hBmp = (something else based on bitmap data from memory)
}
CBitmap bmp;
bmp.Attach(hBmp);
CDC bmDC;
bmDC.CreateCompatibleDC(&dialogDC);
CBitmap *pOldbmp = bmDC.SelectObject(&bmp);
BITMAP bi;
bmp.GetBitmap(&bi);
dialogDC.StretchBlt(xLeft,yTop,xMaxWidth,yMaxHeight,&bmDC,0,0,
bi.bmWidth,bi.bmHeight,SRCCOPY);
bmDC.SelectObject(pOldbmp);
------------- End of code example ----------------
The creation of the bimap structure and writing out the file, I understand just fine.
All of the stuff after it, starting with LoadImage, I got from:
http://www.codeguru.com/Cpp/G-M/bitmap/displayingandsizing/article.php/c4905/
(Thanks to Ramakrishna Talla for that post)
Although there may be other ways to accomplish the same end, I figured if I could
create a bitmap in memory in the same form as the LoadImage gives me, with the "hBmp"
handle, then I would be all set.
I think that the answer may lie in CreateDIBSection, but the (void**)ppvbits thing
has got my brain all confused and I can't figure out how to get my data over to the
right place. I'm just flailing away with different things and all I'm getting is
a big black rectangle where I want to get a color graphic. I'd include some of that
code, but all I have is various snippets of code I've found on-line and it's a mess.
Can someone recommend some code to accomplish what I'm trying to do, or perhaps
point me to a reference for this?????
I've found tons of examples for using a bitmap resource, but only a couple that
explain loading from a file, and none (yet) that explain how to do what I'm trying
to do. I've found many that use CreateDIBSection and code similar I have above for
doing the outputing, but the step where the real data bits get copied or some
pointer gets re-specified seem to be omitted. Maybe this is assumed trivial and
because of my newbie ignorance I just can't make the leap to get there. This seems
like something that would be done a lot. Just last night I started looking into gaming
type books in the hopes that I can find something, but I haven't found it yet. (
Any help on this would be greatly appreciated.
|
|
|
|
|
DIBSections are pretty easy. You specify what you want (using a BITMAPINFO structure, like you already are), and Windows gives you memory that you can write to. You just pass in a pointer to the pointer you want to use to reference this:
unsigned char* pBmpData = NULL;
HBITMAP hBmp = CreateDIBSection(hDC, pbmInfo, DIB_RGB_COLORS, (void**)&pBmpData, NULL, 0);
Then you just need to copy your bitmap data into the memory Windows allocated for you:
memcpy(pBmpData, &aBitmapBits[0], NumOfBytes);
And you're ready to do something fun with your new bitmap. Don't forget to delete the bitmap when you're done with it though (using DeleteObject() )... and that'll free the memory used as well, so don't be using that pointer afterwards. Enjoy!
Medication for us all
You think you know me, well you're wrong
|
|
|
|
|
shog9,
Fantastic! Thanks much.
I had been trying code dangerously close to this, and as I feared I was just a misdeclaration and a couple punctuation marks away from stumbling on the answer. I've been circling this problem for about 2 weeks! Shows what ignorance will get you.
So, what's you poison, and where do I send it?
Mike
|
|
|
|
|