
Invalid Address specified to RtlValidateHeap in EXE Server
Hi:
I'm passing a BSTR (also tried passing a BSTR*) that must be converted to
an LPCTSTR. I got the conversion code from the MSDN sample "Implementing a
Simple MFC Client for an ATL Server". It seems to work OK. At least it
compiles and doesn't complain on run-time.
However, at the end of the method, after returning 0L, I get:
HEAP[MyApp.exe]: Invalid Address specified to RtlValidateHeap( 340000,
12f814 )
I suppose it has something to do with string clean up, LPCTSTR conversion
or something like that, but I can't make it out. Could you, please, help me?
STDMETHODIMP CIRServer::NewJob(/*[in]*/ BSTR* JobName, /*[out,
retval]*/VARIANT* pVariant)
{
// LPCTSTR name;
USES_CONVERSION;
//Update static text with new value
unsigned cmb;
if(JobName)
cmb= wcstombs(NULL, JobName, SysStringLen(JobName)) + 1;
else
cmb= 1;
// name = W2CT(JobName);
//_bstr_t name(JobName, FALSE); //necessary to avoid a memory leak
ImpJob* pJob = CreateJob (W2CT(JobName));
VariantInit (pVariant);
pVariant->vt = VT_BYREF|VT_VARIANT;
SAFEARRAY* psa = NULL;
SAFEARRAYBOUND bound = {1, 0};
psa = SafeArrayCreate (VT_VARIANT, 1, &bound);
if (psa == NULL)
return E_OUTOFMEMORY;
long i=0;
SafeArrayPutElement (psa, &i, &pJob);
pVariant->parray = psa;
return 0L;
Quote:
}
If I use _bstr_t name(JobName, FALSE), I get:
error C2040: 'name' : 'class _bstr_t' differs in levels of
indirection from 'const char *'
So, is it the conversion, the VARIANT*, or what?
Thanks a lot.
Best wishes. Javier.