|
Hi guys, I need some help
I get a filename from an external source, and I must create a file on disk with that filename. The problem is that there is no garantee that the filename I have is a valid filename, i.e. it can have invalid characters such as \ / : * ? " < > |.
Is there a standard way of fixing invalid filenames (through a windows shell api maybe?). I know that I can do it manually, but I would prefer to use a standard method.
Thanks!
James
(2b || !2b)
|
|
|
|
|
You can't really "fix" a filename without applying human ai to it.
for example, say i typed this: c:\myfile.8nc
my big fingers hit the 8 key instead of the i key. You're never going to be able to fix errors like that: other problem areas are where user hits / instead of ., etc.
AFAIK no programs in windows will try to fix a bad name. what you should do is try to create the file anyway, but look for errors from the CreateFile() function. If there is an error, then report back to the user.
Sorry to dissapoint you all with my lack of a witty or poignant signature.
|
|
|
|
|
This is in a server program, not a UI app, so no user interraction can take place.
Thanks anyway
James
(2b || !2b)
|
|
|
|
|
Is it just a filename we're dealing with, or an entire path *and* filename?
If it's just a filename, you can easily scan the string for the invalid characters. If it's a path and filename, you have to split it into it's component parts, check the components one at a time, and then (if you found invalid characters) reassemble the filename without the bad characters.
I guess you could use the Win32 or C++ api to do sanity checks (like trying to create the file on the drive and evaluating any error condition that might be indicated), but it's a lot simpler to just scan/fix the string programatically because then you don't take a chance on generating a message box on the server that nobody can see anyway.
char cMarker = '|';
CString sBadChars = "\\/:*?\"<>";
CString sMyFileName = "a/b:c,1<2>3.xvy";
int nLen = sMyFileName.GetLength();
char cCurr;
for (int i = 0; i < nLen; i++)
{
cCurr = sMyFileName.GetAt(i);
if (sBadChars.Find(cCurr) > -1)
{
replace it with our marker char
sMyFileName.Replace(i, cMarker);
}
}
sMyFileName.Remove(cMarker);
<pre>
To hell with those thin-skinned pillow-biters. - Me, 10/03/2001
|
|
|
|
|
Hi
Use MFC's 'CFile::Open' which will automatically
check for errors, and if there is an invalid file name
it will throw an expection and the
'CFileException::m_cause' will be 'CFileException::invalidFile'.
So u just need to go on creating the file and in case of
exception stop creating.
Best of Luck.
Kumar
|
|
|
|
|
a.x etc. are floats
float arg = (a.x - b.x / a.y - b.y);
this gives me an arg of -1,#IO while I want it to become 1
if I change the code to the following, which is of course the same thing:
float arg = (0.0f - 1.0f / 0.0f - 1.0f);
the compiler tells me:
error C2124: divide or mod by zero
when typing this message I solved it but still, this shouldn't matter. This is the line of code which works correct:
float arg = ((0.0f - 1.0f) / (0.0f - 1.0f));
is this a c++ bug? Do I have to put braces around all my variables?
WAVK
|
|
|
|
|
It's not a bug, division has higher priority than addition/subtraction. This is really basic math, it's not limited to C++.
|
|
|
|
|
When the compiler does the arithmetic, it completes the sums in operator precedence. different operators (*, / etc) are thus done in different orders, unless you use ()'s to change the order.
since the order is this (i think) .... * / + -
then your line:
float arg = (0.0f - 1.0f / 0.0f - 1.0f);
will do the divide operation first. Thus 1.0 / 0 is a divide by zero error.
it's good practise to always use parentheses to control the prescedence of your operations. suffiecient here would be:
float arg = (a.x - b.x) / (a.y - b.y);
Note that your original line,
float arg = (a.x - b.x / a.y - b.y);
since the ()'s were around the whole expression, they weren't doing anything at all.
Sorry to dissapoint you all with my lack of a witty or poignant signature.
|
|
|
|
|
I need to catch up some sleep it seems?! aaaaaaaaaaaaaaaaaaarg how could i be that stupid, of course I know that, aaaaaaaaaaaaaaaaaarg.... thanks for waking me up
WAVK
|
|
|
|
|
Maybe you need to become better at sleeping. I'm an expert at it
Sorry to dissapoint you all with my lack of a witty or poignant signature.
|
|
|
|
|
I posted this question a while back ago in some news groups but never got an answer... since this place is where all the experts hang out anyway I'm making a new go at it... so here goes...
Does anyone know the requirements for getting PDH to work on different versions of NT machines? PdhConnectMachine() gives a very general error message saying it can basically be anything from Charon not being inline with Pluto, humidity being too high in India or to more exactly quote the MSDN:
PDH_CSTATUS_NO_MACHINE
"Could be caused by the machine not being on, not supporting PDH, not being connected to the network, or having the permissions set on the registry to not allow remote connections or remote performance monitoring by the user."
So which is it?! I know from my own research that the 'Remote Registry Service' has to be running on Windows 2000 but what about NT4 and XP... and how come there's 12 inches in a foot?
// Anders
|
|
|
|
|
I must provide dll that will match to every language !!!
I did exctention dll that works well in vc but NOT in another.
after all the suggestions that I gets from the books and from you (and thanks!) I understood that the best way for me (as beginner at this subject) is to use the Wizard of ATL COM with suppot MFC)and imported in my mfc dll.
When I run it by client program (exe) the atl it works !
but the imported function (ShowDialog) dont performed. WHY ????????
------------------------------------------------------------
My steps:
1. I opened project: ATL COM Wizard. [DLL] [MFC Support]
2. I inserted to the library that created the file : MyMfcDll.dll
and attached to the ATL project the files : MyMfcDll.h , MyMfcDll.lib
3. I Added by wizard ATL class [MyClass] [single] [dual]
4. I added by wizard method [ShowMfcDialog] to IMyClass and fill it so :
___________________________________________
extern "C" __declspec(dllimport) void ShowDialog();
STDMETHODIMP CAtlObj::ShowMfcDialog()
{
AFX_MANAGE_STATE(AfxGetStaticModuleState())
AfxMessageBox(".....");
ShowDialog();
return S_OK;
}
-----------------------------------------------------------
Please Try HELP me !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
|
|
|
Your JOB is on the line and you've not bought a book after three weeks ? Sheesh.
I maintain that your best bet is to create a NEW dll, with MFC support if you must, and replicate the functionality of your non-COM dll from scratch. It's mainly cut & paste, but doing it that way means you don't need to worry about the other dll.
Did you trace into the function like I suggested ? What happened ? You've been asking this same question verbatim for two days so I presume you've done something about every suggestion you've recieved.
ATL is not stupid, it simply requires some effort to learn. Which is why I keep telling you to buy a book, because you're NOT going to learn ATL from a web post, or even MSDN unless you have time to spare.
Christian
|
|
|
|
|
1. I think that I must exctention dll because I need in : CDialog.
2. Is in my steps that I described it seems that is all right or something wrong or missing ?
3. When I trace into the function I see that it doesnt enter to the dll function.
4. Believe me that I try to learn it from books and that is what I unterstood that I have to do.
5. Please understand that all the subject of com/dll/atl was not known me untill two weeks all !!!
|
|
|
|
|
1. You can build a COM dll with MFC support - my understanding is that you're build one dll out of another. I don't know much about dll's, maybe you *do* need to do this. If I were you at this late stage I would probably consider that as you've asked the same question for days, you consider if MFC is the problem, do you need MFC support ?
2. Like I said, I don't know much about dll's, although I know a little about ATL.
3. So when you trace into the function that calls your dll, it brings up the AfxMessageBox, but you can't step into the function from your dll, it just goes over the top ? Given how dll's export their functions, doesn't that mean it's lookup table has a problem ?
4. I'm sorry, if you did in fact buy one of the books recommended, it didn't help you at all and as you never said, it was not obvious. I can only maintain that you should consider building it entirely in a COM server dll, regardless of MFC. If you only need MFC to bring up a dialog, bringing up a dialog using ATL is not very hard at all, Win32 is probably easier because of the mass of information available.
5. If your boss is going to sack you for not being able to impliment something you didn't know about two weeks ago, then he is an ass, and you can tell him I said so. It's been obvious all along that you're out of your depth ( and that is no insult, there are a myriad of technologies where I would be in the same boat, no-one knows everything ). Does your boss know you're in trouble ? Is your boss tech savvy at all ( can you talk in terms of ATL, or do you have to talk in terms of the pretty colours ? )
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
I trys now to build ATL without import the MFC DLL that I crated.
So
1. I going to resources and inserting Dialog.
2. I created class dialog::CDialog (possibility ?)
3. I added ATL class - simple.
4. I added to this ATL class object from the class dialog .
5. I added to this ATL class method that doind : dlg.DoModal();
I run it from client program and it is works so :
It shows the dialog of the method of ATL class (in number 5)
But when press OK or Cancel it is crush.
____________________________________________________-
Have I use only in ATL dialog or there are a way to works as I tried (Maybe have I added AFX_MANAGE_STATE somewhere)?
|
|
|
|
|
Is the ATL dialog class called CDialog ? The ATL Object dialog allows you to add a dialog box, is that how you did it ?
Your biggest problem is that when something crashes you bring up CP. People could help you more if you provided some info. Did you trace into the code to see what line crashed ? You should post some code, and also know where it crashed exactly. Then we could help you more. Why don't you email me your project, I'm at home right now playing Worms, and I'd be happy to bring it to a point that your ATL dialog comes up. Just zip it ( without any intermediate files, just the stuff I need to compile it ) and send to cgraus@viewbuild.com
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
I'm sorry, I'm going to bed. Maybe tomorrow night I'll have time to have a look for you if you decide to send it to me.
Christian
As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet.
Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.
|
|
|
|
|
In MSDN, it is said:
DllMain is a placeholder for the library-defined function name.
I do not know what means "placeholder" and "library-defined function name" here.
Can you show me an example or a description?
Thanks,
Maer
|
|
|
|
|
It means that you can name the entry point anything you want. The docs use "DllMain" as an example.
--Mike--
http://home.inreach.com/mdunn/
"....." -- Silent Bob
your with and
|
|
|
|
|
Thanks Mike!
I still have a question. I still do not know what means "library-defined".
Can you show me an example?
Best regards,
Maer
|
|
|
|
|
|
Thanks Mike!
Your answer is the one I am looking for. : )
Regards,
Maer
|
|
|
|
|
What is the function of "UNREFERENCED_PARAMETER" in DllMain?
Thanks,
Maer
|
|
|
|
|
1) It tells other people that may be maintaining your code that you purposely are ignoring a function parameter.
2) It avoids the level 4 warning about unused function parameters.
--Mike--
http://home.inreach.com/mdunn/
"....." -- Silent Bob
your with and
|
|
|
|