I have a BSTR object that I would like to convert to copy to a wchar__t object. The tricky thing is the length of the BSTR object could be anywhere from a few kilobytes to a few hundred kilobytes. Is there an efficient way of copying the data across? I know I could just declare a wchar_t array and alway allocate the maximum possible data...
Here's the code I want to speed up. It's getting a value from an ADO recordset and converting it to a char*. But this is slow. Can I skip the creation of the _bstr_t?
_variant_t var = pRs->Fields->GetItem(i)->GetValue();
if (V_VT(&var) == VT_BSTR)
{
char* p = (c...
When maintaining a COM interface should an empty BSTR be treated the same way as NULL?
In other words should these two function calls produce the same result?
// Empty BSTR
CComBSTR empty(L""); // Or SysAllocString(L"")
someObj->Foo(empty);
// NULL BSTR
someObj->Foo(NULL);
...
OK, so I couldn't really think of an apropos title that summarizes this.
The IPrintPipelinePropertyBag interface has the method AddProperty which aptly enough "adds a property to a property bag."
http://msdn.microsoft.com/en-us/library/aa506384.aspx
AddProperty( [in, string] const
wchar_t *pszName, [in] const
VARIANT *pVa...
So far I've discovered I can convert incoming BSTRs to ANSI in two (of many?) ways, and I'm curious to know whether one is "better" than the other with respect to speed / efficiency etc.
The way I've been using for a while is use the USES_CONVERSION and W2A macros, e.g.
BSTR __stdcall F(BSTR p1, BSTR p2 ) {
USES_CONVERSION;
LP...
I am writing a C++ DLL that is called by an external program.
1.) I take an array of strings (as char *var) as an argument from this program.
2.) I want to iterate through this array and call a COM function on each element of the string array. The COM function must take a BSTR:
DLL_EXPORT(void) runUnitModel(char *rateMaterialTypeName...
Hi,
How can I pass a char * from C dll to VB
Here is sample code:
void Cfunc(char *buffer,int len)
{
BSTR buf_bstr = SysAllocString((BSTR)buffer);
VBptr.VBfunc(buf_bstr,len);
}
This function is not working, In actual some other values are sent to the VB rather than the actual value.
Can Anyone .. tell me how the solution for ...
I have a _bstr_t string which contains Japanese text. I want to convert this string to a UTF-8 string which is defined as a char *.
Can I convert the _bstr_t string to char * (UTF-8) string without loosing the Japanese characters?
...
I'm trying to send a COM object over a MSMQ message in C++. This is my object :
class ATL_NO_VTABLE CAnalisis :
public CComObjectRootEx,
public CComCoClass,
public ISupportErrorInfo,
public IDispatchImpl,
public IPersistStreamInit
{
private:
typedef struct {
DOUBLE size;
float color;
float light;
...
It's at least common practice to treat null BSTR (null WCHAR* pointer) as an empty string and design all the code manipulating BSTRs accordingly. Answers to this question say the same.
Where is this practice documented? Is there any official document describing this convention?
...
Suppose a method from a COM interface returns BSTR value. Am I right in my opinion that I must free it?
The code example at http://msdn.microsoft.com/en-us/library/aa365382(VS.85).aspx does not do that.
Who's wrong?
...
Hello Experts,
I have my certrequest as a PEM base64 data. See data below.
1) My understanding is that this is an ASCII data type and not in
UNICODE format. Please clarify.
-----BEGIN NEW CERTIFICATE REQUEST-----
MIIBTjCBuAIBADARMQ8wDQYDVQQDEwZ3dTAwMzEwgZ0wDQYJKoZIhvcNAQEBBQAD
gYsAMIGHAoGBAKP48eljetv3fVicT6g6hKjmLpsySJaZ/NnepEJEqtQQNbw...
Any ideas on how to make a BSTR out of an LPCOLESTR? Silly thing to get hung up on..
...
Hi,
I'm working with third-party COM object that has some of its methods passing values back as BSTR pointer. Since VBscript supports only Variant type attempts to use in a way like Object.Method(sMyString) reasonably end with "Type mismatch" error.
I suspect this error is generated by the COM object itself rather then VBscript interp...
Hi,
I have a string that starts out in a .Net application, is encrypted and stored in AD. It's then picked up by a native C++ app and decrypted to produce an array of bytes
e.g "ABCDEF" becomes 00,41,00,42,00,43,00,44,00,45 once it has been decrypted at the C++ end.
I need to take this byte array and convert it to the BSTR "ABCDEF" so t...
I have a _bstr_t variable bstrErr and I am having a CString variable csError. How do I set the value which come in bstrErr to csError?
...
I'm new to COM. What exactly is the advantage of replacing:
L"String"
with
CComBSTR(L"String")
I can see a changelist in the COM part of my .NET application where all strings are replaced in this way. Would like to know what is the need for this.
...
I'm confused about COM string assignments. Which of the following string assignment is correct. Why?
CComBSTR str;
.
.
Obj->str = L"" //Option1
OR should it be
Obj->str = CComBSTR(L"") //Option2
What is the reason
...
I have read that the following code causes memory leak. But did not understand why.
CComBSTR str;
pFoo->get_Bar(&str);
pFoo->get_Baf(&str);
How does it cause a leak when we are not allocating anything?
...
When allocating an empty BSTR, either by SysAllocString(L"") or by SysAllocStringLen(str, 0) you always get a new BSTR (at least by the test I made). BSTRs aren't typically shared (like Java/.NET interment) since they are mutable but an empty string is, for all intents and purposes, immutable.
My question (at long last) is why doesn't C...