|
Good question ... without an answer.
The physics has its limits, and computer aren't paragnostic.
You have only two chances: know the size of what you are receiving in advance (and allocate the required) or, "guess it" and store as you can. You may waste something, or you may be required to relocate.
In both of the cases, dynamic allocation must be used (so an on-stack array cannot help).
There are dynamic memory allocation operations (search for "new and delete") or dynamic allocating classes (see std::vector).
Search for their documentation.
2 bugs found.
> recompile ...
65534 bugs found.
|
|
|
|
|
Depending on how you are getting the content the answer is different. Reading from a file is simple.
But, if you are getting the website content from a web server then all you have to do is parse the HTTP return headers for the Content-Length header option. This will give you the size of the buffer that is required. From here you can make the new buffer and store the rest of the web page into the newly allocated buffer, or you can take the size and resend the same request after finding out the required buffer size. Skipping the headers by looking for \r\n\r\n in the buffer and once this is found to begin storing the website contents.
So, in both cases you need to dynamically allocate the buffer as stated before, but it all depends on how you are reading the website content, from file or from a web server.
|
|
|
|
|
See the remarks section here[^], you should always check the return values of system calls to see whether they succeeded or not. In the case of recv it will tell you if the message cannot be completely transferred to the buffer. You should re-allocate your buffer to a larger size and try again until you are able to read the entire message.
It's time for a new signature.
|
|
|
|
|
Thanks for all answers and thanks to Richard, that will sure do the job for me!
|
|
|
|
|
I have a program that embeds Word through DsoFramer, but I need to know which version (2000/2003/XP/2007/2010) is installed because I need to adjust some things depending on the installed version.
Does anyone know how to do that? I have a pointer to the CApplication interface, and I can probably get any interface that's needed.
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
If you can get the path to Word's executable you might try using GetFileVersionInfo[^], this is just an idea, am not sure if Word's executable(s) actually contain(s) this or not, but you can check.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> "It doesn't work, fix it" does not qualify as a bug report. <
> Amazing what new features none of the programmers working on the project ever heard of you can learn about when reading what the marketing guys wrote about it. <
|
|
|
|
|
I did find an article via Google some time ago which described it, but unfortunately I cannot remember how (maybe "office registry keys" or something). However if you look at a key similar to
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\11.0\Registration\{91130409-6000-11D3-8CFE-0150048383C9} you can find the values. You may need to enumerate some of the keys looking for "Office" etc but it should not be too difficult.
It's time for a new signature.
|
|
|
|
|
There is 'Version' property on CApplication interface.
Moreover, DsoFramer is no longer recommended or supported by Microsoft. It has several known issues with modern office applications.
|
|
|
|
|
Thank-you kindly.
The following VBA code gives me word version as being 12 (when using office 2007)
Sub getWordVer()
Dim wordApp As Object
Set wordApp = CreateObject("Word.Application")
wordApp.Visible = True
wordVer = wordApp.Version
MsgBox ("Word version: " + Str(wordVer))
End Sub
modified on Friday, July 16, 2010 4:01 AM
|
|
|
|
|
Thanks, this seems the best solution. Can you tell me what the known issues are? I'd like to know to see if they will affect my project.
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
as you know, DsoFramer appeared in msdn KB articles as a sample of OLE on office applications. Latest office applications are actually not meant to be embedded. DsoFramer was declared as dead and no longer available in msdn samples.
One way to embedd office applications is to load them inside web browser control and do some registry modifications to force IE to embedd office applications. Still i think you will be missing some features like ribbon control in Office 2007 and 2010.
modified on Wednesday, July 21, 2010 10:41 AM
|
|
|
|
|
Hi All,
I am using CreateFile to open a specific file which will be accessed by multiple instance of same process simultaneously. This time function getting failed and GetLastError() is returning the following error.
"The process cannot access the file because it is being used by another process."
This is how i called the function
hFile = ::CreateFile( csFileName_i.operator LPCTSTR(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
if( INVALID_HANDLE_VALUE == hFile )
{
CString csErr;
csErr.Format( _T("Failed to open File**** Error code = %d"), GetLastError());
AfxMessageBox( csErr );
return bRet;
}
I need to open the same file simultaneously by different process.
Please help me.
-Cvaji
modified on Thursday, July 15, 2010 9:30 AM
|
|
|
|
|
Is one of your processes writing to the file (looking at your other question)? In that case you need to specify the sharing mode there too.
|
|
|
|
|
Cvaji wrote: hFile = ::CreateFile( csFileName_i.operator LPCTSTR(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );if( INVALID_HANDLE_VALUE == hSMPFile )
The return value of the CreateFile is stored in hFile , but you have checked the INVALID_HANDLE_VALUE aganist hSMPFile file. Is it really like that in the code or its just a typo?
|
|
|
|
|
sorry my friend..its just a mistake..
|
|
|
|
|
Even though my application is only doing the file read,
::CreateFile( csFileName_i.operator LPCTSTR(), GENERIC_READ, FILE_SHARE_READ|<big>FILE_SHARE_WRITE</big>, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
this made it work. Strange
|
|
|
|
|
how can I add Gmail | hotmail support to my MFC application if it is possible?
|
|
|
|
|
If you want to read and write emails, you can host a WebBrowser control[^] in a dialog or view.
|
|
|
|
|
Is there a more straight forward way may be through using a library or something like that?
|
|
|
|
|
|
|
The link isn't working for me.
|
|
|
|
|
|
Hi,
We are using Microsoft provided DOM parser - MSXML2 version 4(or 40)
When we are saving XML file, we are generating whole new file including all nodes and elements. Size of XML file is 3.5 MB. So it is taking 350 MB memory (both virtual as well as physical) Once save is done we are releasing all the XML objects. But there is no change happening in memory. So every consecutive save keeps on increasing memory by 350MB (approx) After 3-4 save we have to restart application again.
We have seen that if we minimize the application physical memory is coming back to original size (mean additional 350MB is getting reduced) but virtual memory is not changing. I think may be OS have reserved that place for application as memory cleaning is not done properly. But we have make sure that we have release all the memory we use.
Some where on some forum we seen a work around like this,
VARIANT_BOOL bstatus;
m_pXMLDomDoc->loadXML(CComBSTR(""), &bstatus );
Release(m_pXMLDomDoc);
That guy suggested that after you release saved document try to load a blank file. It will remove uncleaned area. But there is not much improvement. Please let me know if someone can help me.
|
|
|
|
|
Using which tool did you check the Memory usage? If you checking this from the task manager of window XP, I must say that you should consider only the VM usage, the memory usage it specifies is actually Working Set.
I dont remeber excatly, but there was problem with DOM parser such that it will release the memory completely only when the thread( that created DOM objects are created) is terminated. You can try like, create a dedicated thread to read the data from the XML and once it is done, end that thread and check whether the memory is back to normal or not( VM size, not Memory usage ).
|
|
|
|