views:

688

answers:

1

Hello all,

I've built a small activex control using c#. I've got a function that returns an array of bytes. From some reason when I try to consue the returned array in js I receive an undefined value. Why is this happenning? Is there anyway to solve it?

Here's a simple demonstration of my code:

Activex:

[ComVisible(true)]
     public byte[] Close()
     {
      try
      {
       MessageBox.Show("called from activex Close");
       return Stop();
      }
      catch (Exception e)
      {
       //ExceptionHandling.AppException(e);
       throw e;
      }
     }

Javascript Call:

function CloseActiveX(){
var myRslt = document.OurActiveX.Close();
}
A: 

You haven't shown what the Stop() method contains. If Stop() returns null, you should expect to see what you're seeing.

As it stands, however, it looks like your ActiveX control is written in .NET. This is a bad idea for myriad reasons, not the least of which that performance will be low, and you will encounter problems if there are other controls or extensions running in the browser that want a different version of the framework.

Beyond that problem, the likely issue is that the byte[] isn't being marshalled back to the caller in a way that allows its use. You need to return a VARIANT with the following properties: ARRAY, BYREF, U1.

http://msdn.microsoft.com/en-us/library/z6cfh6e6(VS.80).aspx may be useful.

EricLaw -MSFT-