Cyber-Drugs
asked on
Converting a CString into an Array
Hi guys,
I have this line of code:
CString cszArg2= pDispParams->rgvarg[0].bst rVal;
But instead of storing a CString, I am looking to store an array. Any ideas on what I need to do to get this working? This is partially related to another question I have open, but is not the same question.
Cheers!
I have this line of code:
CString cszArg2= pDispParams->rgvarg[0].bst
But instead of storing a CString, I am looking to store an array. Any ideas on what I need to do to get this working? This is partially related to another question I have open, but is not the same question.
Cheers!
ASKER
Hi,
Unfortunately I got an error with that one:
C:\Documents and Settings\Administrator\Des ktop\Brows er\CustomB rowser\Cus tomBrowser \Idispimp. cpp(383) : error C2039: 'auto_ptr' : is not a member of 'std'
If it at all helps, full details of the function this belongs to can be found here:
https://www.experts-exchange.com/questions/22067364/Custom-Browser-Issue.html
Cheers!
Unfortunately I got an error with that one:
C:\Documents and Settings\Administrator\Des
If it at all helps, full details of the function this belongs to can be found here:
https://www.experts-exchange.com/questions/22067364/Custom-Browser-Issue.html
Cheers!
See http://www.codeproject.com/string/ctokenex.asp ("String Tokenizer Class (CTokenEx)"), this one will help you to break a string down into an array. But, since you deal with filenames, that might be problematic depending on the which delimiter tokens you use.
CString strText = "Puranik";
char * chText = strText.GetBuffer(1);
char * chText = strText.GetBuffer(1);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
std::auto_ptr requires
#include <memory>
but you could use a regular pointer instead as long as you call delete.
But certainly as Mahesh suggests, there is no need to copy the string necessarily.
#include <memory>
but you could use a regular pointer instead as long as you call delete.
But certainly as Mahesh suggests, there is no need to copy the string necessarily.
Is CStringArray any use?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi guys,
I ended up making a function to solve this, here is what I got:
CString* CCustomBrowserDlg::CB_GetA rray(VARIA NT vMyValue, int nArg2)
{
CString* aEndArray = new CString[nArg2];
int pos = 1;
CComPtr<IDispatchEx> pDispEx;
HRESULT hr=vMyValue.pdispVal->Quer yInterface (IID_IDisp atchEx,(vo id**)&pDis pEx);
DISPID dispid;
// get the DISPID of the first item.
hr = pDispEx->GetNextDispID(fde xEnumAll, DISPID_STARTENUM, &dispid);
while (hr == NOERROR)
{
// get the item name
CComBSTR bstrName;
hr = pDispEx->GetMemberName(dis pid, &bstrName);
// get the item value
CComVariant vValue;
DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
hr = pDispEx->InvokeEx(dispid, LOCALE_USER_DEFAULT,
DISPATCH_PROPERTYGET, &dispparamsNoArgs,
&vValue, NULL, NULL);
if (pos <= nArg2)
{
switch (vValue.vt)
{
case VT_I4:
// value is integer
char buf[5];
itoa(vValue.iVal, buf, 10);
aEndArray[pos-1] = buf;
break;
case VT_BSTR:
// value is string
aEndArray[pos-1] = vValue.bstrVal;
break;
}
}
pos++;
//get the DISPID of the next item.
hr = pDispEx->GetNextDispID(fde xEnumAll, dispid, &dispid);
}
return aEndArray;
}
I ended up making a function to solve this, here is what I got:
CString* CCustomBrowserDlg::CB_GetA
{
CString* aEndArray = new CString[nArg2];
int pos = 1;
CComPtr<IDispatchEx> pDispEx;
HRESULT hr=vMyValue.pdispVal->Quer
DISPID dispid;
// get the DISPID of the first item.
hr = pDispEx->GetNextDispID(fde
while (hr == NOERROR)
{
// get the item name
CComBSTR bstrName;
hr = pDispEx->GetMemberName(dis
// get the item value
CComVariant vValue;
DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
hr = pDispEx->InvokeEx(dispid, LOCALE_USER_DEFAULT,
DISPATCH_PROPERTYGET, &dispparamsNoArgs,
&vValue, NULL, NULL);
if (pos <= nArg2)
{
switch (vValue.vt)
{
case VT_I4:
// value is integer
char buf[5];
itoa(vValue.iVal, buf, 10);
aEndArray[pos-1] = buf;
break;
case VT_BSTR:
// value is string
aEndArray[pos-1] = vValue.bstrVal;
break;
}
}
pos++;
//get the DISPID of the next item.
hr = pDispEx->GetNextDispID(fde
}
return aEndArray;
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Have you tried that with OLE2CA as shown above ?
ASKER
itsmeandnobodyelse,
>>>> CString cszArg2= pDispParams->rgvarg[0].bst rVal;
has not disappeared, I merely parse that value into the function above, and it outputs an array for me.
mahesh1402,
I will be trying the other methods once I finish off a few bits of work in the office, and then will get back to you on the results, but wanted to let you all know that it's no longer urgent, as I have a working solution. :)
Cheers!
>>>> CString cszArg2= pDispParams->rgvarg[0].bst
has not disappeared, I merely parse that value into the function above, and it outputs an array for me.
mahesh1402,
I will be trying the other methods once I finish off a few bits of work in the office, and then will get back to you on the results, but wanted to let you all know that it's no longer urgent, as I have a working solution. :)
Cheers!
You can use the same thing.
CString cszArg2= pDispParams->rgvarg[0].bst rVal;
After this
cszArg2.GetBuffer(1) will return an array.
CString cszArg2= pDispParams->rgvarg[0].bst
After this
cszArg2.GetBuffer(1) will return an array.
memcpy(cszArg2.get(), pDispParams->rgvarg[0].bst