CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Array Addresses

  1. #1
    Join Date
    Aug 1999
    Location
    Memphis, TN, USA
    Posts
    159

    Array Addresses

    I'm trying to use the MsgWaitForMultipleObjects function, and one of the arguments is a pointer to an array of handles. So, I've got my array of Longs and use VarPtr on the 0th element to pass it as a pointer. However, the function only recognizes this as a pointer if the array has only one element (I use GetLastError and get error code 6). Are VB pointers structured differently than C++ pointers? Does anyone know of a work-around for this?


  2. #2
    Join Date
    Apr 1999
    Location
    Netherlands
    Posts
    181

    Re: Array Addresses

    VB doesn't have pointers like in C, although there are some undocumented functions yo get a pointer. If I remember it well, I saw a while ago another API, which wants an array too as one of it's arguments. I saw inthe example code that they change it in the declaration from Byval Blah as long to Blah() as long, or something like that (sorry it was a loooong time ago I saw it...)
    Maybe you can try that, and see if that works.

    Crazy D :-)

  3. #3
    Join Date
    Aug 1999
    Location
    Memphis, TN, USA
    Posts
    159

    Re: Array Addresses

    Yeah, you can pass pointers to API's in vb by preceding the variable with VarPtr. It's pretty much undocumented in MS, but will return the address (long type) of pretty much any type of variable, including user-defined types (supposedly). However, in my case, it just doesn't seem to work well enough for arrays. Thanks for the suggestion, though. I'll try it.


  4. #4
    Join Date
    Jul 1999
    Posts
    145

    Re: Array Addresses

    Passing a pointer to an array is simple, just pass the first item in the array ByRef to the procedure. All you have to be careful of is that the array is sized large enough to handle what will be written in to it by the procedure being called, assuming something will be written into it of course. If not things get a little nutty.
    You don't have to mess with VarPtr..
    You can also pass any item in the array and it will be assumed that it is the "start" of the array.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured