Re: c dll calling vb dll
From: Igor Tandetnik (itandetnik_at_mvps.org)
Date: 08/05/04
- Next message: Amir: "Re: problems using mysql, please help"
- Previous message: niu: "Error: the array is fixed or temporary locked"
- In reply to: ch5082: "Re: c dll calling vb dll"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 5 Aug 2004 11:30:04 -0400
"ch5082" <ch5082@discussions.microsoft.com> wrote in message
news:3875C954-5364-4B2D-AC69-B50FF3DF9FEE@microsoft.com
> I'm having problems with the variable initialization. The strings
> I'm passing back always seem to have the value I'm expecting plus a
> bunch of junk. Here's what I'm doing now. [code]
>
> BSTR sName=NULL;
> BSTR sDomain=NULL;
>
> if(g_oObjPtr->GetPlan(&sName,&sDomain))
> {
>
>
WideCharToMultiByte(CP_ACP,NULL,sName,SysStringLen(sName),sPlanName_out,
SysStringLen(sName)+1,NULL,NULL);
>
WideCharToMultiByte(CP_ACP,NULL,sDomain,SysStringLen(sDomain),sPlanDomai
n_out,SysStringLen(sDomain)+1,NULL,NULL);
SysStringLen does not account for the terminating NUL character. When
you tell WideCharToMultiByte to convert a buffer that does not have a
terminating NUL, it does not write NUL into the output either. So your
char* strings end up not being NUL-terminated.
Another issue - you tell WideCharToMultiByte that the destination buffer
is at least SysStringLen(sName)+1 bytes large. How do you know that?
There is no indication that the caller-provided buffer is large enough.
This code is asking for a buffer overrun.
--
With best wishes,
Igor Tandetnik
"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken
- Next message: Amir: "Re: problems using mysql, please help"
- Previous message: niu: "Error: the array is fixed or temporary locked"
- In reply to: ch5082: "Re: c dll calling vb dll"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|