Patrick McHale wrote:
> 
> Thanks for all of your input - maybe I need to make things a bit clearer.
> 
> I wish to be able to implement:
> 
>     out string GetVersion(out string aValue);

This implies that you want to return *two* strings. Is that
really what you want? 

To return *one* string you do:

  // idl
  string getVersion();
  // or better...
  readonly attribute string version;

You call from JS:

  var foo = bar.getVersion();
  // or better...
  var foo = bar.version;

Implementation in C++ (same for either method or attribute decl)

NS_IMETHODIMP X::GetVersion(char **_retval) {
 static const char version[] = "X 1.1";
 *_retval = reinterpret_cast<char*>(
    nsMemory::Clone(version, strlen(version)+1));
 return (*_retval) ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
}

To return *two* strings you do:

  string getVersion(out string aSecondOutString);

You call from JS:

  // this is why multiple out params are to be avoided!
  var secondObj = {};
  var foo = bar.getVersion(secondObj);
  var secondString = secondObj.value;

John.

> 
> so that I can obtain a string returned from the C++ code via javascript in
> this fashion.  Is this possible?.
> 
> All I have been able to use so far is:
> 
>     void GetVersion(out string aValue)
> 
> This returns nothing but a void as a return value. In order to minimize the
> changes necessary to our present
> Javascript code I need to be able to return a string as a function return -
> and not from a function parameter
> return value.
> 
> Thanks
> 
> Patrick McHale
> Powerlan USA.
> 
> "Rick Parrish" <[EMAIL PROTECTED]> wrote in message
> [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> > Patrick McHale wrote:
> >
> > > In our IDL file we have tried using
> > >
> > >   string GetVersion();
> > >
> > > The idl file generates:
> > >
> > > NS_METHOD GetVersion(char * _retval)
> > >
> >
> >
> > The C++ class interface stub should be producing something like
> >
> > NS_METHOD GetVersion([out, retval] char ** _retval);
> >
> > You could also experiment with making the function a readonly
> > attribute from IDL as in ...
> >
> > attribute readonly string GetVersion;
> >
> >  From JavaScript you would call the method using syntax similar
> > to the IDL description. From C++ you would use the latter syntax.
> >
> > // JS
> > var x = component.GetVersion();
> >
> > // C++
> > char *pStr = NULL;
> > nsResult ret = pObj->GetVersion(*pStr);
> > // do something with pStr and then ...
> > nsMemory::Free(pStr);
> > // its caller's job to release the returned string's memory.
> >
> >
> > > My question is - can we still use this method and how is
> > > this implemented.  At the present time is to write Java Glue to achieve
> > > this - but this is not seamless and will require a large amount of glue
> to
> > > be implemented. We want to avoid having thousands of tech support calls
> and
> > > wish to be able to continue using original HTML code with minimal
> changes
> > > necessary to implement XPCOM.
> >
> >
> > I assume you meant JavaScript and not Java. Using XPCOM you can access
> > just about any property or method on an XPCOM component.
> >
> >
> > > Above is an example using the method GetVersion which produces a return
> > > string. In actuality we have at least 30 other routines that need to be
> > > setup.
> >
> >
> > It isn't clear to me whether you are needing to implement your own
> > XPCOM components. If that is the case, you can write them in C++ or
> > JavaScript and then manipulate them from your XUL or HTML embedded
> > JavaScript.
> >
> > Post here or email me directly if you need help on this.
> >
> >
> > > With Thanks
> > >
> > > Patrick McHale
> > > Software Engineer
> > >
> > > Paul Baxter
> > > Principal Software Engineer
> > >
> > > Powerlan U.S.A.
> >
> >
> > Regards,
> > Rick
> >

Reply via email to