|
swatgodjr wrote: "the process cannot access the file because it is being used by another process."
Exactly this is the reason. Make sure that this file is not being used by another application or background process, or create a temporary file and call this function on this file and see what happens. If the problem persists then make sure that you have not opened this file before this call.
|
|
|
|
|
yea as i explained i also tried this on a file i had not even touched at all and got the same error in doing so. is there maybe something wrong with my code i posted?
|
|
|
|
|
swatgodjr wrote: yea as i explained i also tried this on a file i had not even touched at all and got the same error in doing so. is there maybe something wrong with my code i posted?
Well this I got from MSDN...
If the function fails, the return value is INVALID_FILE_ATTRIBUTES . To get extended error information, call GetLastError .
Do check for this value instead of !dwFileAttributes.
|
|
|
|
|
actually i originally had it checking for INVALID_FILE_ATTRIBUTES but no matter what i did it kept giving me an error saying it was an undeclared identifier so i just put !attribList so that it would compile so that i could at least test it out. i included the files it needed and everything and after quite a bit of looking around i just left it the way i have it now. the code i posted was actually modified from my getlasterror function which works nicely.
|
|
|
|
|
I don't get your code.
First, check the return value from GetFileAttributes().
If it's 0xFFFFFFFF, then call GetLastError() to get the error code.
Then, do a FormatMessage with the return value from GetLastError()!
(It's natural you always gets the same error message when you always calls FormatMessage with the same value, 0xFFFFFFFF).
Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson
|
|
|
|
|
swatgodjr wrote: if(!attribList)
You must read the docs a bit closer:
if (INVALID_FILE_ATTRIBUTES == attribList)
{
MessageBox("An Error Has Occured", pszCaption, MB_ICONWARNING);
}
"Talent without discipline is like an octopus on roller skates. There's plenty of movement, but you never know if it's going to be forward, backwards, or sideways." - H. Jackson Brown, Jr.
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
i tried to use INVALID_FILE_ATTRIBUTES and it returns an error on compiling saying that it was an undeclared identifier and also tried checking for the other error code but that just gives me the same error message i have been having when the function is called in my program. i have the correct files being included into my program so i really am not sure why it wotn let me use INVALID_FILE_ATTRIBUTES. also from what i have noticed, it never returns either error message as it goes to the main body of the function like it should.
|
|
|
|
|
I need extra eyes on this. Below are two examples of some code I have. My application is slowing down over time, so I suspect resource / memory leaks. My tools indicate the following chunk of code leaks a DC. Do you see it? I don't. Look for <<<<<
CWaitDlg::UpdateCursor(CPaintDC *pDC, int nImage)
{
CDC dcBitmap;
dcBitmap.CreateCompatibleDC(pDC); // <<<<<<<< this is where the leak is allegedly.
CBitmap * pOldBitmap = dcBitmap.SelectObject(&m_WaitImages[nImage]);
pDC->BitBlt(m_nCenterX, m_nCenterY, m_Size.cx, m_Size.cy, &dcBitmap, 0, 0, SRCCOPY);
dcBitmap.SelectObject(pOldBitmap);
dcBitmap.DeleteDC();
}
Example #2: this chunk of code is supposed to leak a solid brush. This follows the
typical pattern of create, select it in, use it, deselect, delete.
.
.
.
CBrush brush;
brush.CreateSolidBrush(N_WHITE); //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
CBrush *pOldBrush = dc.SelectObject(&brush);
dc.Ellipse(radioRc);
dc.SelectObject(pOldBrush);
brush.DeleteObject();
dc.SelectObject(pOldPen);
pen.DeleteObject();
.
.
.
Charlie Gilley
Will program for food...
Whoever said children were cheaper by the dozen... lied.
My son's PDA is an M249 SAW.
My other son commutes in an M1A2 Abrams
|
|
|
|
|
fwiw - this code only reports a resource leak in a release build mode - debug does not report this issue. Even if I compile in release mode with no optimization, it is still reported, but debug never.
Charlie Gilley
Will program for food...
Whoever said children were cheaper by the dozen... lied.
My son's PDA is an M249 SAW.
My other son commutes in an M1A2 Abrams
|
|
|
|
|
How did you determine that there was a resource leak? What is being leaked?
Steve
|
|
|
|
|
Steve - this is a pure mfc application on Windows CE. I have a tool called CodeSnitch that claims these are resource leaks. In the first snippet, I am allegedly leaking the dcBitmap. In the second snippet, the brush is leaking. Again, allegedly.
I don't see it.
Charlie Gilley
Will program for food...
Whoever said children were cheaper by the dozen... lied.
My son's PDA is an M249 SAW.
My other son commutes in an M1A2 Abrams
|
|
|
|
|
I don't see any leaks. I think your tool sucks.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Tell me how you really feel Christian...
Development on WinCE can be a PITA at times.
Charlie Gilley
Will program for food...
Whoever said children were cheaper by the dozen... lied.
My son's PDA is an M249 SAW.
My other son commutes in an M1A2 Abrams
|
|
|
|
|
Well, as the saying goes, "Doh!"
Although this code works fine on the desktop, it turns out that WinCE mfc dll has a little bug. It turns out that WinCE has some issues with really deselecting and deleting GDI objects. Even though I say delete - it doesn't happen. KB839859. Apparently it's a problem with the OnIdle processing for the application. Unbelievable... simply unbelievable.
Insert MS RANT <not repeatable="">
Charlie Gilley
Will program for food...
Whoever said children were cheaper by the dozen... lied.
My son's PDA is an M249 SAW.
My other son commutes in an M1A2 Abrams
|
|
|
|
|
Hey guys,
I am suppose to read in from a text file. M is the sex and 24 is the age.
The file I'm currently reading has the following code.
I am wondering what the ws is for. I see how fin >> sex is reading in the sex of the person and fin >> swimmer[actualSwimmers].age is reading in the age. What is the >> ws doing there???
Someone please help me out here
thanks in advance.
M 24
fin >> sex;
fin >> swimmers[actualSwimmers].age >> ws;
|
|
|
|
|
This is explictly skipping white space. I'm not sure of you need this in your code or not.
Steve
|
|
|
|
|
I'm trying to write a directX program and According to my text book I need to link to these two libraries: d3d9.lib and d3dx9.lib, I've gone to tools>options>Solutions and Projects>VC Directories and selected library paths from the drop down. I've than added C:\Program Files\Microsoft DirectX SDK (August 2006)\Lib\x86 as a new path. When I try and compile I'm only using one directX call (want to get this working before I go further or am able too ) and I get this output:
DirectXBase.obj : error LNK2001: unresolved external symbol _Direct3DCreate9@4
C:\Documents and Settings\Barryod\My Documents\Visual Studio 2005\Projects\DirectX1\Debug\DirectX1.exe : fatal error LNK1120: 1 unresolved externals
Now I've added the include path, I've added the direct lib path and #included the header files which the call I'm making is in. This is my first time using VC++ so I'm sure I'm just missing a blantant step somewhere . Any help is really appreciated as a silly error like this is frustating when you want to get stuck in.
|
|
|
|
|
Im not sure its helpful for you but see here[^]
|
|
|
|
|
You forgot to link to the libraries. Adding a library path doesn't mean that you will automatically link to all libraries that are in the path.
|
|
|
|
|
Ok thanks for the two replies, I've added this to my code:
#pragma comment(lib, "d3dx9.lib")
#pragma comment(lib, "d3d9.lib")
And it now compiles. Do you always have to use this sort of command to link to a library? Is there not a way to do it through the IDE?
|
|
|
|
|
BarryOg wrote: Do you always have to use this sort of command to link to a library? Is there not a way to do it through the IDE?
You always have to link with the library. Now, there is another way of doing it. You can go in the project properties and there, in the link 'tab' you can specify which libraries to link to. The exact location of it depends of the IDE you are using. For example with VC2005, select the 'Linker' option -> 'Input' and add your libraries in 'Additional Dependencies'.
|
|
|
|
|
Ah ok, I wish they made that clearer. Well thanks for the help.
|
|
|
|
|
Hi
New to C++ but a bit stuck with this one.
I need to print a character eg: "x" multiple times on a console application.
I need to print "XXXXX" on the console in the place of an actual word as the user has to guess what the real word is. (Hangman based game)
i have used "example.length()" to obtain the amount of letters in the word but i need to transfer the "example.length()" to the relevant amount of "x's" to make up the word.
eg:
STARWARS must become XXXXXXXX on the console.
Can anyone help out with this one.
Thanks in advance.
I really hate this darn machine;
I wish that they would sell it.
It won't do what I want it to,
but only what I tell it.
~Author Unknown
|
|
|
|
|
for(int i=0;i<example.length();++i)
{
cout="" <<="" "x";
}
although,="" i="" think="" there's="" actually="" another="" way="" to="" do="" it,="" that's="" the="" most="" straightforward.
=""
<div="" class="ForumSig">Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
The below code is not the simplest way of doing what you want. However, I assume you will be changing the X's as the user guesses the word. Thus, you can modify the PrintChar class to compare the guess with the answer, and print either an 'X' or the correct character.
#include <string>
#include <iostream>
#include <algorithm>
using std::wcout;
using std::endl;
using std::for_each;
using std::wstring;
class PrintChar {
public:
void operator() (const wchar_t& c)
{
wcout << L'X';
}
};
int _tmain(int argc, _TCHAR* argv[])
{
wstring answer = L"telephone";
for_each(answer.begin(), answer.end(), PrintChar());
wcout << endl;
return 0;
}
|
|
|
|