Invalid argument to SysFreeString causing crash
Sam Gentile -- sgentile@gensym.com
Tuesday, January 14, 1997
Environment: VC++ 4.02b, Windows NT 4.0
Mike, Help!
I have this Win32 OCX that I have building with MFC. I have an OCX Method,
that when it gets called crashes any OLE Container such as VB and causes
the following BoundsChecker error:
Invalid argument
SysFreeString, HANDLE: 0x0015345C
Bad handle
The stack shows this happens on the SysFreeString line of PushStackArgs:
ASSERT(pArgTemp->vt == VT_BSTR);
BSTR bstrW = pArgTemp->bstrVal;
pArgTemp->bstrVal = AfxBSTR2ABSTR(bstrW);
here->>>>SysFreeString(bstrW);
The stack is:
CCmdTarget::PushStackArgs(unsigned char * 0x0012f64c, unsigned char *
0x100b55a8, void * 0x0012f6f0, unsigned short 3, tagDISPPARAMS *
0x0012f76c, unsigned int * 0x0012f7a0, tagVARIANT * 0x0012f660) line 690
CCmdTarget::CallMemberFunc(const AFX_DISPMAP_ENTRY * 0x100b3788, unsigned
short 1, tagVARIANT * 0x00000000, tagDISPPARAMS * 0x0012f76c, unsigned int
* 0x0012f7a0) line 956 + 36 bytes
COleDispatchImpl::Invoke(COleDispatchImpl * const 0x017c12f0, long 10,
const _GUID & {...}, unsigned long 1033, unsigned short 1, tagDISPPARAMS *
0x0012f76c, tagVARIANT * 0x00000000, tagEXCEPINFO * 0x0012f828, unsigned
int * 0x0012f858) line 1401 + 28 byt
BCK32API! 00b4ec30()
My OLE Method is:
long CG2GateCtrl::G2Connect(LPCTSTR sMachineName, LPCTSTR sPortNumber)
{
gsi_int lStatus;
char *initialization_string = "Anything"; // create a unique string here
int connection = 0; // allocate a new connection index
connection_initialization_string_table[connection] = initialization_string;
// All calls in the GsiInterface class are thread-safe
lStatus = m_pMyGsiInterface->GsiInitiateConnection(NULL, NULL, 0, "T",
(char*)sMachineName,
(char *)sPortNumber,
initialization_string);
}
This is happening in the Invoke, so it's as soon as this OLE Method is
called/invoked. I thought this would be solved by using the BSTR data type
to eliminate this crash, but I couldn't figure out how to convert from
LPCTSTRs to BSTRs. I asked on the microsoft.public.vc.mfcole newgroup and
someone asked me why I was even wanting to use BSTRs. They said:
You very rarely need a by-reference BSTR (which is what you have is you
have a BSTR FAR*).
I don't know what you are trying to do with this parameter. The OLE Events
tab is used to describe an event you are firing from a control to a
container. When you want to send a string parameter to the event handler,
you generally select the LPCTSTR data type selection. For such parameters
MFC applications, UNICODE and ANSI, will take your string (in ANSI for ANSI
builds or in UNICODE for UNICODE builds) and properly convert it, as
necessary to a BSTR.
I thought BSTRs were THE OLE String Data type for dealing with OLE
Automation/OCXs especially dealing with VB? Can anyone help me (Mike B?)
figure out why I'm getting this problem. I have a code deadline tommorrow!
Thanks,
Sam
Jim Murphy -- jim.murphy@aspentech.com
Thursday, January 16, 1997
I would look at the local string assignment:
char *initialization_string = "Anything"; // create a unique string here
consider using:
BSTR initialization_string = SysAllocString("Anything");
and pass the BSTR!
>Environment: VC++ 4.02b, Windows NT 4.0
>
>Mike, Help!
>I have this Win32 OCX that I have building with MFC. I have an OCX Method,
>that when it gets called crashes any OLE Container such as VB and causes
>the following BoundsChecker error:
>Invalid argument
>SysFreeString, HANDLE: 0x0015345C
>Bad handle
>
>The stack shows this happens on the SysFreeString line of PushStackArgs:
>ASSERT(pArgTemp->vt == VT_BSTR);
>BSTR bstrW = pArgTemp->bstrVal;
>pArgTemp->bstrVal = AfxBSTR2ABSTR(bstrW);
>here->>>>SysFreeString(bstrW);
>
>The stack is:
>CCmdTarget::PushStackArgs(unsigned char * 0x0012f64c, unsigned char *
>0x100b55a8, void * 0x0012f6f0, unsigned short 3, tagDISPPARAMS *
>0x0012f76c, unsigned int * 0x0012f7a0, tagVARIANT * 0x0012f660) line 690
>CCmdTarget::CallMemberFunc(const AFX_DISPMAP_ENTRY * 0x100b3788, unsigned
>short 1, tagVARIANT * 0x00000000, tagDISPPARAMS * 0x0012f76c, unsigned int
>* 0x0012f7a0) line 956 + 36 bytes
>COleDispatchImpl::Invoke(COleDispatchImpl * const 0x017c12f0, long 10,
>const _GUID & {...}, unsigned long 1033, unsigned short 1, tagDISPPARAMS *
>0x0012f76c, tagVARIANT * 0x00000000, tagEXCEPINFO * 0x0012f828, unsigned
>int * 0x0012f858) line 1401 + 28 byt
>BCK32API! 00b4ec30()
>
>My OLE Method is:
>long CG2GateCtrl::G2Connect(LPCTSTR sMachineName, LPCTSTR sPortNumber)
>{
> gsi_int lStatus;
> char *initialization_string = "Anything"; // create a unique string here
> int connection = 0; // allocate a new connection index
>
> connection_initialization_string_table[connection] = initialization_string;
>
> // All calls in the GsiInterface class are thread-safe
> lStatus = m_pMyGsiInterface->GsiInitiateConnection(NULL, NULL, 0, "T",
> (char*)sMachineName,
> (char *)sPortNumber,
> initialization_string);
>}
>
>This is happening in the Invoke, so it's as soon as this OLE Method is
>called/invoked. I thought this would be solved by using the BSTR data type
>to eliminate this crash, but I couldn't figure out how to convert from
>LPCTSTRs to BSTRs. I asked on the microsoft.public.vc.mfcole newgroup and
>someone asked me why I was even wanting to use BSTRs. They said:
>You very rarely need a by-reference BSTR (which is what you have is you
>have a BSTR FAR*).
>
>I don't know what you are trying to do with this parameter. The OLE Events
>tab is used to describe an event you are firing from a control to a
>container. When you want to send a string parameter to the event handler,
>you generally select the LPCTSTR data type selection. For such parameters
>MFC applications, UNICODE and ANSI, will take your string (in ANSI for ANSI
>builds or in UNICODE for UNICODE builds) and properly convert it, as
>necessary to a BSTR.
>
>I thought BSTRs were THE OLE String Data type for dealing with OLE
>Automation/OCXs especially dealing with VB? Can anyone help me (Mike B?)
>figure out why I'm getting this problem. I have a code deadline tommorrow!
>
>Thanks,
>Sam
>
>
>
>
>
>
**************************************************************************
||
|||||| Jim Murphy
|||||||||| Senior Engineer
||||||||||||||
|||||||||||||| Advanced Control & Optimization Div.
|||||||||||||| Aspen Technology Inc.
|||||||||| Houston, TX
|| T(713) 313-1171 F(713) 313-1380
||
**************************************************************************
| Вернуться в корень Архива
|