|
-
September 17th, 2004, 05:48 AM
#1
SysReAllocString - newbie confused!
Hi everyone,
I've written a class and put a COM wrapper around it. The class (and COM) takes a BSTR as an input parameter which is modified and then sent back out to whatever called the COM. I've declared the BSTR as [in, out] in the IDL and I'm using:
SysReAllocString(&strParameters, (OLECHAR*)chstrParams);
to alter the BSTR strParameters that is the input to the COM. I then have to call delete[] on the char* chstrParams. At this point the BSTR still appears to be valid, but when the COM exits I get an unhandled exception error. Am I dealing with returning the altered BSTR correctly and the re-allocation of the string?
Thanks for your help.
-
September 17th, 2004, 07:35 AM
#2
Re: SysReAllocString - newbie confused!
BSTR cannot be the [in,out] parameter. Only BSTR*.
Code:
HRESULT cX::funcX(... /*[in,out]*/ BSTR * strParameters,...)
{...
SysReAllocString( strParameters, (OLECHAR*)chstrParams);
...
}
With best wishes,
Vita
-----------------------
Russian Software Development Network -- http://www.rsdn.ru
-
September 17th, 2004, 08:53 AM
#3
Re: SysReAllocString - newbie confused!
It's always good to think in VB first and then define the IDL interface to your COM DLL.
For instance, if you have a "(ByRef P As String)" (or "P As String") you'll translate it as ([in,out]BSTR *P); and if you have a "(ByVal Q As String)" you'll translate it as ([in]BSTR Q);
It's almost mechanical, but you need to get used to that.
You can even try writing an empty VB DLL with the desired interface, and use OLEVIEW to check exactly how you need to write the IDL interface in your COM DLL. OLEVIEW is a good learning tool.
-
September 17th, 2004, 08:56 AM
#4
Re: SysReAllocString - newbie confused!
Thanks guys I've taken what you've said on board and managed to get everything going now. Cheers!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|