|
NS17 wrote: If it is less than the count you specified
What you mean here, find the length of the file and check it with the buffer size?
I appreciate your help all the time...
Eranga
|
|
|
|
|
try using CFile::GetPosition().
or what ns17 has suggested also holds good.
say for example, in your read, you specify x bytes to be read.
if the read function returns a value that is less than x then it means that, end of file is reached.
--------------------------------------------
Suggestion to the members:
Please prefix your main thread subject with [SOLVED] if it is solved.
thanks.
chandu.
|
|
|
|
|
Like this
char buffer[5000] ;
CFile ReadFile ;
whiel(1)
{
if( ReadFile.Read(buffer, 4) < 4 )
break; // End of file reached
}
Hope you got it...
- NS -
|
|
|
|
|
This tread is old now, but I have a clue on this. I'm try it in this way,
First find the length of the file in bytes. Then iteratively do the process within calculated number of bytes. The code is as follows.
<br />
int length = 0 ;<br />
CString str<br />
<br />
length = srf_ReadFile.GetLength()/sizeof(TCHAR) ;<br />
str.Format(_T("File size is %d bytes long."), length) ;<br />
AfxMessageBox(str, MB_OK) ; <br />
What you guys think about it, is there any efficient way to do it.
I appreciate your help all the time...
Eranga
|
|
|
|
|
Hi all,
I want to make 5 exe's from 1 project only....how to do it? suppose i want to make a set up program in which i want that a main exe that will take various exe's as input and path , a extractor, my uninstall exe and then a setup exe which will place all the given exe's at a mentioned place. I am not getting how to do it....can anybody help me in this....
Thanks in advance
|
|
|
|
|
Create configurations for each of your requirement.
In VS2005, got to "Build | Configuration Manager | Active SOlution COnfiguration | < New >".
Regards,
Paresh.
|
|
|
|
|
In 2005, you can also do this by right-clicking on the solution in Solution Explorer and then selecting Add => New Project
Judy
|
|
|
|
|
hello everybody,
I am saving some configuration in my custom class object.
amd now i want to store this object into file, so anybody know how can i write whole my custom object into file?
Please guide with code if possible.
thanks in advance
Manish Patel.
B.E. - Information Technology.
|
|
|
|
|
Basically you have to save the information to save by yourself at the time of application exit, and read it on the application loading.
What kind of configuration values are they?
- NS -
|
|
|
|
|
ya i know it but i want to write whole object of my custom class.
I know how to write string values but i dont know about object.
so please tell me how to write it to file?
thanks.
Manish Patel.
B.E. - Information Technology.
|
|
|
|
|
Have a look at serialization.
- NS -
|
|
|
|
|
Thanks for reply.
can you please give me any reference code on serialization because i am not understanding how to use serialization?
Manish Patel.
B.E. - Information Technology.
|
|
|
|
|
Please see the the below reply made by Paresh Chitte.
- NS -
|
|
|
|
|
Use CArchive class. Read here[^] for more information.
Regards,
Paresh.
|
|
|
|
|
Visual C++ 6.0
I am trying to open notepad with CreateProcess function.
function returns true.
Then i get CWnd* handle to the window of notepad by using FindWindow(..)
I get a CWnd* handle to the notepad window.
Now.. here is the problem code:
I try to set focus to the notepad by following command
handle->BringWindowToTop();
i get (MFC42D.DLL): 0xC0000005: Access Violation.
please help me resolve this problem
Ritesh
|
|
|
|
|
Do you have the same problem if you build your app for release?
Perhaps the "Mixed DLLs" section in this article[^] can be of interest.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
riteshsv wrote: Then i get CWnd* handle to the window of notepad by using FindWindow(..)
You do realize that this could result in a deadlock situation if Notepad is currently in a blocking situation, don't you?
While probably of less importance to you, it will also fail if your program is internationalized, because the caption will be different.
"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
|
|
|
|
|
Can you use of EnumWindow instead FindWindow?
|
|
|
|
|
Hi guys,
I've got a problem as follow.
Suppose we have a string class named MyString. This class has a constructor to construct a MyString object base on a char * like this:
<br />
class MyString<br />
{<br />
private:<br />
char *m_pData;<br />
int *m_iLength;<br />
<br />
public:<br />
MyString(char *s)<br />
{<br />
m_iLength = strlen(s);<br />
m_pData = new char[m_iLength + 1];<br />
strcpy(m_pData, s);<br />
}<br />
};<br />
And we have a main function like this:
<br />
void main()<br />
{<br />
char *p = new char[5];<br />
MyString s(p);<br />
}<br />
The question is: the p pointer is allocated only 5 char in the memory, but the strlen function can return a value bigger than 5 (depend on where it finds the '\0' char in the memory of pointer). So the MyString object can access unallocated memory. Does it safe? How can we solve this problem?
Best regards.
Lan hue sau ai lan hue heo
Lan hue sau doi trong heo ngoai tuoi
|
|
|
|
|
nmhuy wrote: So the MyString object can access unallocated memory. Does it safe?
As long as you don't write to the memory you haven't allocated, you're fine as long as strlen() finds a '\0' char within the virtual address space assigned to the process.
You won't get an access violation by reading addresses on the heap even if the memory hasn't been allocated.
nmhuy wrote: How can we solve this problem?
Well, it depends on how you want it to work.
Probably you can guess a maximum length of the strings and provide that as a default parameter to the constructor, e.g:
MyString( const char* pStr, int nMaxLength = 256 );
If the calculated length of the string exceeds the nMaxLength you could either treat is as an error and not copy the string and possibly throw an exception, or only copy nMaxLength chars of it. You would also have the possibility to make a new guess for the maximum string length for each string object constructed if you need to.
BTW, in your example you've declared the length member as a pointer to an integer...
I assume that it's really an integer in your code.
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
You're right. I had a typing mistake. m_iLength is an integer.
Thanks for you answer.
Lan hue sau ai lan hue heo
Lan hue sau doi trong heo ngoai tuoi
|
|
|
|
|
Hey Friends
I need the given below code converted to c++
<dllimport("uxtheme.dll", bestfitmapping:="False," callingconvention:="CallingConvention.Winapi," charset:="CharSet.Unicode," entrypoint:="#65" )=""> _
Private Shared Function SetSystemVisualStyle(ByVal pszFilename As String, ByVal pszColor As String, ByVal pszSize As String, ByVal dwReserved As Integer) As Integer
End Function 'Set the Visual style, for example Luna.msstyles
I tried
HMODULE hmodFonc;
DWORD Ordinal = MAKELONG(0, 65);
FARPROC Proc;
hmodFonc = LoadLibrary(_T("uxtheme.dll"));
if (!hmodFonc) {
_tprintf(_T("Err LoadLibrary: %ld\n"), GetLastError() );
return ;
}
Proc = (FARPROC)GetProcAddress(hmodFonc, (LPCSTR) &Ordinal);
if (!Proc ) {
//_tprintf(_T("Err GetProcAddress: %ld\n"), GetLastError() ); << err 127 ERROR_PROC_NOT_FOUND
return ;
}
However always it is not able to find the proc address.
The function is to change windws xp theme.
Need Help
Regards
|
|
|
|
|
vikrant kpr wrote: I need the given below code converted to c++
I didnt see any VB code in your post. Only a function declaration.??
|
|
|
|
|
yeah that's it
this is working & when called changes the windows theme
|
|
|
|
|