Click here to Skip to main content
15,903,385 members
Home / Discussions / COM
   

COM

 
QuestionHow to Drawing in word Through C# Pin
sam_g18-Mar-06 0:36
sam_g18-Mar-06 0:36 
QuestionSystem.Runtime.InteropServices.COMException (0x800C0008): The download of the specified resource has failed. Pin
imunevar7-Mar-06 15:24
imunevar7-Mar-06 15:24 
QuestionAbout Remoting topic Pin
ashishnagar17-Mar-06 2:21
ashishnagar17-Mar-06 2:21 
Questionworking with VB .dll Pin
_kane_7-Mar-06 1:03
_kane_7-Mar-06 1:03 
QuestionHow to connect to the Automation server which is not registered in ROT. Pin
oleg636-Mar-06 5:37
professionaloleg636-Mar-06 5:37 
QuestionHow to trap IE refresh Pin
tenali_gowda5-Mar-06 20:41
tenali_gowda5-Mar-06 20:41 
QuestionPassing user defined object between COM component and client Pin
dario_alvarez5-Mar-06 12:37
dario_alvarez5-Mar-06 12:37 
QuestionBSTR problems in COM Service Pin
RobCraig3-Mar-06 9:12
RobCraig3-Mar-06 9:12 
I have written a COM service using ATL 7.0 and VS 2003 which contains one COM Class. The class uses a number of member variables, some of which are CComBSTRs. Clients can use the get/put methods on these strings. The strings are processing parameters for calls to the calculation operation in the COM object. The string variables are changed to alter the output each time the object is called. Sometimes, the result of the get function is not what was sent to the put function.

Server Code:
<br />
//variable declaration<br />
CComBSTR m_bstrTheString;<br />
<br />
//assignment in constructor<br />
m_bstrTheString = SysAllocString(L"Testing");<br />
<br />
//interface entry<br />
[propget, helpstring("property m_bstrTheString")] HRESULT m_bstrTheString([out, retval] BSTR* pVal);<br />
[propput, helpstring("property m_bstrTheString")] HRESULT m_bstrTheString([in] BSTR newVal);<br />
<br />
//property manipulation<br />
STDMETHOD(get_m_bstrTheString)(BSTR* pVal);<br />
STDMETHOD(put_m_bstrTheString)(BSTR newVal);<br />
<br />
//property manipulation code<br />
STDMETHODIMP CMyClass::get_m_bstrTheString(BSTR* pVal)<br />
{<br />
	*pVal = m_bstrTheString;<br />
	return S_OK;<br />
}<br />
<br />
STDMETHODIMP CHunter::put_m_bstrTheString(BSTR newVal)<br />
{<br />
	size_t s = ::SysStringLen(m_bstrTheString);<br />
	if(s > 0)<br />
		::SysFreeString(m_bstrTheString);<br />
	m_bstrTheString= ::SysAllocString(newVal);<br />
	return S_OK;<br />
}<br />


In the client code(simplified):

<br />
BSTR bstrIn;<br />
BSTR bstrOut;<br />
<br />
HRESULT hr = CoInitialize(NULL);<br />
CT2CW szIn(argv[3]);<br />
bstrIn = ::SysAllocString(szIn);<br />
if(bstrIn == NULL)<br />
  return E_OUTOFMEMORY;<br />
MyService::IMyPtr pMine(__uuidof(MyService::CMy));<br />
hr = pHunter->put_m_bstrTheString(bstrIn);<br />
hr = pHunter->get_m_bstrTheString(&bstrOut);<br />


My question is: Is this a good way to go about this. I am having the problem of the string sometimes being overwritten by other variables of the same type when performing operations on them.

Thanks in advance for any help.

Rob
AnswerRe: BSTR problems in COM Service Pin
Gerald Schwab3-Mar-06 10:02
Gerald Schwab3-Mar-06 10:02 
GeneralRe: BSTR problems in COM Service Pin
RobCraig3-Mar-06 11:58
RobCraig3-Mar-06 11:58 
QuestionHow to detect ActiveX on IE when it begins run using BHO? Pin
Blue-Bird1-Mar-06 21:09
Blue-Bird1-Mar-06 21:09 
QuestionUsing ActiveX in MFC Pin
lroels1-Mar-06 20:36
lroels1-Mar-06 20:36 
Questionout of process activex exe Pin
david_reynolds28-Feb-06 9:16
david_reynolds28-Feb-06 9:16 
AnswerRe: out of process activex exe Pin
Roger Stoltz28-Feb-06 21:23
Roger Stoltz28-Feb-06 21:23 
GeneralRe: out of process activex exe Pin
david_reynolds1-Mar-06 3:11
david_reynolds1-Mar-06 3:11 
QuestionHow to delete a COM object - My Other Code Pin
AmitGG27-Feb-06 22:45
AmitGG27-Feb-06 22:45 
AnswerRe: How to delete a COM object - My Other Code Pin
AmitGG28-Feb-06 22:14
AmitGG28-Feb-06 22:14 
QuestionHow to delete a COM object Pin
AmitGG27-Feb-06 20:30
AmitGG27-Feb-06 20:30 
AnswerRe: How to delete a COM object Pin
mbue27-Feb-06 22:07
mbue27-Feb-06 22:07 
GeneralRe: How to delete a COM object Pin
AmitGG27-Feb-06 22:21
AmitGG27-Feb-06 22:21 
GeneralRe: How to delete a COM object Pin
mbue27-Feb-06 23:29
mbue27-Feb-06 23:29 
GeneralRe: How to delete a COM object Pin
AmitGG28-Feb-06 0:05
AmitGG28-Feb-06 0:05 
GeneralRe: How to delete a COM object Pin
mbue28-Feb-06 3:51
mbue28-Feb-06 3:51 
QuestionConnecting Multiple clients to single server using DCOM Pin
abhiramsss27-Feb-06 18:21
abhiramsss27-Feb-06 18:21 
AnswerRe: Connecting Multiple clients to single server using DCOM Pin
FearlessBurner6-Mar-06 1:51
FearlessBurner6-Mar-06 1:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.