Jump to content

Reading data from pointer


 Share

Recommended Posts

Hi!

I'm trying to use DLL to convert an image from a DICOM file into memory and then to grab it and show it with autoit. I'm passing the DLL a pointer and saving the image into it. I think I've been able to do everything else, but I don't know how to read the data from the pointer. I always only get the address where the pointer is pointing to. I have made the DLL myself, so it's possible to change its methods if you have any suggestions. I've tried to search the forums for it (and I think those stub-things do something like I want to) but I haven't been able to get anything worth of it.

In other words, I'd like to know how I can get data from the pointer address (like *data in C++). Here's the code in autoit:

CODE
#include <A3LMemory.au3>

$a = DllStructCreate("int size") <------------------- My DLL returns the amount of the data in bytes.

$c = _MEM_GlobalAlloc( 2000000, $GMEM_FIXED ) <------------------- Allocating an overkill amount of memory

DllCall( "proo.dll", "int:cdecl", "fnProo", "ptr", $c, "ptr", DllStructGetPtr($a, "size"), "str", "testi.dcm", "str", "humppa.bmp", "int", 1, "int", 0 )

/***** I really ain't sure if these work but I just use it to point to you what I want to do. I'd use something like: *******/

$data = GetDataFromPointer( $c, DllStructGetData($a, "size") ) <------------ This is would be a bit like what I want to do. I like to read "size" bytes from the pointer $c

$BitToHBit = _GDIP_BitmapCreateHBITMAPFromBitmap($data)

$hBitmap = _GDIP_BitmapCreateFromHBITMAP($BitToHBit)

************/

_Mem_GlobalFree( $c )

So do you have any ideas how to get the actual data from the $C?

Thanks,

Lassi

Link to comment
Share on other sites

I'm not sure but if your DLL returns bitmap maybe try something like this:

#include <A3LMemory.au3>

$a = DllStructCreate("int size")
$c = _MEM_GlobalAlloc( 2000000, $GMEM_FIXED )

DllCall( "proo.dll", "int:cdecl", "fnProo", "ptr", $c, "ptr", DllStructGetPtr($a, "size"), "str", "testi.dcm", "str", "humppa.bmp", "int", 1, "int", 0 )

$BitToHBit = _GDIP_BitmapCreateHBITMAPFromBitmap($c) ; use directly $c - pointer to memory with your bitmap
$hBitmap = _GDIP_BitmapCreateFromHBITMAP($BitToHBit)

_Mem_GlobalFree( $c )
Link to comment
Share on other sites

Thx for the fast reply! I haven't had time to check this before so I'm sorry that responding took so long...

Now I'm sure that my DLL works and I can write a .bmp file with it. The DLL should return a bitmap, because I can write and show it with _GDIP_BitmapCreateFromFile() and the following code:

CODE

$a = DllStructCreate("int size") <------------------- My DLL returns the amount of the data in bytes.

$c = _MEM_GlobalAlloc( 2000000, $GMEM_FIXED ) <------------------- Allocating an overkill amount of memory

DllCall( "proo.dll", "int:cdecl", "fnProo", "ptr", $c, "ptr", DllStructGetPtr($a, "size"), "str", $name, "str", "humppa.bmp", "int", $plap, "int", $plop )

$humppa = DllStructCreate( "char[" & DllStructGetData($a, "size") & "]", $c )

$ham = FileOpen( "test.bmp", 17 )

$i = 0

while ($i <= DllStructGetData($a, "size"))

$i = $i + 1

FileWrite( $ham, DllStructGetData($humppa, 1, $i) )

WEnd

FileClose($ham)

Though I need to use ANSI-version of Autoit (with unicode it just doesn't show properly, but you can still view it). Neither _GDIP_BitmapCreateHBITMAPFromBitmap($c) or _GDIP_BitmapCreateFromHBITMAP($c) worked. Is there any way to "cast" from $humppa to string or to something which isn't an array? I'll try to make it working myself, but I'd really appreciate any help from you guys <3.

Link to comment
Share on other sites

Hi once again!

Haven't made almost any progress. Though I can read $humppa to a string with the same loop as with filewrite. But does anyone have any idea why none of the gdip-functions can use that string? What about any idea about how to convert that string to a proper format? It's starting to look like I have to make that HBitmap object in the DLL and return a handle to it. Though I'd prefer to do it in the autoit...

Thanks!

Link to comment
Share on other sites

  • 2 weeks later...

Still haven't been able to do it... But I realized (or so I think) that it should be a bit same as using a string read from a file:

#include <A3LGDIPlus.au3>

$str = FileRead( "test.bmp" )
$BitToHBit = _GDIP_BitmapCreateHBITMAPFromBitmap( $str )
$hBitmap = _GDIP_BitmapCreateFromHBITMAP( $BitToHBit )
...

But this doesn't work either. Does anyone have any idea how to make it work with a string? This way I could read it from a pointer to a string and it would work /

Link to comment
Share on other sites

Still haven't been able to do it... But I realized (or so I think) that it should be a bit same as using a string read from a file:

#include <A3LGDIPlus.au3>

$str = FileRead( "test.bmp" )
$BitToHBit = _GDIP_BitmapCreateHBITMAPFromBitmap( $str )
$hBitmap = _GDIP_BitmapCreateFromHBITMAP( $BitToHBit )
...

But this doesn't work either. Does anyone have any idea how to make it work with a string? This way I could read it from a pointer to a string and it would work /

At least you must open file in binary mode I think.

Look at FileOpen.

Link to comment
Share on other sites

At least you must open file in binary mode I think.

Look at FileOpen.

Yeah, forgot about that one, but reading it with mode 16 didn't help. Maybe I'll just have to convert my script to c++ (which isn't nice considering about developing it etc. And I'm a noob with C). Or maybe I'll just forget about that thumbnail-thing. Though it would be great to find some way to make it work.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...