www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - accessing memory from address

reply "bojoe" <jbogner gmail.com> writes:
I am interfacing with a dll that returns a pointer to an int.

In python, I can use from_address:

  shape=list((c_int*rank).from_address(pi[2].contents.value))

Is there something equivalent in d? Or do I need to manually call 
ReadProcessMemory at that location?
Aug 30 2014
next sibling parent Rikki Cattermole <alphaglosined gmail.com> writes:
On 31/08/2014 1:41 a.m., bojoe wrote:
 I am interfacing with a dll that returns a pointer to an int.

 In python, I can use from_address:

   shape=list((c_int*rank).from_address(pi[2].contents.value))

 Is there something equivalent in d? Or do I need to manually call
 ReadProcessMemory at that location?
In the c world integral types are a bit more complicated. So for reference take a look at the table on [0]. As long as you have a pointer to a piece of data such as int* or void* you should be free to dereference it to get the value. Such as: extern(C) int* myCFunc(); void main() { int value = *myCFunc(); } [0] http://dlang.org/interfaceToC.html
Aug 30 2014
prev sibling parent "bojoe" <jbogner gmail.com> writes:
On Saturday, 30 August 2014 at 13:41:27 UTC, bojoe wrote:
 I am interfacing with a dll that returns a pointer to an int.

 In python, I can use from_address:

  shape=list((c_int*rank).from_address(pi[2].contents.value))

 Is there something equivalent in d? Or do I need to manually 
 call ReadProcessMemory at that location?
that was silly - looks like I just needed to do this: int shapex = *(cast(int*)shape);
Aug 30 2014