|
Please be aware that you should NOT use OLE2A in a tight loop.
This is will propably crash:
void main()
{
USES_CONVERSION;
LPSTR sz="";
BSTR bstr = L"Goodbye, World...";
for (int i=0 ; i<100000 ; i++)
sz = OLE2A(bstr);
}
The reason is that OLE2A allocates memory on the stack for performance reasons, so you will run out of stack space if you do not take care to leave scope once in a while.
Instead, put your OLE2A macro in a separate function, where it is certain that it will not be called several times without leaving scope - or use dynamically allocated mamory (slower but safer).
Christian Skovdal Andersen
|
|
|
|
|
Just one quick comment on the ATL convertion macro's.
They alloc the string on the stack, using _alloca(), so they are no good for long strings, or when used in a loop...
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
Yeah, right. But there is a ocscpy() function to copy converted string into a pre-allocated memory.
Best regards,
-----------
Igor Soukhov (Brainbench/Tekmetrics ID:50759)
igor_soukhov@yahoo.com | ICQ:57404554 | http://siv.da.ru
|
|
|
|
|
|
|
Where do you find that function?
It's not documented anywhere in the MSDN Libaray...
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
Try to "Search" Tab in MSDNL. =)
ps: I've faced this function when I've been programming SnapIn.
ps2:here is the local address in my hard disk: (but I'm not sure that URL will be correctly displayed in forum):
mk:@MSITStore:C:\Program%20Files\Microsoft%20Visual%20Studio\MSDN\2000OCT\1033\period99.chm::/html/VC99A01.htm
Best regards,
-----------
Igor Soukhov (Brainbench/Tekmetrics ID:50759)
igor_soukhov@yahoo.com | ICQ:57404554 | http://siv.da.ru
|
|
|
|
|
Found it
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
Hi Andres,
You A2OLE isn't good for use in long strings ?
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
If you use a standard stacksize and convert more than 1 mb with the ATL macro's, you get a stack overflow error, and your app. crashes...
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
So, if my data was more 1 MB then i must use _alloca() ?
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
No, it means you should change stack size. (in linker's options)...
ps: it's a never-ending thread =)
Best regards,
-----------
Igor Soukhov (Brainbench/Tekmetrics ID:50759)
igor_soukhov@yahoo.com | ICQ:57404554 | http://siv.da.ru
|
|
|
|
|
I don't think changing stack size is such a good idea.
If you change data you don't know the size of, at compiletime, you never know if your program works...
ps: it's a never-ending thread =)
Yep
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
Nope, the ATL conversion macro's uses _alloca(), which allocates on the stack.
If you want to convert, say 5 mb, you cannot use theese macro's, but have to do it in another way, where you can allocate your memory on the heap...
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
A2OLE allocate memory from stack ?
Or do you mean SysAllocString for BSTR strign ???
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
A2OLE allocate memory from stack?
Yes
- Anders
Money talks, but all mine ever says is "Goodbye!"
|
|
|
|
|
Good, so how can i allocate memory from heap for A2OLE ?
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
Hi all.
What is Requery() ???
Is it for refresh recordset ?
So, when i add/new/delete/edit each record, i must use it ?
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
G'day Hadi,
Requerying a recordset is functionally similar to closing and re-opening the recordset without some of the overhead.
It's useful for those situations where you open a recordset which is sorted on a particular field. Now, say you add some records to the set. These new records 'appear' at the end of the recordset and not necessarily in their properly sorted position in the recordset. Just call Requery() and all of the records will be re-sorted.
I hope this makes sense.
Steve
|
|
|
|
|
Hi steve.
Thank you for useful answer ...
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
hi,
I like to know how can the save dialog can appear when i click on the close button to close my application.
Thanks
Ehsan
Ehsan Behboudi
|
|
|
|
|
I do it in an MDI App in my MainFrame OnClose handler like this:
CWinApp* pApp = AfxGetApp();
POSITION posTemplate = pApp->GetFirstDocTemplatePosition();
while (posTemplate)
{
CDocTemplate* pTemplate = pApp->GetNextDocTemplate(posTemplate);
POSITION posDocument = pTemplate->GetFirstDocPosition();
while(posDocument)
{
CDocument* pDoc = pTemplate->GetNextDoc(posDocument);
if (pDoc)
{
CGrausPaintDoc* pGPDoc = (CGrausPaintDoc*) pDoc;
if (!pGPDoc->m_bSaveSinceLastChange)
{
CString s;
if (pGPDoc->m_Filename.GetLength()>0)
s.Format("%s - save before close ?",pGPDoc->m_Filename);
else
s = "Untitled - save before close ?";
DWORD response = AfxMessageBox(s,MB_YESNOCANCEL | MB_ICONQUESTION);
switch (response)
{
case IDYES:
pGPDoc->OnSaveDocument(pGPDoc->m_Filename);
case IDNO:
pGPDoc->m_bSaveSinceLastChange = true;
pGPDoc->OnCloseDocument();
break;
case IDCANCEL:
return;
}
}
}
}
}
Most of this code is just to step through all the open documents - if you have an SDI app, you just need to get the Doc *, check a flag you set for changes (users will hate being asked to save if they have not done anything to the document ) and call OnSaveDocument. You'll note I also allow the user to press cancel - if they are being prompted they should get a chance to decide not to close the program.
Christian
#include "std_disclaimer.h"
People who love sausage and respect the law should never watch either one being made.
The things that come to those who wait are usually the things left by those who got there first.
|
|
|
|
|
Wasn't standard MFC implementation enough? And what's difference between m_bSaveSinceLastChange and CDocument::SetModifiedFlag/IsModified?
Tomasz Sowinski -- http://www.shooltz.com.pl
|
|
|
|
|
I presume you're telling me MFC has a flag built in that does the same thing ? The difference then would be one of control, but I admit to having vague recollections of the flag you're talking about and not knowing about it at all when I implimented the code I posted.
Christian
#include "std_disclaimer.h"
People who love sausage and respect the law should never watch either one being made.
The things that come to those who wait are usually the things left by those who got there first.
|
|
|
|
|
Just call CDocument::SetModifiedFlag(TRUE) when your document changes and all saving/filename prompting will be done by MFC. It's already there.
Tomasz Sowinski -- http://www.shooltz.com.pl
|
|
|
|