COM component returning data to VB app

When I try to add a method to my COM interface, it doesn't allow me to return anything but an HRESULT.

How do I return a string from my COM interface so that a VB app can say:

dim strResult as string
strResult = MyObject.GetSessionName()


Thanks!
LVL 1
jhattinghAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GlennDeanCommented:
jhattingh:
   The interface must be dual and VB only accepts a return value of type HRESULT.  So, the way you define a function to return a value, add to your interface a function like

  HRESULT NameOfFunction([out,retval] BSTR bstr);

   The key here to making it a return value is the keyword "retval".
   IF you're doing this from inside VC++ then you right click the IDL file, click Add Method and then enter the above.  When you go to your IDL you'll notice VC++ has actually added some more info (namely the dispatch id of your new function and a help string for people who want to browse your type library).
    Glenn
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
GlennDeanCommented:
Also note that BSTR is an interface's equivalent of a string.  
0
jhattinghAuthor Commented:
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Thanks for the reply. After attempting to follow your instructions, I have the following line in my IDL:

[id(3), helpstring("method GetStorePath")] HRESULT GetStorePath([out,retval] BSTR bstr, VARIANT inEntryID);

and an error that says:

error MIDL2281 : invalid use of "retval" attribute : [ Parameter 'bstr' of Procedure 'GetStorePath' ( Interface 'IMessageServiceAdmin' ) ]


I also added an "in" parameter...

0
jhattinghAuthor Commented:
Help file seemed to indicate the retvalue should be the last parameter. Changed them around and got different error:

error MIDL2121 : [out] only parameter must not derive from a top-level [unique] or [ptr] pointer/array : [ Type 'wireBSTR' ( Parameter 'bstr' ) ]
0
GlennDeanCommented:
jhattingh:
   Oops, it's suppose to be
  [out,retval] BSTR * bstr

   Glenn
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.