• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 286
  • Last Modified:

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!
0
jhattingh
Asked:
jhattingh
  • 3
  • 2
1 Solution
 
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
 
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

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now