how to call a function like "HRESULT test([in]byte* aaa);" using VBScript
-
:omg:I wrote a com object with ATL, it has a test function, which declared like "HRESULT test([in]byte* aaa);" ; I wrote the following code in a html file,:omg::omg: want to call test function, but always get error message "type not match". Who can tell me is it possible to call test using VBScript and how to . my script code: Dim MyObj Set MyObj = CreateObject("Test.Test") Dim data(5) data(0) = CByte(97) data(1) = CByte(97) data(2) = CByte(97) data(3) = CByte(97) data(4) = CByte(97) data(5) = CByte(97) MyObj.test data
-
:omg:I wrote a com object with ATL, it has a test function, which declared like "HRESULT test([in]byte* aaa);" ; I wrote the following code in a html file,:omg::omg: want to call test function, but always get error message "type not match". Who can tell me is it possible to call test using VBScript and how to . my script code: Dim MyObj Set MyObj = CreateObject("Test.Test") Dim data(5) data(0) = CByte(97) data(1) = CByte(97) data(2) = CByte(97) data(3) = CByte(97) data(4) = CByte(97) data(5) = CByte(97) MyObj.test data
VBScript is an untyped language, or more correctly all types in VBScript are VARIANT. The problem is not in your VBScript, it is in your ATL method definition. To pass an array of any type into an ATL COM object from VBScript, you have to make several changes: 1) The parameter must be declared as [in, out] to force it to be passed ByRef instead of ByVal. 2) The parameter must be declared as a VARIANT* type. 3) You have to write additional code in the ATL function to convert the VARIANT* array into a byte array. So, your new function definition must be: "HRESULT test([in, out] VARIANT* aaa);" Once you have passed the array into the ATL COM object you need to access it as a SAFEARRAY and retrieve the values as VARIANTS then cast them to bytes. For more info see: http://support.microsoft.com/kb/218454/EN-US/[^] Robert