|
Hi all,
In my application, I can read a file and process it to collect some data. To make my application I want to make only allowed to work on one file format. I mean my application read same type of file all the time, so the extension and file name length is fixed.
To confirm that what I have do is, get the file name from the full path with the extension. Then find the length and the extension. Check that both conditions are true with fixed file name length and the file extension.
Is that ok, I mean is that this is proper way to do it.
Thanks.
I appreciate your help all the time...
Eranga
|
|
|
|
|
Checking the file name and extension isn't always helpful. You may get a fake file with the same name and ext. So, better write your file with specific header at it's start. And whenever you open the file, verify the file with your header structure and data in it. If you found anything mismatch in the data, the file isn't yours! So, this makes you use flexible file name and extension. This could be more secured. I hope you got my point.
- Malli...!
|
|
|
|
|
what malli has suggested is good.
and for more security, you can also put the checksum at the end of hte file.
--------------------------------------------
Suggestion to the members:
Please prefix your main thread subject with [SOLVED] if it is solved.
thanks.
chandu.
|
|
|
|
|
Thanks for the both replay. But I'm not sure that is easy to me
This is the way I've done it.
<br />
void CSRFDBDlg::CheckFileName(CString FileNameToCheck)<br />
{<br />
CString withExt;
CString fileExt;
<br />
withExt = FileNameToCheck.Right(FileNameToCheck.GetLength() - (FileNameToCheck.ReverseFind('\\') + 1));
<br />
fileExt = withExt.Mid(14, 3);<br />
<br />
if( (withExt.GetAt(0) == 'G') && (withExt.GetLength() == 17) )<br />
{<br />
if( (fileExt.GetAt(0) == 's') && (fileExt.GetAt(1) == 'r') && (fileExt.GetAt(2) == 'f') )<br />
{<br />
CString str( _T("Selected Target:\n\n" + FileNameToCheck) );<br />
AfxMessageBox(str, MB_OK);<br />
GetDlgItem( IDC_READ )->EnableWindow( TRUE );<br />
}<br />
else<br />
{<br />
AfxMessageBox( "This file format is not support in this application." );<br />
}<br />
}<br />
else<br />
{<br />
AfxMessageBox( "This file format is not support in this application." );<br />
}<br />
}<br />
I appreciate your help all the time...
Eranga
|
|
|
|
|
If you use CArchive::Serialize it will check if the structure of the data are correct to the project it self.
I.E. you code this:
if (ar.IsStoring ())
{
ar << myObject.myInt;
ar << myObject.myDouble;
ar << myArray[x].myString;
}
and you save a file with those datas, if you afterwards try to read them and you put it in other way, like:
else
{
ar << myArray[x].myString;
ar << myObject.myDouble;
ar << myObject.myInt;
}
the programm will complain and say that the data are not readable. So there is an error coding, or the file is not from your application. Is very difficult to find a "fake" file with the same structure of data as the files from your application (probability will be inverse proportional to the ammount of data saved in your file).
With the CFile you dont have that support, so you should use the solutions above.
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
|
|
|
|
|
Thanks pal. How about if I check both structure(as you said here) and the way the file name organized(as my code). Is it good or bad.
I appreciate your help all the time...
Eranga
|
|
|
|
|
hello,
in my project i have to fix a formview in another dialog like
m_GAUserEnteredOption.Create(this, IDC_S_VIEW_USERENTEREDOPTION,
IDR_F6CP_MAINFRAME,
RUNTIME_CLASS(CGADocument),
RUNTIME_CLASS(CGAMainFrame),
RUNTIME_CLASS(CDigitalUserOption),
WS_CHILD | WS_VISIBLE, 0L);
but once i fix this in another dialog i cant destroy the window
and those controls which are under this frame and dialog is not accesible . how to over come this
"Men never do evil so completely and cheerfully as when they do it from religious conviction"
-Pascal
|
|
|
|
|
This is a simple assignment for my c++ class requiring us to convert some text in a char array inline, not using another array. My code compiles with no errors, but when I run the program nothing comes out. I guess somewhere I'm accidently overwriting the entire string to nothing but... yeah. Anyhow, in the array, the following changes are supposed to occur: th -> z, s -> z, and r -> rr. This, of course, requires the entire string to be shifted if in the cases of th -> z and r -> rr. Here is my code:
<br />
#include "stdafx.h"<br />
#include <br />
#include <br />
#include <br />
<br />
using namespace std;<br />
<br />
#define MAX_SIZE 100<br />
<br />
int getLength(char inputText[]);<br />
void moveLeft(char* inputText, int index);<br />
void moveRight(char* inputText, int index);<br />
<br />
<br />
void main()<br />
{<br />
<br />
char text[MAX_SIZE];<br />
<br />
cout << "Enter your words here: ";<br />
cin.getline(text, MAX_SIZE);<br />
<br />
int sizeText = getLength(text);<br />
<br />
int j;<br />
int k;<br />
<br />
for( j = 0, k = 0; j < sizeText; j++, k++)<br />
{<br />
if ( (text[j] == 't' || text[j] == 'T') && (text[j + 1] == 'h' || text[j + 1] == 'H'))<br />
{<br />
text[k]= 'z';<br />
moveLeft(text, k);<br />
j++;<br />
}<br />
else if (text[j] == 'r' || text[j] == 'R')<br />
{<br />
moveRight(text, k);<br />
text[k] = 'r';<br />
text[k+1]= 'r';<br />
k++;<br />
}<br />
else if (text[j] == 's' || text[j] == 'S')<br />
{<br />
text[k] = 'z';<br />
}<br />
<br />
}<br />
<br />
cout << "The new line is: " << text << endl;<br />
<br />
}<br />
<br />
int getLength(char inputText[])<br />
{<br />
int length = 0;<br />
while (inputText[length]!= '\0')<br />
{<br />
length++;<br />
}<br />
<br />
return length+1;<br />
}<br />
<br />
void moveLeft(char* inputText, int index)<br />
{<br />
for (int i = index; inputText[i] = '\0'; i++)<br />
{<br />
inputText[i] = inputText[i+1];<br />
}<br />
}<br />
<br />
void moveRight(char* inputText, int index)<br />
{<br />
for (int i = 100; i > index; i--)<br />
{<br />
inputText[i] = inputText[i-1];<br />
}<br />
}<br />
Any help that you could provide would be greatly appreciated! Thank you!
-Sam
|
|
|
|
|
I guess here is the mistake :
for (int i = index; inputText[i] = '\0'; i++)
you're assigning it ! Correct it as :
for (int i = index; inputText[i] == '\0'; i++)
Better keep habit of placing constants at left side of '==' and variables at right side while comparing (conditions). i.e.
for (int i = index; '\0' == inputText[i]; i++)
This would raise compiler error itself, if you put single '=', rather double '=='.
- Malli...!
|
|
|
|
|
It's a common mistake to simply look at a program's output in determining if it's correct or not. Instead, you should use the debugger and step through each line of code to verify whether or not it's doing what you expect. Using that approach, you can easily narrow the problem to a statement or two.
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
hai,
i want to create a thread pool which is having atleast 10 threads,
Normally we are creating threads using Createthread()API,
But how to create pool..and all...?
is any body knows reply me...
Thanks.
Mani
Born to win...!
|
|
|
|
|
|
hai..
thanks for reply,
one doubt....is IOCP method is like a thread pool method...or...what?
if i am using an IOCP method any thread pool will get create..? or...?how it is..?
could u pls tell me short and sweet...
Born to win...!
|
|
|
|
|
D.Mani wrote: if i am using an IOCP method any thread pool will get create..?
With IOCP, you are responsible for creating a pool of threads.
Any thread waiting on GetQueuedCompletionStatus() is part of the IOCP's "thread pool".
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
|
Hi,
Please post any help on parsing the excel file.
Regards,
Mayank
|
|
|
|
|
|
Hey Guys,
I'm working on a graphics app. There will be a form that allows the user to find/select a image from hundreds of stored art. My question is: How can I "load" hundreds of images effeciently? I know MS gives you a listviewbox to work with but it is terribly slow and cumbersome when dealing with so many images.
Popular graphics programs like PrintShop gives you hundreds of images in one area with seemingly no load time. Any tips on how to accomplish this?
Richard
may your code be error free.
(okay, maybe two lines.)
|
|
|
|
|
I have seen a lot of samples around which passes the processing to a thread. This will make your application still available for the user to interact with while the thread processes the loading of image. The rest will rely on your algorithm of loading each image to the form. Optimize your codes for faster processing.
|
|
|
|
|
Hi all,
Can u pls tell me how to mount any disk mage file to any folder.
How we can mount any file?pls tell me it is highly obliged me.
Thanks in Advance
Bhaskar
|
|
|
|
|
hi all,
i'm using ADO and datagrid in my project, which is working fine in my machine. But when i made a setup and ran in another machine it was not working , there is problem in loading the ADO or data Grid. DSN name is coming correctly since i included the code for that when i made set. i also included the all the MFC dll(like MFC42.dll,etc) which i used to include.
Should i include any other dlls or any registry entry when i use these(ADO n data Grid ) when i make setup?
kindly reply,
thanks in advance...
||SnAkeBed||
|
|
|
|
|
Use the vc tool "Depends" you already have to find all the dlls your progam depends on.
|
|
|
|
|
thankyou for ur kind reply..i'm trying with that...will get back to u soon..
||SnAkeBed||
|
|
|
|
|
i tried with all the dll specified but the ado part is not working.it showed me to add kernel32.dll,ole32.dll and i have included the other 5 common dlls. but its not working ..could u pls tell me if i need to include any other dll to make the ado work
||SnAkeBed||
|
|
|
|
|
Hi all,
Actually i need to create to virtual drive for hard disk. i am trying to fisrt create Disk Image File , then mount this disk image file and use it as virtual drive. Can anybody tell me how to create disk image file or .iso file of any drive.Pls help me. It is highly obliged to me.
Thanks in advance
Bhaskar
|
|
|
|