Results 1 to 7 of 7

Thread: How to dereference a pointer as a structure

  1. #1

    Thread Starter
    Fanatic Member jian2587's Avatar
    Join Date
    Aug 2000
    Location
    I bet u need a fusion powered shuttle to reach my place...
    Posts
    963

    How to dereference a pointer as a structure

    I've an IntPtr which points to the location where a Bitmap stores its raw image, i.e. not pointer to the bitmap object, but pointer to the image data itself (which I obtained through BitmapData.Scan0)

    Now I've a structure like this
    VBCode Code:
    1. Structure RGB
    2.     B As Byte
    3.     G As Byte
    4.     R As Byte
    5. End Structure

    I need to be able to access the individual pixels (which I locate using the pointer) on the image as this RGB Structure.
    In other words, it's like casting the pointer as a structure type. In C# it may be something like (RGB*) bmpptr;

    Anyone know how?

    Thanks in advance.
    ASM,C,C++,BASIC,VB,JAVA,VBS,HTML,ASP,PHP,mySQL,VB.NET,MATLAB
    Programming is fun, but only if you're not on a tight deadline
    So I consider all those working engineers sad people

    VB FTP class
    3 page PHP crash course
    Crash Course on DX9 Managed with VB.NET covering basics till terrain creation

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How to dereference a pointer as a structure

    Doesn't the MSDN help topic for the Scan0 property essentially show you how to do that? The code example it provides gets all the RGB data into a Byte array. You would then create multiple instances of your structure from the elements of that array.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Fanatic Member jian2587's Avatar
    Join Date
    Aug 2000
    Location
    I bet u need a fusion powered shuttle to reach my place...
    Posts
    963

    Re: How to dereference a pointer as a structure

    Thanks for your reply.
    I know that method; that's precisely the method I want to avoid. I want to change it directly, right away, on the spot, with the help of a structure. This is why I want to dereference the pointer as a structure which I've defined. Copying to an array incurs a lot of overhead. My code runs in a tight loop so I hope to be able to change the data as fast as possible.
    ASM,C,C++,BASIC,VB,JAVA,VBS,HTML,ASP,PHP,mySQL,VB.NET,MATLAB
    Programming is fun, but only if you're not on a tight deadline
    So I consider all those working engineers sad people

    VB FTP class
    3 page PHP crash course
    Crash Course on DX9 Managed with VB.NET covering basics till terrain creation

  4. #4

    Thread Starter
    Fanatic Member jian2587's Avatar
    Join Date
    Aug 2000
    Location
    I bet u need a fusion powered shuttle to reach my place...
    Posts
    963

    Re: How to dereference a pointer as a structure

    I only hope VB.net has a native method to do this, and I would like to know what it is. I dont want to use Marshal class's WriteByte or the WriteInts, nor do I want to use FillMemory API because they incur tiny bits of overheads.

    Unless, the JIT inlines the function call, which I'm not sure.
    ASM,C,C++,BASIC,VB,JAVA,VBS,HTML,ASP,PHP,mySQL,VB.NET,MATLAB
    Programming is fun, but only if you're not on a tight deadline
    So I consider all those working engineers sad people

    VB FTP class
    3 page PHP crash course
    Crash Course on DX9 Managed with VB.NET covering basics till terrain creation

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How to dereference a pointer as a structure

    Sounds to me like VB is the wrong language for this. I'd suggest writing a library in C# using unsafe code and then referencing that from your VB app, if that's an option.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Fanatic Member jian2587's Avatar
    Join Date
    Aug 2000
    Location
    I bet u need a fusion powered shuttle to reach my place...
    Posts
    963

    Re: How to dereference a pointer as a structure

    thanks jmcilhinney for the advice.
    unfortunately I'm not using C#.
    The fact that they all are .NET compliant leads me to think VB.NET might have something like that, too.
    I guess I'll just drop the idea and look for alternatives.
    Speed is still an issue with VB.net, it seems.
    ASM,C,C++,BASIC,VB,JAVA,VBS,HTML,ASP,PHP,mySQL,VB.NET,MATLAB
    Programming is fun, but only if you're not on a tight deadline
    So I consider all those working engineers sad people

    VB FTP class
    3 page PHP crash course
    Crash Course on DX9 Managed with VB.NET covering basics till terrain creation

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How to dereference a pointer as a structure

    VB.NET was never intended to support pointers. If wanted to do even medium-duty work with pointers in VB the code would get ugly very quickly. The language is simply not designed for it.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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