|
Depends on how you define "fast".
If you meant small code: use fopen fprintf and fclose.
If you meant fast writing: use Win32 file API or/and mapped files.
-Dominik
_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do??
|
|
|
|
|
Hello all,
When I use StreamOut feature of RichEditCtrl, I have a problem with large content. My StreamOut function always gets 2050 characters although my RichTextCtrl contains up to 300000 characters.
Please take a look on my code below and tell me why.
DWORD __stdcall MyStreamOutCallback(DWORD dwCookie,LPBYTE pbBuff,LONG cb,LONG *pcb)<br />
{<br />
USES_CONVERSION;<br />
LPWSTR lpUniText = T2W((LPTSTR)pbBuff);<br />
CString * psBuffer = (CString *)dwCookie;<br />
*psBuffer = CString(lpUniText);<br />
*pcb = wcslen(lpUniText);<br />
return 0;<br />
}<br />
<br />
CString GetSelText(CRichEditCtrl &rtf)<br />
{<br />
CString strOut;<br />
EDITSTREAM es;<br />
es.dwCookie = (DWORD)&strOut;<br />
es.pfnCallback = MyStreamOutCallback;<br />
rtf.StreamOut(SF_TEXT|SF_UNICODE,es);<br />
CHARRANGE cr;<br />
rtf.GetSel(cr);<br />
<br />
strOut = strOut.Mid(cr.cpMin,cr.cpMax-cr.cpMin-1);<br />
TRACE(_T("\ncpMax-cpMin-1 = %ld"),cr.cpMax-cr.cpMin-1);<br />
<br />
return strOut;<br />
}<br />
<br />
void CTestRTFView::OnButton1Click()<br />
{<br />
CRichEditCtrl &rtf = (CRichEditCtrl &)GetRichEditCtrl();<br />
CHARRANGE cr;<br />
rtf.SetSel(0,-1);<br />
CString str = GetSelText(rtf);<br />
}
Is my StreamOut function correct? Please give me a way to use StreamOut with a large content.
Thank you very much for your help.
|
|
|
|
|
Here's the methods that I use, which happily work for thousands of characters!
CString CRichEditViewEx::GetContent()
{
CString strContent = "";
EDITSTREAM es;
CMemFile memFile;
es.dwCookie = (DWORD) &memFile;
es.pfnCallback = StreamOutCallback;
GetRichEditCtrl().StreamOut(SF_RTF, es);
memFile.SeekToBegin();
char szBuff[GETCONTENT_BUFFER + 1];
memset(szBuff, 0, GETCONTENT_BUFFER + 1);
while(memFile.Read(szBuff, GETCONTENT_BUFFER) > 0)
{
strContent += CString(szBuff);
memset(szBuff, 0, GETCONTENT_BUFFER + 1);
}
return strContent;
}
DWORD CRichEditViewEx::StreamOutCallback(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
{
CMemFile *memFile=(CMemFile *)dwCookie;
memFile->WriteHuge(pbBuff,cb);
*pcb = cb;
return 0;
}
Note that here I am getting the RTF - to just get the text, you need to change the flag SF_RTF to SF_TEXT , like you have in your code - and of course add SF_UNICODE if required.
If you want to get just the selected text, which is what the line strOut=strOut.Mid(....) seems to imply, then instead of doing CString::Mid() , you can use the flag SFF_SELECTION along with SF_TEXT et al.
|
|
|
|
|
Hello,
I have followed your code, but I have a Debug Assertion Failed at line 102 of file filemem.cpp when it executes to line:
while(memFile.Read(szBuff, GETCONTENT_BUFFER) > 0)
Can you tell me what happens.
Thank you very much for your help.
|
|
|
|
|
I'm confused. Delving into the CMemFile code, it looks like the internal CMemFile buffer is NULL, which means that (memory shortage problems aside) the rich edit control has never called the callback to write to the file.
It might be worth putting a breakpoint before the offending line and taking a look at the memFile member variables to see if there is indeed a valid looking buffer in there!
If there is no buffer, it could be down to where you are calling the function from - could it be at a point where the rich edit control might have already cleared down the content and started destroying itself?
Just out of interest, what did you set GETCONTENT_BUFFER to? I set it to 4096.
Sorry I can't be any more help!
|
|
|
|
|
You use the compiler switch /Zc:forScope if you want standard C++ behavior for for loops with Microsoft extensions (/Ze). Standard behavior is to let a for-loop's initializer go out of scope after the for loop.
However, this switch APPEARS not to work if you are watching the value of a for-loop's initializer in a Watch Window
Consider the following code compiled with /Ze and /Zc:forScope:
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
<code>#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
float doug[3] = {0.0};
for (short i = 1; i < 3; i++)
{
doug[i] = 3.3;
} //next i
short i = 0;
short a = i;
cout << i << endl << a ;
return 0;
}</code>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Firstly, you get a compiler warning:
warning C4258: 'i' : definition from the for loop is ignored; the definition from the enclosing scope is used.
The warning is at the line:
<code> short i = 0;</code>
I claim that this warning is nonsense, since the definition of "i" should not exist at this point. How can you ignore something that does not exist?
Anyway, run the code past the for-loop and pause at the line:
<code> short i = 0;</code>
Note at this point that, according to the Watch Window
i = 3
a = -13108 (Why should "a" even exist at this point, albeit with a nonsense value?)
Now pause at the line:
<code> cout << i << endl << a;</code>
Note that the Watch Window says
i = 3
a = 0
In other words the Watch Window reports the value of "i" INCORRECTLY, whilst internally the program seems to have got the right idea.
Pinch yourself and see if you are not hallucinating with the line:
<code> cout << i << endl << a ;</code>
Yup ... both "i" and "a" really do seem to have value = 0, BUT the Watch Window STILL says that i = 3!
(Incidently disabling Microsoft extensions altogether with /Za fixes the Watch Window problem)
This is all very unsettling for a beginner programmer.
2 Questions:
1. Can anyone shed any light or comment? Am I missing something?
2. According to the Watch Window, why does "a" seem to exist before getting to the line:
<code> short a = i;</code> ???
Thanks to all,
Doug
Doug
|
|
|
|
|
Use gcc.
BuggyMax
|
|
|
|
|
I cannot use gcc in my code.
Benchmarking shows that gcc in my application, which is computation intensive, slows it down to 1/3 of the unmanaged version.
Doug
Doug
|
|
|
|
|
//This code works but the string is signed. How do I convert a large DWORD to a string format?
thanks
DWORD dw = 4294967281; //0xFFFFFFF1;
CString strNum;
strNum.Format("%d", dw);
DWORD dw2 = atol(strNum); //problem strNum looks like -15 and not 4294967281
ASSERT(dw == dw2);
|
|
|
|
|
|
%u - thank you very much!
|
|
|
|
|
I'm adding a new feature into my program that will move saved games (for Microsoft's Freelancer) to different folders. The problem is, saved games reside in each users' "My Documents\My Games\Freelancer\Accts\SingePlayer" folder, and I don't know how to find other users' My Documents folders. Is that possible? It's fine if the solution requires admin priviledges in 2000/XP.
|
|
|
|
|
Hi together,
I have written a thread last week concerning "CRecentFileList", but it seemed that nobody could help me, so I want to ask again for help:
Does anybody of you knows an nice article or an working example (MRUCombo doesn't work correctly for me) that could eventually helps me?
That would be very nice!
Best regards, Tobias
|
|
|
|
|
Hi together,
do you know a good Tutorial for me about how do Print arbitrary things, for example something like an Array of Integers, or some Strings, with MFC?
Neither I know a good tutorial, nor I have an idea how to address the printer!
Please, it will be very nice, if you can help me!
Best regards, Tobias
|
|
|
|
|
Once you have the printer's DC, use its TextOut() method.
|
|
|
|
|
Thanks for your Reply!
I found an article about printing with use of a CPrintDialog and other things at
www.c-plusplus.de
Greetings, Tobias
|
|
|
|
|
Hey All,
I am in need of some function or library that will allow me to intercept (or spy on) messages in a third-party application (essentially any application) similar to Spy++. I noticed an application posted here called InterSpy, but it uses hooks and you need to add code to your application to spy on messages. Spy++ obviously doesn't require this since you can spy on any application. Does anyone know how Spy++ works?
Tom
|
|
|
|
|
I think global hooks can be used without injecting any code into the target application. SetWindowsHookEx with dwThreadId set to 0 seems to watch on every thread within the desktop, from what the docs say.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I was thinking the same thing.
A global system hook should catch messages without any code in the target application. That's what a global hook does.
hey
|
|
|
|
|
|
I thought the source for Spy++ was came with the MS Platform SDK. Aren't there other articles here on CP about hooking into other apps. I'd also be looking on MSDN. I'm sure you'll find articles there on doing this stuff.
Neville Franks, Author of ED for Windows. Free Trial at www.getsoft.com
|
|
|
|
|
Take a look at the Winspector program in the free tools section here. Its a home grown version of spy which works a lot better in many ways. The only problem is that the source is not available, but you can get hold of the exe.
Roger Allen
Sonork 100.10016
Were you different as a kid? Did you ever say "Ooohhh, shiny red" even once? - Paul Watson 11-February-2003
|
|
|
|
|
how to get HTTP POST data before sending request from multipart/form-data encoded form ?
This kind of forms gives empty post data in this event, and headers parameter contains chaotic part of data sent, like this :
Content-Type: multipart/form-data; boundarrt/form-data; boundary=--------------7d3892
and that's all what is sent.
It must be some bug in IE (i have 5.0), or htmlview, but i couldn't find anything on net about this ?
Anybody has the idea what's wrong ?
Thank you
rrrado
|
|
|
|
|
You can not do this from view....
Pluggable protocol/filter is your best bet.
|
|
|
|
|
But how to make mime filter and attach it to one instance of webbrowser ?
I've never wrote any mime filter or pluggable protocol, but it seems to be only
permanent or tmporary, but both types seems to be global for all instances of IE. I don't want this filter to be called even if user is browsing in IE outside my application.
Thank you !
rrrado
|
|
|
|