Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. COM
  4. how to call a function like "HRESULT test([in]byte* aaa);" using VBScript

how to call a function like "HRESULT test([in]byte* aaa);" using VBScript

Scheduled Pinned Locked Moved COM
c++htmlcomtoolsregex
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    samfromcn
    wrote on last edited by
    #1

    :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

    R 1 Reply Last reply
    0
    • S samfromcn

      :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

      R Offline
      R Offline
      rwestgraham
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups