2

I am trying to convert the following function from VBScript to JavaScript:

Object.UtilBlobToVariant(VARIANT *pV, long BlobPointer, long BlobSize)

Where pv is defined as:

A VARIANT that is returned with type (VT_ARRAY|VT_U1)

The UtilBlobToVariant function is part of a 3rd party COM library, so I can not change its definition.

The two long parameters work just fine in my JavaScript version of this function, but the parameter pV gives me a "Type mismatch" error afterwords because pV always comes back as undefined.

Object is an ActiveX object, so my target is strictly Internet Explorer because of this and other COM dependencies. I have tried just passing a var, or instantiating it as an empty array [] or an empty object {} but none of these have worked. Is this even possible?

DanM7
  • 2,203
  • 3
  • 28
  • 46
  • possible duplicate of [Working with "Out" Parameters in JavaScript](http://stackoverflow.com/questions/5122704/working-with-out-parameters-in-javascript) – Cheran Shunmugavel Oct 20 '14 at 05:21
  • @CheranShunmugavel - duplicate because they found there's no workaround for by-reference and that specific ActiveX function? I guess maybe a different question with the same answer. I was reaching, but I was hoping there was something that could be done. – DanM7 Oct 20 '14 at 14:19
  • I don't think it's anything to do with a specific function or another; it's just that JScript doesn't support "out" parameters. That's why I voted to close. The only longshot idea I have without knowing the 3rd party API is that maybe the function should be called like `var arr = Object.UtilBlobToVariant(blobPointer, blobSize)`, but that's based on the fact that the function declaration looks like it's from C++ and I have some vague recollection of seeing a C++ COM API where the return value of the function was actually listed as the first parameter. – Cheran Shunmugavel Oct 21 '14 at 05:16
  • @CheranShunmugavel - I'll definitely try that. That was why I thought the question was worth asking, even though I'm well aware there is no by-ref in JavaScript. There may be some weird workaround for COM with arrays and such. Thanks. – DanM7 Oct 21 '14 at 14:20

1 Answers1

0

Try in this way

For example this could be your javascript code

function UtilBlobToVariant(BlobPointer,BlobSize) {

 // your code here then at the end:

 return pV; 

}
Gianluca Colombo
  • 717
  • 17
  • 38
  • Thanks for your answer! Unfortunately, the `UtilBlobToVariant` function is part of a 3rd party COM library, so I can not change its definition. I've edited my question to address your point. – DanM7 Oct 17 '14 at 13:20