c++ - CComBSTR memory allocation -
I have "const char * str" with very long strings. Let me know this one from CPP customer. Net com will be passed by the method which expects the BRST type. Currently I use it:
CComBSTR bstr = str;
It has the following problems:
- Sometimes this row is exited from the memory message
- When I pass bstr In the com class, it takes a lot of memory (more than string size), so it can be out of memory
Question:
- Am I converting CComBSTR wisely? Like
Any other suggestion has also been welcomed ...
If any method is passing BSTR
pass BSTR
then the only correct way.
You change char *
in BSTR
to MultibyteToWideChar ()
for conversion Win32 API function and memory allocation For the SysAllocStringLen ()
you can not go around it - you need SysAllocStringLen ()
for memory allocation because otherwise the COM server will fail if this call SysStringLen ()
.
When you use CComBSTR
and assign it a four *
, then the same sequence is run - Available as ATL header And you can see how to read it, how it works, so in reality, CComBSTR
actually sets the minimum of required tasks.
When you pass a BSTR
to a COM server CComBSTR :: operator, BSTR () const
is said to be wrapped in BSTR Anything that is not copied
- BSTR
body depends on the com server or the interop - they decide themselves whether they BSTR
body or copy it directly.
To solve your only memory exclusion, the condition is to change the COM interface so that it accepts some readers and requests the data through that reader.
Comments
Post a Comment