void yourfuntion()
{
USES_CONVERSION;
BSTR bstr=SysAllocString(OLESTR("Hello")); // contains an ole string
2Byte
char* pArr = new char[20];
pArr=OLE2A(bstr); // ole to ansi conversion
delete [] pArr; // contains the ansi string 1 Byte
}
--
===============================
Alexander Nickolov
STL Panasonic
email: agnic...@geocities.com
===============================
Remo Brigger wrote in message <7b2tfp$hvk$1...@pollux.ip-plus.net>...
Remo
Alexander Nickolov wrote in message ...
char* pArr = new char[20];
// assigns a pointer allocated from the heap to pArr
pArr=OLE2A(bstr); // ole to ansi conversion
// assigns a pointer allocated from the stack using _alloca()
delete [] pArr; // contains the ansi string 1 Byte
// deletes the memory pointed to by pArr which points to the stack
// this will corrupt something...probably the stack frame.
deleting a pointer is not a problem IN GENERAL, but what you've done here
will definitely cause problems.
Note that had you done this:
char* pArr = new char[20];
delete [] pArr;
pArr=OLE2A(bstr);
It would work fine.
HTH
--
Reginald Blue | Opinions expressed here do not
Natural Language Understanding | necessarily represent those of
Unisys Corporation | my employer.
|-------------------------------
| My email address is wrong, you
r...@NOSPAM.trsvr.tr.unisys.com | need to remove the obvious.
Remo Brigger wrote in message <7b5dqd$f0r$1...@pollux.ip-plus.net>...
Remo, I simply didn't see the new operator :) Else I would have
scored TWO errors :) - the former - memory leak, the latter - GPF.
--
===============================
Alexander Nickolov
STL Panasonic
email: agnic...@geocities.com
===============================
Reginald Blue wrote in message ...