|
Hi.
Is it possible to create a file with a long path name? For example:
-----
std::string pathFile("c:\testing\December 27\newfile.type");
// CreateFile fails
if (::CreateFile(pathFile->c_str(),...) == INVALID_HANDLE_VALUE)
{
}
-----
I would like to know two properties of CreateFile(). First, is it possible to create a file in a directory that does not exist via CreateFile()? In the example above, directories "testing" and "December 27" do not exist.
Secondly, is it possible to create directories with spaces between one or more words, i.e. December 27. Notice the space before "2."
Thanks,
Kuphryn
|
|
|
|
|
1. CreateFile will NOT create directories. You'll need a recursive create directory function. There are a few hanging around CP. And I have you if you need it.
2. Yes. Spaces are fine.
CreateDirectory("December 27");
should work
Todd Smith
|
|
|
|
|
kuphryn wrote:
is it possible to create a file in a directory that does not exist
No, if the dir doesn't exist there's no place to create the file.
Secondly, is it possible to create directories with spaces between one or more words
Yes, CreateFile() uses whatever string you pass it for the name.
--Mike--
If it doesn't move and it should: WD-40. If it moves and it shouldn't: duct tape.
1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click!
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
Okay. Thanks everyone.
Is there a Win32 API for checking the existence of a directory? Otherwise, recursive creation will do.
One last inquiry. I have seen in the past members mentioning directories with two backslashes. Is there something special about creating directories with two backslashes instead of one?
Example:
std::string pathFile("c:\\testing\\December 27\\file.type");
Kuphryn
|
|
|
|
|
kuphryn wrote:
Is there a Win32 API for checking the existence of a directory? Otherwise, recursive creation will do.
Technically, no. At least I haven't seen one. In an instance that I had, I had to create a file, several dirs deep. So I had to do a _access(filename, 00) to see if the dir existed. If not, I would create it. That might be how you will have to do it.
kuphryn wrote:
I have seen in the past members mentioning directories with two backslashes. Is there something special about creating directories with two backslashes instead of one?
I am not sure about this. In some cases, if you are required to use \\ in order to have just one \. In other cases, it doesn't matter. For instance in your case, I think it will work to have just one c:\ instead of c:\. I know in other cases, for instance, in a wsprintf, strcpy, you have to have \\.
|
|
|
|
|
|
kuphryn wrote:
Is there something special about creating directories with two backslashes instead of one?
The two backslashes are necessary to comply with C++ syntax. In string and character literals, a backslash is a special character and indicates that the next character should be treated specially. For instance, \t means "the tab character". One backslash by itself is meaningless*, so in order to have a backslash character in a string, you write \\ in your code.
So to create a directory C:\testing , you write "C:\\testing" . If you write "C:\testing" , that is interpreted as C followed by colon followed by TAB followed by "esting", which is not what is intended.
*Except when the backslash comes at the end of a line, in which case it is an instruction to the preprocessor to join the line with the following one.
--Mike--
If it doesn't move and it should: WD-40. If it moves and it shouldn't: duct tape.
1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click!
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
|
Hi!
I wanted to create a MFC dll which displays a SDI window when I call it
whith rundll. The function is - let's say - "EntryPoint". It worked so far,
but the SDI doesn't want to stay on the screen, it just pops up and closes.
In the MSDN, I've read that a dll is being unloaded when the function I'm
calling (EntryPoint) returns. How can I make the SDI staying on the screen?
Is there a workaround or somewhat? Perhaps a wait loop which doesn't take
much processor time?
Mfg
the Datalord
|
|
|
|
|
I'm adding IRC chat to my game launcher, and am wanting to show the chat text in colors using a Rich Edit 2.0 control in a dialog. I'm doing the following to add a line of text (Tmp is a CString containing the chat line text):
<br />
CHARFORMAT cf;<br />
<br />
cf.cbSize = sizeof(cf);<br />
cf.dwMask = CFM_COLOR | CFM_FACE;<br />
strcpy(cf.szFaceName,"Subway");<br />
...<br />
cf.crTextColor = RGB(255,0,0);<br />
...<br />
ChatList.SetSel(-1,0);<br />
ChatList.SetDefaultCharFormat(cf);<br />
ChatList.ReplaceSel(Tmp);<br />
ChatList.LineScroll(ChatList.GetLineCount());<br />
Now, the text is correctly show using the "Subway" font, but it's still only black What am I doing wrong?
Thanks!
|
|
|
|
|
Hmm, the coloring works in release builds!
|
|
|
|
|
i love this site!
can Somebody tell me why ?
-=Ehsan-de-Burge=-
|
|
|
|
|
1) Easy to navigate and pleasant interface
2) Super fast message boards responses
3) Quality articles which seldomly require H scrolling
4) Emoticons are so damn cool
5) A real sense of community
"An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
|
|
|
|
|
+ + =
- Nitron
"Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb
|
|
|
|
|
Is there a way or another function that will work the same as STRTOK without removing the string after the token?
I want to find the first token and leave the string as it was.
Thanks,
Jim
|
|
|
|
|
if you just want to search for a sub-string, try "strstr".
-c
I'm not the droid you're looking for.
|
|
|
|
|
strstr would work, but I only know the string based on a delimiter.
strtok() works so well I was hoping I would have to save off the string first and then put it back in later.
Thanks...guess I'll keep searching....
|
|
|
|
|
substring by using strstr()?
~~~~Code the Dreams~~~~~
|
|
|
|
|
hi
i searched the MSDN but i findout out that the random() function in stdlib.h is not exist.
it seems that it's replaced with srand() and rand() . can anyone explain me how can i use these 2 function or any other to reach random numbers in requested range ? (for example 0 < x < 1000 )
thnx
|
|
|
|
|
|
thanks mr.nishant but it seems that in this example the Range of Figures are not important.
may be i should do something like this :
<br />
int r=1000;<br />
while(1){ r=rand(); if (r<999) break; }
thanks any way.
-=Fight with be Best Die like the Rest=-
|
|
|
|
|
*cough* modulus *cough*
Know that good little % operator?
I wonder what this would do:
min + (rand() % (max - min + 1))
|
|
|
|
|
HellShrimp4free wrote:
but it seems that in this example the Range of Figures are not important.
Correct, in the MSDN example the range isn't important, however you can do the following to limit your range to under 1000:
#include "stdafx.h"
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#using <mscorlib.dll>
#include <tchar.h>
using namespace System;
int _tmain(void)
{
srand( (unsigned)time( NULL ) );
for( int i = 0; i < 10;i++ )
printf( " %6d\n", rand()%1000 );
Console::Read();
}
Nick Parker
You see the Standards change. - Fellow co-worker
|
|
|
|
|
Hi
Those two functions have always been there. In fact I never used (saw ?) the function Random()
Here is how to use them:
// Seed Random-number Generator with Current Time
srand(( unsigned) time(NULL ));
int nRandomData = rand() % 4;
Replace 4 with the Maximum value accepted (1000 in your request)
The call to srand with current time allows the generation of different random sequences. If you start always with the same number, you always got the same sequence ( as far as I remember) ...
HTH
Thierry
|
|
|
|
|
I have a Windows NT service which maintains a pool of objects. The purpose of the pool is to improve performance because the objects being pooled require a signifigant amount of time for construction.
At any given time, there can be from 0-N requests for objects from the pool. There are times when the pool will have no requests at all for days. Other times, it will have 1000s of requests an hour/minute. I keep track of # of requests, avg time between requests, first request, last request, time to allocate, time to fill request, peak objects in pool, peak requests per sec/min, # of requests made when pool was exausted.
I am looking for an algorithm that will limit the number of requests that occur when the pool is exausted while not exceeding a maximum pool size or memory usage. There really is not MAX size, but I don't want to just allocate 1000s all the time. My goal would be to have 75-85% of requests filled by the pool with no waiting.
Currently, the algorithm I use is something like this:
(Pseudocode
long lDesiredPoolSize = lMinSize;
if (lRequestsLast5Minutes > (lRequestsLastHour / 12) && lRequestsLast5Minutes > lDesiredPoolSize)
lDesiredPoolSize = lRequestsLast5Minutes * 1.25;
if (lPoolExaustedRequests > lDesiredPoolSize)
lDesiredPoolSize = lPoolExaustedRequests * 1.25;
if (lRequestsLastHour >= lRequestsAtPeak)
lDesiredPoolSize = lRequestsLastHour * 1.25;
if (lDesiredPoolSize > lMaxPoolSize)
lDesiredPoolSize = lMaxPoolSize;
if (lRequestsLastHour == 0)
lDesiredPoolSize = 0;
I just made this up and tinkered with it, but I wonder if anyone in CPland has any more experience with this kind of thing?
|
|
|
|