473,480 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Passing parameters by reference to a VC COM Object

I need to change a C++ COM Object so that it will correctly accept parameters by reference from a classic ASP/VBscript webapplication.
I'm working from the article found here: http://support.microsoft.com/kb/197957/EN-US/, as this article descibes my problem with the COM Object exactly.

The article gives the following original example method:

STDMETHODIMP CByRefObj::ByRefMethod( BSTR* bstrVal )
{
CComBSTR bstrRtnVal = L"This variable is passed by Reference";
*bstrVal = bstrRtnVal.Detach();
return S_OK;
}

And then at the bottom of the article, they say that the method needs to change so that it will accept a variant instead of a string as the output parameter. And as an example they suggest the following change:

// Where m_bstr is a BSTR member of SomeComObject.
vVal->vt = VT_BSTR;
vVal->bstrVal = m_bstr.Copy();

But since I don't know much C++ (I didn't write the COM object, but I do have its project sources) I don't understand where to put this in the example method.
I think it should look like this:

STDMETHODIMP CByRefObj::ByRefMethod( VARIANT* bstrVal )
{
CComBSTR bstrRtnVal = L"This variable is passed by Reference";
vVal->vt = VT_BSTR;
vVal->bstrVal = bstrRtnVal.Detach();
return S_OK;
}

Is this correct?

Regards, Marja
Dec 16 '05 #1
7 1254
Is this correct?


Yes.

Brian
Dec 16 '05 #2
>>Is this correct?

Yes.


I get compilation errors when I do it like that:

error C2065: 'vVal' : undeclared identifier
error C2227: left of '->vt' must point to class/struct/union/generic type

What's wrong?

--
Marja
Dec 16 '05 #3
Change it to:

STDMETHODIMP CByRefObj::ByRefMethod( VARIANT* vVal)
{
CComBSTR bstrRtnVal = L"This variable is passed by Reference";
vVal->vt = VT_BSTR;
vVal->bstrVal = bstrRtnVal.Detach();
return S_OK;
}

-cd

"Marja Ribbers-de Vroed" <ma***@nospam.webwaresystems.nl> wrote in message
news:u8**************@TK2MSFTNGP15.phx.gbl...
Is this correct?


Yes.


I get compilation errors when I do it like that:

error C2065: 'vVal' : undeclared identifier
error C2227: left of '->vt' must point to class/struct/union/generic type

What's wrong?

--
Marja
Dec 16 '05 #4
> Change it to:

STDMETHODIMP CByRefObj::ByRefMethod( VARIANT* vVal)
{
CComBSTR bstrRtnVal = L"This variable is passed by Reference";
vVal->vt = VT_BSTR;
vVal->bstrVal = bstrRtnVal.Detach();
return S_OK;
}


In this example, where does bstrVal come from in vVal->bstrVal = bstrRtnVal.Detach(); ?
What does it do?

Regards, Marja
Dec 16 '05 #5

"Marja Ribbers-de Vroed" <ma***@nospam.webwaresystems.nl> wrote in message
news:OF*************@TK2MSFTNGP09.phx.gbl...
Change it to:

STDMETHODIMP CByRefObj::ByRefMethod( VARIANT* vVal)
{
CComBSTR bstrRtnVal = L"This variable is passed by Reference";
vVal->vt = VT_BSTR;
vVal->bstrVal = bstrRtnVal.Detach();
return S_OK;
} In this example, where does bstrVal come from in vVal->bstrVal =
bstrRtnVal.Detach(); ?
What does it do?


It populates the bstrVal member variable with the BSTR pointer. Calling
Detach() indicates to the CComBSTR smart pointer that ownership of the BSTR
has been transferred to the assigned variable.

In the end, you have defined vVal to be a VARIANT containing the BSTR that
was created for you by the CComBSTR smart pointer.

Regards, Marja
Dec 16 '05 #6
>>In this example, where does bstrVal come from in vVal->bstrVal =
bstrRtnVal.Detach(); ?
What does it do?


It populates the bstrVal member variable with the BSTR pointer. Calling
Detach() indicates to the CComBSTR smart pointer that ownership of the BSTR
has been transferred to the assigned variable.

In the end, you have defined vVal to be a VARIANT containing the BSTR that
was created for you by the CComBSTR smart pointer.


Thank you very much for this explanation and your help.

Regards, Marja
Dec 16 '05 #7
Thanks Carl, that worked.

Regards, Marja
Dec 16 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
12586
by: harry | last post by:
I have 2 multi-dim arrays double subTotals = null; String rowTitles = null; I want to pass them to a function that initialises & populates them like so - loadData( rowTitles, subTotals);
3
14898
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
5
36373
by: Andy | last post by:
Hi Could someone clarify for me the method parameter passing concept? As I understand it, if you pass a variable without the "ref" syntax then it gets passed as a copy. If you pass a...
26
45462
by: Dave Hammond | last post by:
In document "A.html" I have defined a function and within the document body have included an IFRAME element who's source is document "B.html". In document "B.html" I am trying to call the function...
39
7590
by: Mike MacSween | last post by:
Just spent a happy 10 mins trying to understand a function I wrote sometime ago. Then remembered that arguments are passed by reference, by default. Does the fact that this slowed me down...
8
2104
by: Dennis Myrén | last post by:
I have these tiny classes, implementing an interface through which their method Render ( CosWriter writer ) ; is called. Given a specific context, there are potentially a lot of such objects,...
8
4393
by: Johnny | last post by:
I'm a rookie at C# and OO so please don't laugh! I have a form (fclsTaxCalculator) that contains a text box (tboxZipCode) containing a zip code. The user can enter a zip code in the text box and...
6
5972
by: MSDNAndi | last post by:
Hi, I get the following warning: "Possibly incorrect assignment to local 'oLockObject' which is the argument to a using or lock statement. The Dispose call or unlocking will happen on the...
7
3281
by: TS | last post by:
I was under the assumption that if you pass an object as a param to a method and inside that method this object is changed, the object will stay changed when returned from the method because the...
12
2552
by: dave_dp | last post by:
Hi, I have just started learning C++ language.. I've read much even tried to understand the way standard says but still can't get the grasp of that concept. When parameters are passed/returned...
0
6908
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7045
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6741
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
6944
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5341
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4782
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4483
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2985
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
182
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.