Results 1 to 3 of 3

Thread: Does anyone know VB equiv. to C/C++ statement: value= *(pointer)?

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2000
    Posts
    52
    I'm really hoping there's a way to do this in VB 5.

    VB 5 has finally given us access to actual addresses, but seemingly only to pass on to win32 API calls that were written in C.

    In C, the operation *(address) returns to you the actual value stored at address, and not the address.

    If I have an array of data that I know starts at address data_buff_ptr, I really want to be able access that data by referencing that beginning address. This is a piece of cake in C/C++, but how the hell can you do this in VB?

    Anyone know if this is possible, without getting too ridiculously complicated (like using a third party control or dll)?

  2. #2
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    I can't remember the syntax of C so I'll try to explain in english there arre 3 pointer functions in VB which have been there all along but are undocumented

    VarPtr(lngA) returns a long pointer to lngA
    StrPtr(strA) returns a long pointer to the first integer in a wide character array. (VB does a hell of a lot of string converting behind the scenes though, It could just be a character array)
    VarPtr(StrA) Returns a Pointer to a Pointer to the first integer in a wide Character arrey etc...

    ObjPtr(objA) returns a pointer to the Object objA (I don't know much about COM, I suspect it's a pointer to the Data specific to the object rather than it's interface.

    To get the Target of the Pointer You have to use the CopyMemory API

    [Edited by Sam Finch on 04-22-2000 at 11:35 PM]

  3. #3

    Thread Starter
    Member
    Join Date
    Feb 2000
    Posts
    52
    Thanks for the reply Sam.

    You know, I've just realized how ridiculously simple it is to do this with a dll in c. In my present project I'm using a dll I wrote to compress and decompress files. All I need to do is export one more function:

    int _stdcall return_value(unsigned char* buff_ptr) {

    return *(buff_ptr)

    }

    Of course, this will return the value one byte at a time; a few more lines of code and another parameter to indicate the data size would generalize it.

    This is kind of absurd. It greatly upsets my aesthetic sensibilities. It's like a great big ugly festering sore on the butt of Visual Basic, a language and environment that otherwise has a great deal of beauty.

    To me, the best of all worlds would be if Visual C++ included an optional VB type IDE that gave you the same kind of event-driven programming while using C/C++ for the actual language that was used. I see no reason whatsoever why this could not be done.


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