|
right on, thanks for the help guys. saved me another day of tearing my hair out, haha.
muchas gracias
later
-james
|
|
|
|
|
if u use CreateFile()
Specifiy the create dispozition paramater: OPEN_EXISTING;
if the function return INVALID_HANDLE_VALUE then it does not exist or u can use GetLastError() and FormatMessage() to see the exact error returned hope this helps
gabby
|
|
|
|
|
Another way for you knowledge:-
You can also use
CFile::GetFileStatus(CString filename,CFileStatus status) a static function
returns false if it doesnt exist and then return from your function.
Regards
farPointer
|
|
|
|
|
jnerv wrote: if i give it a file location that doesn't exist, it outputs the message and doesn't create a file, but most of the time it creates the file and doesn't output the message. why is this?
Which Api/Class are you using to read/write File.. as these api contain flags... which can return ERRROR is no file Exist by that name on the specified path.
"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
|
|
|
|
|
I all [[]]
Is this ok?
<br />
class errorMemoryShortage;<br />
<br />
int Func( void )<br />
{<br />
SomeType* SomeVar;<br />
<br />
SomeVar = new SomeType;<br />
if ( !SomeVar ) throw new errorMemoryShortage;<br />
}<br />
If there is no memory how can i throw an exception?
Thx!
Peace [[]]
hint_54@hotmail.com
|
|
|
|
|
If there is not enough memory, new will throw bad_alloc exception for you anyway and you will never even get to your NULL test.
My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it.
|
|
|
|
|
> If there is no memory how can i throw an exception?
Never *ever* throw exceptions which allocate memory dynamically (or dynamically allocate the exception object itself), when you are out of memory. Things may happen to your application which you may not recover from if you had a thousand catch clauses (I love paraphrasing lyrics by the way )
As Nemanja says, "reuse" the exception which new provides for you. You'll be much better off that way.
--
Pictures[^] from my Japan trip.
|
|
|
|
|
At least in my case. What I am trying to do is to obtain an icon from an executable and to add it among with exe name to the report-styled list control.
<br />
if(ExtractIconEx(str,0,NULL,NULL,0) > 0)<br />
{<br />
ExtractIconEx(str,0,NULL,&hIcon,1);<br />
m_plistIcons->Add(hIcon);<br />
}<br />
else<br />
m_plistIcons->Add(m_hIcon);<br />
What I get is while every run the handle is different and after the loop ends image list contains 37 entries the only icon which is applied to absolutly all list items is the first added to the image list.
Image list is being attached to list control using this line:
m_ProcList.SetImageList(m_plistIcons,LVSIL_SMALL);
I am quite sure I'm doing something wrong. I just dunno what.
-- modified at 4:49 Saturday 10th December, 2005
|
|
|
|
|
Nobody knows ? Not a single human being ? I take help from aliens as well...as long as you speak the language I speak
|
|
|
|
|
Maybe it depends on how you add the items to your list control. By default the CListCtrl assumes to use image 0 for all items. You have to specify for every item which image it should use.
|
|
|
|
|
Wow. Some people wonder outside of page 1 Anyway I've figured it out on my own but thanks anyway.
--------------------------------
Human stupidity is infinite.
|
|
|
|
|
hi guys
Im trying me in managed C++ Appications. I have a string ( System::String^ item; ) an i want to compare it with another one ( "abc" ). My first idea was strstr but it dont works ( something like cannot convert ... ) Now its your turn. I need a similiar function that works like strstr in managed c++
Salut!
|
|
|
|
|
MaTTEvIL wrote: hi guys
Im trying me in managed C++ Appications. I have a string ( System::String^ item; ) an i want to compare it with another one ( "abc" ). My first idea was strstr but it dont works ( something like cannot convert ... ) Now its your turn. I need a similiar function that works like strstr in managed c++
Salut!
strstr does not compare two strings, it is used to search a string for a substring. You probably mean strcmp .
For managed strings, use String::Compare .
Alternatively you can compare the String handles directly using the == operator, because due to string interning, all handle variables to the same string will have the same handle value.
|
|
|
|
|
Anyone use this product? If so, did you update it for VC7+? If so...I need to talk to you!
ed
~"Watch your thoughts; they become your words. Watch your words they become your actions.
Watch your actions; they become your habits. Watch your habits; they become your character.
Watch your character; it becomes your destiny."
-Frank Outlaw.
|
|
|
|
|
Hello everybody,
i'm using Word automation to generate some data reports in word for printing.
Because my program is a top-level window i need to bring the word window to the top level
to make it accessible. I use a method explained here.
This method of changing the caption with automation and find it with the API FindWindow works like
a charm with Word97. But with Word 2003 the FindWindow API finds nothing . I searched a couple of hours on the internet, but I can't seem to find some answer/hint on how to pull it off.
All suggestions are welcome .
Greets Remco.
|
|
|
|
|
you can use SPY++ to find Word 2003 window,then you can get some information about the Word 2003 window,it help you to use the API FindWindow function.
|
|
|
|
|
Hello sun_shb,
I tried it with spy++, i used the class of the word window and the custom caption i gave it, but still FindWindow is unable to find it.
|
|
|
|
|
I need to open a file from the a CD rom. This application must run on multiple computers, each with a different drive letter for the CD drive. Is there a simple call to obtain which letter the cd drive is on without searching each drive letter A-Z for that file? (I know it will never be A or C)
Currently I use the _chdrive in a for loop to traverse through all possibilities.
Thanks in advance.
|
|
|
|
|
Maybe use RealDriveType Shell function instead ?
|
|
|
|
|
You can call GetDriveType API function to determine if it's a CD Rom.
Check out the following wrapper class:
#include <windows.h>
#include <vector>
#include <string>
#include <iostream>
using namespace std;
class DriveInfo
{
public:
DriveInfo()
{
char* buffer = 0;
size_t bsize = 0;
getDriveLetters(bsize,buffer);
parseDriveLetters(bsize,buffer);
delete [] buffer;
}
size_t NumDrives() const
{ return mDrives.size();}
std::string DriveName(size_t index) const
{ return mDrives[index]; }
char DriveLetter(size_t index) const
{ return mDrives[index][0]; }
DWORD DriveType(const std::string& driveName) const
{ return ::GetDriveType(driveName.c_str()); }
private:
void getDriveLetters(size_t& bufferSize, char*& driveStrings) const
{
bufferSize = MAX_PATH;
driveStrings = new char[bufferSize];
bool gotDriveNames = false;
while (!gotDriveNames)
{
DWORD pos = ::GetLogicalDriveStrings((DWORD)bufferSize, driveStrings);
if (pos > bufferSize)
{
bufferSize *= 2;
delete [] driveStrings;
}
else
{
gotDriveNames = true;
}
}
}
void parseDriveLetters(size_t size, const char* buffer)
{
std::string s(buffer, size);
std::string driveString;
for (size_t i=0; i<size; i++)
="" {
="" if="" (s[i]="=" 0)
="" (!drivestring.empty())="" mdrives.push_back(drivestring);
="" drivestring="" ;
="" }
="" else
="" +="s[i];
" }
="" std::vector<std::string=""> mDrives;
};
Example usage:
int main()
{
DriveInfo di;
for (size_t i=0; i
|
|
|
|
|
Or use something as simple as
<br />
for(int i=0;i<25;i++)
{<br />
if(RealDriveType(i,0) == DRIVE_CDROM)<br />
}<br />
|
|
|
|
|
Thanks for both your help.
I actually am using GetLogicalDriveStrings to get the available letters and then traverse through the letters using GetDriveType.
Thanks again....CP is the best!
|
|
|
|
|
NYTSX wrote: Thanks for both your help.
you can try warpper class for same here :-
http://www.codeproject.com/system/SysUtil.asp[^]
"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
|
|
|
|
|
Hi,
I am curious about how c++ stores it's array size after a call to new x[].
does it store the array size, or an object count?
If it is an object count then deleting an object recasted from what it was originally newed could cause an heap error right?
eg, would the code...
class objectx
{
// lots of things that make this an object much larger than bool!
};
objectx* myObject = new (myObject)bool[20];
// do code
delete[] myObject;
...cause a heap corruption as delete trys to delete 20 x objectx's?
-- modified at 16:22 Friday 9th December, 2005
|
|
|
|
|
lastgen wrote: objectx* myObject = new (myObject)bool[20];
???
what are you trying to do there?
lastgen wrote: delete[] myObject
the '[]' means this is an array of objects, so call their destructor (if there is one) before deallocating the memory. but the memory you allocated holds only bools, not myObjects.
massive trouble awaits those who lie to the compiler about what lies on the other side of a pointer.
Cleek | Image Toolkits | Thumbnail maker
-- modified at 16:19 Friday 9th December, 2005
|
|
|
|