Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String from VB to C++ ATL and backwords.... 1

Status
Not open for further replies.

yaronb

Programmer
Jan 6, 2001
13
IL
Hi...
I'm trying to pass a string (a text field) to a Property in C++.
I have managed to do so with numbers by creating a property with "long" type.
I have tried to add a new property with a BSTR type so I'll be able to deliver a string - but - it crashes...

Can any one help me ? - all I want is to pass a text field from VB to the property in C++...

Thanks...
 
Here is some code you might study as an example. It uses ATL, accepts a BSTR and converts it to a char *

#include "atlconv.h"

STDMETHODIMP CLogisticObj::SetAsExcluded(BSTR ExcludedFieldName)
{

USES_CONVERSION;
const char *tmp1;
char variable[MaxString];

tmp1 = W2CA(ExcludedFieldName);
strcpy(variable, tmp1);

for (int i = 0; i < pm_columns; i++)
{
if ( strcmp(pm_fields.name, variable) == 0 )
{
pm_fields.classification = excluded;
break;
}
}

return S_OK;
}
 
BSTR is a bouble byte for a character string.
char* x = &quot;hello&quot;;
wchar_t* wx = L&quot;hello&quot;;
//wchar_t* is the same as unsigned short
//and the same as BSTR, pay attention on L
also when you pass a BSR as a parameter pass it in a SysAllocString(L&quot;hello&quot;) instead of a L&quot;hello&quot;. All the functions which work with wchar_t* (it means UNICODE, not ANSI) are the same as for ANSI but begins usually with wcs instead of str, for example for ANSI is strcpy but for UNICODE is wcscpy. John Fill
1c.bmp


ivfmd@mail.md
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top