Pointer of structure

Can I get the pointer of a structure. e.g getting pointer of any integer etc maybe I need Marshal class.
Allow time to reverse.

With Marshal.StructureToPtr you can copy your structure to a memory block
(see the VB example in the documentation) and then access the data via pointer represented as an
IntPtr (for example, using Marshal.Copy). If you make some parts in C#, then you will be able to deal with pointers via
unsafe and fixed, which are not available in VB.
Thanks Viorel,
I found my answer that I cannot get the pointer of a structure declared in .net environment. In order to deal with unmanaged structure I made this code:
Imports System.Runtime.InteropServices
Namespace Unmanaged
Public Structure [Object](Of Struct As Structure)
Implements IDisposable, ICloneable, IObject
Private _Pointer As IntPtr
''' <summary>
''' Returns the pointer of structure
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public ReadOnly Property Pointer As IntPtr Implements IObject.Pointer
Get
Return _Pointer
End Get
End Property
''' <summary>
''' Returns the total size of object.
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public ReadOnly Property Size As Integer Implements IObject.Size
Get
Return Marshal.SizeOf(GetType(Struct))
End Get
End Property
''' <summary>
''' Return the type of structure.
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public ReadOnly Property Type As Type
Get
Return GetType(Struct)
End Get
End Property
''' <summary>
''' Accepts or returns the managed array of bytes.
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property ManagedBytes As Byte()
Get
Dim bytes(Size - 1) As Byte
Marshal.Copy(_Pointer, bytes, 0, Size)
Return bytes
End Get
Set(value As Byte())
Marshal.Copy(value, 0, _Pointer, Size)
End Set
End Property
''' <summary>
''' Returns the managed value of structure.
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property Value As Struct
Get
Return Marshal.PtrToStructure(_Pointer, GetType(Struct))
End Get
Set(value As Struct)
Marshal.StructureToPtr(value, _Pointer, True)
End Set
End Property
''' <summary>
''' Returns a copy of unmanaged object. Similar to Clone.
''' </summary>
''' <returns></returns>
''' <remarks></remarks>
Public Function Copy() As [Object](Of Struct)
Dim bytes(Size - 1) As Byte
Marshal.Copy(_Pointer, bytes, 0, Size)
Dim pointer = Marshal.AllocHGlobal(Size)
Marshal.Copy(bytes, 0, pointer, Size)
Erase bytes
Return New [Object](Of Struct)(Intptr:=pointer)
End Function
''' <summary>
''' Copy structure from current pointer to a specific pointer.
''' </summary>
''' <param name="Pointer"></param>
''' <remarks></remarks>
Public Sub CopyTo(Pointer As IntPtr)
Marshal.StructureToPtr(Value, Pointer, True)
End Sub
''' <summary>
''' Copy structure from current pointer to a pointer of specific unmanaged object.
''' </summary>
''' <param name="Obj"></param>
''' <remarks></remarks>
Public Sub CopyTo(Obj As [Object](Of Struct))
Obj.Value = Me.Value
End Sub
''' <summary>
''' Create new unmanaged object that has value of specific managed structure.
''' </summary>
''' <param name="Value"></param>
''' <remarks></remarks>
Sub New(Value As Struct)
_Pointer = Marshal.AllocHGlobal(Marshal.SizeOf(GetType(Struct)))
Marshal.StructureToPtr(Value, _Pointer, True)
End Sub
''' <summary>
''' Converts pointer of structure to unmanaged object.
''' </summary>
''' <param name="Intptr"></param>
''' <remarks></remarks>
Sub New(Intptr As IntPtr)
Me._Pointer = Intptr
End Sub
''' <summary>
''' Creates an unmanaged object at specific pointer having specific value.
''' </summary>
''' <param name="Pointer"></param>
''' <param name="Value"></param>
''' <remarks></remarks>
Sub New(Pointer As IntPtr, Value As Struct)
_Pointer = Pointer
Marshal.StructureToPtr(_Pointer, Pointer, True)
End Sub
Public Shared Narrowing Operator CType(Value As [Object](Of Struct)) As Struct
Return Value.Value
End Operator
Public Shared Narrowing Operator CType(Value As Struct) As [Object](Of Struct)
Return New [Object](Of Struct)(Value)
End Operator
Public Shared Narrowing Operator CType(Obj As [Object](Of Struct)) As IntPtr
Return Obj.Pointer
End Operator
Public Shared Narrowing Operator CType(Pointer As IntPtr) As [Object](Of Struct)
Return New [Object](Of Struct)(Intptr:=Pointer)
End Operator
''' <summary>
''' Create a copy of unmanaged object.
''' </summary>
''' <returns></returns>
''' <remarks></remarks>
Public Function Clone() As Object Implements ICloneable.Clone
Return New [Object](Of Struct)(Me.Value)
End Function
''' <summary>
''' Destroy unmanaged object.
''' </summary>
''' <remarks></remarks>
Public Sub Dispose() Implements IDisposable.Dispose
Marshal.FreeHGlobal(_Pointer)
_Pointer = Nothing
End Sub
End Structure
Public Structure Array(Of Struct As Structure)
Implements IDisposable, ICloneable, IObject, IEnumerable
Private _Pointer As IntPtr
Private Property _Count As Integer
Get
Return Marshal.ReadInt32(_Pointer)
End Get
Set(value As Integer)
Marshal.WriteInt32(_Pointer, value)
End Set
End Property
Public ReadOnly Property Count As Integer
Get
Return _Count
End Get
End Property
Public ReadOnly Property Pointer As IntPtr Implements IObject.Pointer
Get
Return _Pointer
End Get
End Property
Public ReadOnly Property Size As Integer Implements IObject.Size
Get
Return 4 + (Count * StructureSize)
End Get
End Property
Public Property Value As Struct()
Get
Dim array(Count - 1) As Struct
For i = 0 To Count - 1
array(i) = Me(i)
Next
Return array
End Get
Set(value As Struct())
For i = 0 To value.Count - 1
Me(i) = value(i)
Next
End Set
End Property
Public ReadOnly Property StructureType As Type
Get
Return GetType(Struct)
End Get
End Property
Public ReadOnly Property StructureSize As Integer
Get
Return Marshal.SizeOf(StructureType)
End Get
End Property
Public ReadOnly Property ArrayPointer As IntPtr
Get
Return _Pointer + 4
End Get
End Property
Public ReadOnly Property MemberPointer(ID As Integer) As IntPtr
Get
If ID >= Count Then Throw New System.IndexOutOfRangeException()
Return _Pointer + 4 + (Size * ID)
End Get
End Property
Public Property Member(ID As Integer) As [Object](Of Struct)
Get
Return New [Object](Of Struct)(Intptr:=MemberPointer(ID))
End Get
Set(value As [Object](Of Struct))
Dim obj = Member(ID)
obj.Value = value.Value
End Set
End Property
Default Public Property ManagedMember(ID As Integer) As Struct
Get
Dim pointer = MemberPointer(ID)
Return Marshal.PtrToStructure(pointer, GetType(Struct))
End Get
Set(value As Struct)
Dim pointer = MemberPointer(ID)
Marshal.StructureToPtr(value, pointer, True)
End Set
End Property
Public Function Copy() As Array(Of Struct)
Dim bytes(Size - 1) As Byte
Marshal.Copy(_Pointer, bytes, 0, Size)
Dim pointer = Marshal.AllocHGlobal(Size)
Marshal.Copy(bytes, 0, pointer, Size)
Erase bytes
Return New Array(Of Struct)(Pointer:=pointer)
End Function
Sub New(Pointer As IntPtr)
Me._Pointer = Pointer
End Sub
Sub New(Count As Integer)
_Pointer = Marshal.AllocHGlobal(4 + (Count * Marshal.SizeOf(GetType(Struct))))
Me._Count = Count
End Sub
Sub New(Array() As Struct)
Me.New(Array.Count)
Me.Value = Array
End Sub
Public Function Clone() As Object Implements ICloneable.Clone
Return New Array(Of Struct)(Me.Value)
End Function
Public Sub Dispose() Implements IDisposable.Dispose
Marshal.FreeHGlobal(_Pointer)
_Pointer = 0
End Sub
Public Function GetEnumerator() As IEnumerator Implements IEnumerable.GetEnumerator
Return New Enumerator(Me)
End Function
Private Structure Enumerator
Implements IEnumerator
Private _current As Integer
Private _array As Array(Of Struct)
Sub New(Array As Array(Of Struct))
Me._array = Array
_current = 0
End Sub
Public ReadOnly Property Current As Object Implements IEnumerator.Current
Get
Return _array(_current)
End Get
End Property
Public Function MoveNext() As Boolean Implements IEnumerator.MoveNext
_current = _current + 1
Return (_current < _array.Count)
End Function
Public Sub Reset() Implements IEnumerator.Reset
_current = 0
End Sub
End Structure
End Structure
Public Interface IObject
''' <summary>
''' Returns the pointer of structure
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
ReadOnly Property Pointer As IntPtr
''' <summary>
''' Returns the total size of object.
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
ReadOnly Property Size As Integer
End Interface
End Namespace
I think I am doing right. Does my array matches the native array?
Allow time to reverse.
I would say NO!
La vida loca

Similar Messages

  • Pointer to structure ActiveX Interface

    Hi,
    My Application is a ActiveX COM Server which exposes various methods. In one of the methods I need to pass a pointer to structure.
    My develope env is Microsoft Visual C++ .NET 6
    In the context of C programming, it would be something similar to this
    typedef _MyStruct_s
        BOOL blFlag1;
        BOOL blFlag2;
    }MyStruct_s;
    BOOL MyAPI(MyStruct_s *pstMyStrcut)
        BOOL RetVal;
        RetVal = (pstMyStrcut->blFlag1 && pstMyStrcut->blFlag2);
        result RetVal;

    Hi Brandon,
    Looks like this limitation is from TestStand ActiveX adapter, and not from ActiveX/COM itself.
    My application is an ActiveX/COM automation server. The same API (which is having issue through TestStand), does not have any issue if it is called from another UI based Standalone application.
    (This Standalone application basically implements similar features with GUI by calling the exposed APIs of ActiveX/COM automation server)
    Is any setting is missing (e.g. Custom Data Type etc) which is causing this problem?
    I am aware that TestStand does not have any issue with passing a pointer to structure for C DLL.
    Please let me know your inputs.
    Setup:
    TestStand 4.0
    OS- WindowsXP
    Thanks and Regards,
    Subhash
    Attachments:
    NI_structure_Issue.JPG ‏41 KB

  • Pointer to structure, retrieve into a cluster

    I have a DLL that returns a pointer to an array of pointers.  Each pointer in this array points to a structure.  How do I access/display the contents of the structures in a cluster?

    So to simplify my request, I have a pointer to a structure, how can I view the data in the structure.
    the structure contains 
    char
    enum
    int
    double
    Here is my code so far
    Attachments:
    retrieve_struct_into_cluster.jpg ‏121 KB

  • Pointer to structure in parameter list of DLL

    I want to use the CALL_LIBRARY_FUNCTION to access a function in a DLL
    which returns a pointer to a structure in its parameter list. How can I
    access this structure under LabVIEW 6.02? What is the parameter type I
    have to select in the CALL_LIBRARY_FUNCTION configuration window - there
    is no STRUCTURE or CLUSTER entry?
    Any help is very much appreciated. Thanks, Frank

    You may select "Adapt to Type" as a type of the parameter of the function, and then connect appropriate cluster to the output of the "Call Library" node.
    Oleg Chutko.

  • Degree Audit Callup Point and Structure View of RC's (PIQRULEWB_AC)

    Hello,
    I have linked a rule container to an academic object (type SC, in this case), via callup point 60 (degree audit). When I am in the structure view looking at this, I notice that the popup text over the callup points icon says "Non-Academic Callup Pnt". I have read a VSR cookbook, and was under the impression that RC's linked to academic objects would have academic callup points. Am I looking at a bug (SAP GUI client 710; server 4.72), or do I have a misunderstanding about the degree audit callup point?
    Thanks,
      Eric

    Hi Eric,
    actually the use of Rule Containers and Callup-Points in Degree Audit is a bit different than how it is used for the academic processes. While you define particular rules like prerequisites using the VSR rule elements for callup points within activities like module booking or admission, in Degree Audit the rules in the rule containers are "collected" to build the audit profile for the student. Also the concept of academic and non-academic callup points does not really apply to the use callup points for audits.
    I would not necessarily consider it as a bug that the display shows the callup-point as "non-academic" - however it could be a bit confusing and I suggest that you sent a low priority OSS message such that our development can review whether they could make that a bit clearer to the end-user.
    Regards
    Joachim

  • How to declare a pointer to structure element which is array structures

     LStr, *LStrPtr, **LStrHandle structure is taken from LabView cintools extcode.h
       I used: sprintf(((*(*in_array)->Strings[*count])->str), local_str); to pass local_str string to
    LabView array.  It worked fine, but  one programmer adviced me to change code to  be more readable.
    Means - to change  (*(*in_array)->Strings[*count]) construction to a pointer. I tried many different
    ways to implement this - but in all cases it caused LabView to crash. I understand that this question
    is related to C programming not about LabView, but could you point me at a place where I have mistake ?
    The most likely incorrect string is " LV_array = &(**((**in_array).Strings[*count])); "
    Thanks in advance.
    1.  typedef struct {
    2.        int32   cnt;            /* number of bytes that follow */
    3.        uChar   str[1];         /* cnt bytes */
    4.  } LStr, *LStrPtr, **LStrHandle;
    5.      
    6.  typedef struct {
    7.        int32 dimSize;
    8.        LStrHandle Strings[1];
    9.  } LVStringArray;
    10.      
    11. typedef LVStringArray **LVStrArrayHdl;
    12.      
    13  _declspec(dllexport) void avg_hello(int *count, LVStrArrayHdl in_array)
    14.      {
    15.      
    16.       unsigned char *local_str="Entering function ma_in()";
    17.       (*count) = 0;
    18.       LStr* LV_array;
    19.      
    20.       LV_array = &(**((**in_array).Strings[*count])); //Set address to which should point LV_array
    21.       subfunc(count, &in_array);                      // Call a function which resizes array (works)
    22.       sprintf(LV_array->str, local_str);              //passing string to LabView (not working)
    23.      
    24. }
    Solved!
    Go to Solution.

    thank you Andrey Dmitriev! spasibo!
    With your example I understood where I have error in my code:
    I tried to assign to pointer an address of string which wasn't yet pre-allocated!
    that means simply swapping strings we get final code:
    1.  typedef struct {
    2.        int32   cnt;            /* number of bytes that follow */
    3.        uChar   str[1];         /* cnt bytes */
    4.  } LStr, *LStrPtr, **LStrHandle;
    5.      
    6.  typedef struct {
    7.        int32 dimSize;
    8.        LStrHandle Strings[1];
    9.  } LVStringArray;
    10.      
    11. typedef LVStringArray **LVStrArrayHdl;
    12.      
    13  _declspec(dllexport) void avg_hello(int *count, LVStrArrayHdl in_array)
    14.      {
    15.      
    16.       unsigned char *local_str="Entering function ma_in()";
    17.       (*count) = 0;
    18.       LStr* LV_array;
    19.       subfunc(count, &in_array);                      // Call a function which resizes array (works), First we resize array, and only after that we can assign an address of string to a pointer
    20.       LV_array = &(**((**in_array).Strings[*count]));  //Assigning address to which should point LV_array
    21.      
    22.       sprintf(LV_array->str, local_str);              //passing string to LabView (not working)
    23.      
    24. }

  • Structure of Filter-tables in BW7.0?

    Hi,
    i'm actually not in access of an BI7.0-System and i like to develop some Filter like they are used in 7.0. Can someone please give me the Tablestructure of the 7.0 filter Tables and maybe a hint if they are accessible in 3.5 as well?
    thanks - i will assign points for structure...

    If you search on Google, there are couple of threads answering the same and here are the first three in the list,
    http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:941629680330
    How to compare two oracle database schemas
    http://www.red-gate.com/products/oracle-development/schema-compare-for-oracle/
    HTH
    Aman....

  • How to convert structures defined in VC++ to Labview

    hi
    I am converting a previously written VC++ code  to labview ...
    but i m facing a problem ... ie ... in VC++ 
     typedef struct
        float X,Y,Z;
        int X2,Y2; 
    }Position;
     in VC++ , if i hv to assign a value to structure.I use pointer to structure  so as to give value to each individual variable...
    but as far as labview is concerned how to create structure & assign value to it directly ...
    is creating structure same as creating clusters in labview ? 
    & how to assign value to it ? is thr any thing like pointer's in labview ? 
    I am using Labview 8.0..  
    waiting in anticipation ... 
    reply asap... thanking u for ur support... 
    regards
    Yogan

    Let me see if I understand correctly: you have a 12-bit signed value, stored in a 16-bit value, and you want it sign-extended through 16 bits?  I think there are easier ways to do this in both LabVIEW and C.  Here's one idea:

  • Rename an append structure ?

    Hello,
    we are using an append structure for table MAKT. The name of the append structure is in Z namespace.
    Now we need to use our own namespace because we want to sell our product.
    So we need to rename the old Z append structure to a new name.
    But is this possible without loseing data.
    What/How can we do it.
    Thanks

    You can create an append structure in SE11. Load the table EKKO in display mode and than you find in the menu "Goto" the point "Append structure...". Here you can define the name of your append structure. The name should be in the customer name space. So maybe use the given name.
    After this you can define your fields an save the structure.
    Now you can use the new field with select statements or you can see the field in SE16.
    But If you want to add fields to a "Custome data" tab in of PO header (Transaction ME21, ME22 & ME23 as well as ME21N, ME22N and ME23N) you have to use the given append structure CI_EKKODB.
    Please read the documentation to the user exit "mm06e005" in transaction SMOD.

  • Transportation planning point in SHPMNT03

    Hi friends,
    Please I need to know where I can find the "Transportation planning point" in the IDoc SHPMNT03.
    It s an urgent need,
    Thx in advance.
    Sofiane.

    These are the input parameters should be configured
    Transportation planning point,Shipment Type,Route,Route determination.
    Step1-Create Transportation planning point
    Enterprise Structure>Definition>Logistics Execution>Maintain transportation planning point.
    Step-2.Shipment Typer and Route and Route determination
    You could refer this path.http://help.sap.com/saphelp_47x200/helpdata/en/d5/2285347860ea35e10000009b38f83b/frameset.htm
    Process.
    Stock Transfer Order(ME21N)>Outbound Delivery Document(VL10B/VL10D)>Shipment Creation(VT01N)>Shipment will assigned in delivery document(VT01N/VT02N).Based on the delivery assignment shipment will be planned for shipping the goods.>Post Goods Issue(VL02N).
    Murugan Mallaiyasamy
    Edited by: sapmurugan on Jan 28, 2010 2:55 PM

  • Using Call Library Function Node To Return C++ Structure Informatio​n

    Hi everyone.  This question is for all you LabVIEW gurus out there.
    I am trying to call a function from a .dll to get information from a structure about a device (FT232H chip).  I am using the "Call Library Function Node" to do this in LabVIEW.  My issue is I do not know how to set up the "Call LIbrary Function Node" parameter for a C++ structure.  How do I set up the pointer to FT_DEVICE_LIST_INFO_NODE structure using the "Call Library Function Node" so that I can read back the device information?
    The details of the C++ function and the structure are below.
    Thanks for everyone's help!
    The C++ function is the following:
    FT_STATUS I2C_GetChannelInfo (uint32 index, FT_DEVICE_LIST_INFO_NODE *chanInfo)
    In = index (Index of the channel)
    Out = *chanInfo (Pointer to FT_DEVICE_LIST_INFO_NODE structure)
    The pointer to the FT_DEVICE_LIST_INFO_NODE is defined as:
    typedef struct _FT_DEVICE_LIST_INFO_NODE {
    ULONG Flags;
    ULONG Type;
    ULONG ID;
    DWORD LocId;
    char SerialNumber[16];
    char Description[64];
    FT_HANDLE ftHandle;
    } FT_DEVICE_LIST_INFO_NODE;

    Dennis/Nathan,
    I tried to set up the "Call Library Function Node (CLFN)" correctly in order to read out Device Information from a FTDI Chip (FT232H) but when I run the VI LabVIEW crashes on me always.
    I have attached the code.  For the FT_DEVICE_LIST_INFO_NODE structure I passed into the "CLFN" a constant cluster of all the structure elements and then I set up the node to:
    Type: Adapt to Type
    Data format: Handles by Value
    I think LabVIEW crash may have something to do with the fact that the output of the dll function is using a pointer to a structure.  With the Handles by value Data format I am unable to set the Pointer to structure.
    Can you please take a quick look at the code to see if I am setting the CLFN up correctly?
    Thanks!
    Once again, here are the C++ Code Details:
    FT_STATUS I2C_GetChannelInfo (uint32 index, FT_DEVICE_LIST_INFO_NODE *chanInfo)
    In = index (Index of the channel)
    Out = *chanInfo (Pointer to FT_DEVICE_LIST_INFO_NODE structure)
    The pointer to the FT_DEVICE_LIST_INFO_NODE is defined as:
    typedef struct _FT_DEVICE_LIST_INFO_NODE {
    ULONG Flags;
    ULONG Type;
    ULONG ID;
    DWORD LocId;
    char SerialNumber[16];
    char Description[64];
    FT_HANDLE ftHandle;
    } FT_DEVICE_LIST_INFO_NODE;
    Attachments:
    FT_I2C_GetChannelInfo.vi ‏14 KB

  • KMN  news   Iview  pointing  taxonomy   needs to have  a Link ..plz guide

    I have a  KMN    Iview Pointing  Taxonomy  structure  which  displays  department  news of a company.
    the company has  20 departments.  by default  user  can  see  one  department news which he  assigned.
    my  requiremnt is  to  provide  a  link   which  pops up  a  window that has  all  20 departments  with  checkbox
    options  where user  can  select  the  other  departments  to get the  news.
    can   you  guide me  how  to  provide  a link  which  pops a window  that has  check boxes and save  button.
    Thanks
    Suneel

    I have a  KMN    Iview Pointing  Taxonomy  structure  which  displays  department  news of a company.
    the company has  20 departments.  by default  user  can  see  one  department news which he  assigned.
    my  requiremnt is  to  provide  a  link   which  pops up  a  window that has  all  20 departments  with  checkbox
    options  where user  can  select  the  other  departments  to get the  news.
    can   you  guide me  how  to  provide  a link  which  pops a window  that has  check boxes and save  button.
    Thanks
    Suneel

  • Java - Write And Read From memory Like CheatEngine ( Writing not working?)

    Hello Oracle Forum
    I came here some time ago to ask about javaFX , i solved all my issues and im right now waiting for javaFx tot ake over swing and hmm, im working on learning LIBGDX to create games in java.
    However, im in need to create an app to change values of memory to fix a bug in an old program that i have, and the only way until now is using cheatEngine, So i decided to take a tutorial and learn how to do that in java.
    Well, im able to read from the memory but the write isnt working somehow... Im posting the code here, if anyone can give me a hint, i would thank and a lot, because theres a community that really needs this app to automate the fix without using cheat engine.
    package MainStart;
    import com.br.HM.User32;
    import com.br.kernel.Kernel32;
    import com.sun.jna.Memory;
    import com.sun.jna.Native;
    import com.sun.jna.Pointer;
    import com.sun.jna.ptr.IntByReference;
    public class Cheater {
        static Kernel32 kernel32 = (Kernel32) Native.loadLibrary("kernel32", Kernel32.class);
        static User32 user32 = (User32) Native.loadLibrary("user32", User32.class);
        static int readRight = 0x0010;
        static int writeRight = 0x0020;
        //static int PROCESS_VM_OPERATION = 0x0008;
        public static void main(String[] args) {
            //Read Memory
            //MineSweeper = Campo Minado
            int pid = getProcessId("Campo Minado"); // get our process ID
            System.out.println("Pid = " + pid);
            Pointer readprocess = openProcess(readRight, pid); // open the process ID with read priviledges.
            Pointer writeprocess = openProcess(writeRight, pid);
            int size = 4; // we want to read 4 bytes
            int address = 0x004053C8;
            //Read Memory
            Memory read = readMemory(readprocess, address, size); // read 4 bytes of memory starting at the address 0x00AB0C62.
            System.out.println(read.getInt(0)); // print out the value!      
            //Write Memory
            int writeMemory = writeMemory(writeprocess, address, new short[0x22222222]);
            System.out.println("WriteMemory :" + writeMemory);
            Memory readM = readMemory(readprocess, address, size);
            System.out.println(readM.getInt(0));
        public static int writeMemory(Pointer process, int address, short[] data) {
            IntByReference written = new IntByReference(0);
            Memory toWrite = new Memory(data.length);
            for (long i = 0; i < data.length; i++) {
                toWrite.setShort(0, data[new Integer(Long.toString(i))]);
            boolean b = kernel32.WriteProcessMemory(process, address, toWrite, data.length, written);
            System.out.println("kernel32.WriteProcessMemory : " + b); // Retorna false
            return written.getValue();
        public static Pointer openProcess(int permissions, int pid) {
            Pointer process = kernel32.OpenProcess(permissions, true, pid);
            return process;
        public static int getProcessId(String window) {
            IntByReference pid = new IntByReference(0);
            user32.GetWindowThreadProcessId(user32.FindWindowA(null, window), pid);
            return pid.getValue();
        public static Memory readMemory(Pointer process, int address, int bytesToRead) {
            IntByReference read = new IntByReference(0);
            Memory output = new Memory(bytesToRead);
            kernel32.ReadProcessMemory(process, address, output, bytesToRead, read);
            return output;
    package com.br.HM;
    import com.sun.jna.Native;
    import com.sun.jna.Pointer;
    import com.sun.jna.Structure;
    import com.sun.jna.platform.win32.WinDef.RECT;
    import com.sun.jna.ptr.ByteByReference;
    import com.sun.jna.ptr.IntByReference;
    import com.sun.jna.win32.StdCallLibrary.StdCallCallback;
    import com.sun.jna.win32.W32APIOptions;
    * Provides access to the w32 user32 library. Incomplete implementation to
    * support demos.
    * @author Todd Fast, [email protected]
    * @author [email protected]
    public interface User32 extends W32APIOptions {
        User32 INSTANCE = (User32) Native.loadLibrary("user32", User32.class, DEFAULT_OPTIONS);
        Pointer GetDC(Pointer hWnd);
        int ReleaseDC(Pointer hWnd, Pointer hDC);
        int FLASHW_STOP = 0;
        int FLASHW_CAPTION = 1;
        int FLASHW_TRAY = 2;
        int FLASHW_ALL = (FLASHW_CAPTION | FLASHW_TRAY);
        int FLASHW_TIMER = 4;
        int FLASHW_TIMERNOFG = 12;
        public static class FLASHWINFO extends Structure {
            public int cbSize;
            public Pointer hWnd;
            public int dwFlags;
            public int uCount;
            public int dwTimeout;
        int IMAGE_BITMAP = 0;
        int IMAGE_ICON = 1;
        int IMAGE_CURSOR = 2;
        int IMAGE_ENHMETAFILE = 3;
        int LR_DEFAULTCOLOR = 0x0000;
        int LR_MONOCHROME = 0x0001;
        int LR_COLOR = 0x0002;
        int LR_COPYRETURNORG = 0x0004;
        int LR_COPYDELETEORG = 0x0008;
        int LR_LOADFROMFILE = 0x0010;
        int LR_LOADTRANSPARENT = 0x0020;
        int LR_DEFAULTSIZE = 0x0040;
        int LR_VGACOLOR = 0x0080;
        int LR_LOADMAP3DCOLORS = 0x1000;
        int LR_CREATEDIBSECTION = 0x2000;
        int LR_COPYFROMRESOURCE = 0x4000;
        int LR_SHARED = 0x8000;
        Pointer FindWindowA(String winClass, String title);
        int GetClassName(Pointer hWnd, byte[] lpClassName, int nMaxCount);
        public static class GUITHREADINFO extends Structure {
            public int cbSize = size();
            public int flags;
            Pointer hwndActive;
            Pointer hwndFocus;
            Pointer hwndCapture;
            Pointer hwndMenuOwner;
            Pointer hwndMoveSize;
            Pointer hwndCaret;
            RECT rcCaret;
        boolean GetGUIThreadInfo(int idThread, GUITHREADINFO lpgui);
        public static class WINDOWINFO extends Structure {
            public int cbSize = size();
            public RECT rcWindow;
            public RECT rcClient;
            public int dwStyle;
            public int dwExStyle;
            public int dwWindowStatus;
            public int cxWindowBorders;
            public int cyWindowBorders;
            public short atomWindowType;
            public short wCreatorVersion;
        boolean GetWindowInfo(Pointer hWnd, WINDOWINFO pwi);
        boolean GetWindowRect(Pointer hWnd, RECT rect);
        int GetWindowText(Pointer hWnd, byte[] lpString, int nMaxCount);
        int GetWindowTextLength(Pointer hWnd);
        int GetWindowModuleFileName(Pointer hWnd, byte[] lpszFileName, int cchFileNameMax);
        int GetWindowThreadProcessId(Pointer hWnd, IntByReference lpdwProcessId);
        interface WNDENUMPROC extends StdCallCallback {
             * Return whether to continue enumeration.
            boolean callback(Pointer hWnd, Pointer data);
        boolean EnumWindows(WNDENUMPROC lpEnumFunc, Pointer data);
        boolean EnumThreadWindows(int dwThreadId, WNDENUMPROC lpEnumFunc, Pointer data);
        boolean FlashWindowEx(FLASHWINFO info);
        Pointer LoadIcon(Pointer hInstance, String iconName);
        Pointer LoadImage(Pointer hinst, // handle to instance
                String name, // image to load
                int type, // image type
                int xDesired, // desired width
                int yDesired, // desired height
                int load // load options
        boolean DestroyIcon(Pointer hicon);
        int GWL_EXSTYLE = -20;
        int GWL_STYLE = -16;
        int GWL_WNDPROC = -4;
        int GWL_HINSTANCE = -6;
        int GWL_ID = -12;
        int GWL_USERDATA = -21;
        int DWL_DLGPROC = 4;
        int DWL_MSGRESULT = 0;
        int DWL_USER = 8;
        int WS_EX_COMPOSITED = 0x20000000;
        int WS_EX_LAYERED = 0x80000;
        int WS_EX_TRANSPARENT = 32;
        int GetWindowLong(Pointer hWnd, int nIndex);
        int SetWindowLong(Pointer hWnd, int nIndex, int dwNewLong);
        int LWA_COLORKEY = 1;
        int LWA_ALPHA = 2;
        int ULW_COLORKEY = 1;
        int ULW_ALPHA = 2;
        int ULW_OPAQUE = 4;
        boolean SetLayeredWindowAttributes(Pointer hwnd, int crKey,
                byte bAlpha, int dwFlags);
        boolean GetLayeredWindowAttributes(Pointer hwnd,
                IntByReference pcrKey,
                ByteByReference pbAlpha,
                IntByReference pdwFlags);
         * Defines the x- and y-coordinates of a point.
        public static class POINT extends Structure {
            public int x, y;
         * Specifies the width and height of a rectangle.
        public static class SIZE extends Structure {
            public int cx, cy;
        int AC_SRC_OVER = 0x00;
        int AC_SRC_ALPHA = 0x01;
        int AC_SRC_NO_PREMULT_ALPHA = 0x01;
        int AC_SRC_NO_ALPHA = 0x02;
        public static class BLENDFUNCTION extends Structure {
            public byte BlendOp = AC_SRC_OVER; // only valid value
            public byte BlendFlags = 0; // only valid value
            public byte SourceConstantAlpha;
            public byte AlphaFormat;
        boolean UpdateLayeredWindow(Pointer hwnd, Pointer hdcDst,
                POINT pptDst, SIZE psize,
                Pointer hdcSrc, POINT pptSrc, int crKey,
                BLENDFUNCTION pblend, int dwFlags);
        int SetWindowRgn(Pointer hWnd, Pointer hRgn, boolean bRedraw);
        int VK_SHIFT = 16;
        int VK_LSHIFT = 0xA0;
        int VK_RSHIFT = 0xA1;
        int VK_CONTROL = 17;
        int VK_LCONTROL = 0xA2;
        int VK_RCONTROL = 0xA3;
        int VK_MENU = 18;
        int VK_LMENU = 0xA4;
        int VK_RMENU = 0xA5;
        boolean GetKeyboardState(byte[] state);
        short GetAsyncKeyState(int vKey);
    package com.br.kernel;
    import com.sun.jna.*;
    import com.sun.jna.win32.StdCallLibrary;
    import com.sun.jna.ptr.IntByReference;
    // by deject3d
    public interface Kernel32 extends StdCallLibrary
        // description from msdn
        //BOOL WINAPI WriteProcessMemory(
        //__in   HANDLE hProcess,
        //__in   LPVOID lpBaseAddress,
        //__in   LPCVOID lpBuffer,
        //__in   SIZE_T nSize,
        //__out  SIZE_T *lpNumberOfBytesWritten
        boolean WriteProcessMemory(Pointer p, int address, Pointer buffer, int size, IntByReference written);
        //BOOL WINAPI ReadProcessMemory(
        //          __in   HANDLE hProcess,
        //          __in   LPCVOID lpBaseAddress,
        //          __out  LPVOID lpBuffer,
        //          __in   SIZE_T nSize,
        //          __out  SIZE_T *lpNumberOfBytesRead
        boolean ReadProcessMemory(Pointer hProcess, int inBaseAddress, Pointer outputBuffer, int nSize, IntByReference outNumberOfBytesRead);
        //HANDLE WINAPI OpenProcess(
        //  __in  DWORD dwDesiredAccess,
        //  __in  BOOL bInheritHandle,
        //  __in  DWORD dwProcessId
        Pointer OpenProcess(int desired, boolean inherit, int pid);
        /* derp */
        int GetLastError();
    http://pastebin.com/Vq8wfy39

    Hello there,
    this tutorial was exactly what I needed, so thank you.
    Your problem seems to be in this line:
    int writeMemory = writeMemory(writeprocess, address, new short[0x22222222]); 
    The problem is, you're creating a new short array with the length of 0x22222222. Which not only results in an java.lang.OutOfMemoryError: Java heap space
    but also, if it would work, would create an empty array with the length of 0x22222222.
    I think you want to write 0x22222222 as value in your address.
    Correctly stored the code you'd need to write would be:
    short[] sarray = new short[]{(short) 0x22222222};
    But because the value is too long for the short, the value stored in your array would be the number 8738.
    I think, what you want to do is to store the number 572662306, which would be the hex value, stored in an int variable.
    So first of all you need to strip down your hex-value to shorts:
    Short in Java uses 16 Bit = 2 Byte. 0x22222222 -> 0x2222 for your high byte and 0x2222 for your low byte
    So your array would be
    short[] sarray = new short[]{0x2222,0x2222};//notice, that sarray[0] is the lowbyte and sarray[1] the high byte, if you want to store 20 it would be new short[]{20,0} or if you use hex new short[]{0x14,0x00}
    The next part is your writeToMemory Method. If I'm right, the method in the tutorial is a little bit wrong. The right version should be this:
    public static int writeMemory(Pointer process, int address, short[] data) {
      IntByReference written = new IntByReference(0);
      int size = data.length*Short.SIZE/8;
      Memory toWrite = new Memory(size);
      for (int i = 0; i < data.length; i++) {
      toWrite.setShort(i*Short.SIZE/8,
      data[i]);
      boolean b = kernel32.WriteProcessMemory(process, address, toWrite,
      size, written);
      return written.getValue();
    You need to calculate your offset right. And the size of your memory. Maybe you could write this method not with shorts, but with integers. But this should work.
    If you pass your new array to this function, it should write 0x22222222 to your adress. If you read out your toWrite value with toWrite.getInt(0) you get the right value.
    And there is one more thing. In order to write data to a process, you need to grant two access rights:
    A handle to the process memory to be modified. The handle must have PROCESS_VM_WRITE and PROCESS_VM_OPERATION access to the process.
    You have to grant the right to write data: PROCESS_VM_WRITE: 0x0020 and PROCESS_VM_OPERATION: 0x0008
    So your writeProcess needs to get initialized this way:
    Pointer writeprocess = openProcess(0x0020|0x0008,pid);
    I hope this works for you. Let me know.
    Greetings
    Edit:
    Because every data you write will be 1 byte to whatever count of byte I think the best way is to use the following method to write data to the memory:
    public static void writeMemory(Pointer process, long address, byte[] data)
      int size = data.length;
      Memory toWrite = new Memory(size);
      for(int i = 0; i < size; i++)
      toWrite.setByte(i, data[i]);
      boolean b = kernel32.WriteProcessMemory(process, address, toWrite, size, null);
    You can see some changes. First I changed all address values from int to long, because some addresses are out of range. And with all, i mean all. Not only in writeMemory, but also in readMemory and in your kernel32 Class.
    Second I don't use the IntByReference anymore..
    To use this method you need to store your data the following way if you would write 4 Byte data:
    byte[] values = new byte[]{0x14,0x00,0x00,0x00};
    This value would be the number 20. Index 0 will be the lowest byte and index 3 will be the highest byte.
    And one more thing I wrote is an method which you can use to calculate your address if you have a baseAddress.
    If you restart your program/game your old addresses won't point at the same values of your game. With some research (I use CheatEngine) you can get the baseaddress. This one will alway be the same.
    To get from your baseaddress to the dynamic adress you use offsets.
    public static long findDynAddy(Pointer process, int[] offsets, long baseAddress)
      long pointer = baseAddress;
      int size = 4;
      Memory pTemp = new Memory(size);
      long pointerAddress = 0;
      for(int i = 0; i < offsets.length; i++)
      if(i == 0)
      kernel32.ReadProcessMemory(process, pointer, pTemp, size, null);
      pointerAddress = ((pTemp.getInt(0)+offsets[i]));
      if(i != offsets.length-1)
      kernel32.ReadProcessMemory(process, pointerAddress, pTemp, size, null);
      return pointerAddress;
    This methods gets a process, an array of offsets (hex-values) and your baseadress and returns the dynamic address.
    For Solitaire the following code would give you the address to the score:
    long baseAddr = 0x10002AFA8L;
      int[] offsets = new int[]{0x50,0x14};
      long addr = findDynAddy(process, offsets, baseAddr);
    If somebody wants to get the whole code (user32, kernel32 and the cheater) just pm me and I will give you a link.

  • Adding a new field in searh and result [ comb of 2 other fields ]

    Hi ,
    I have to add a new field in Opportunity Search and later OpportunitySearch Result. This field belongs to Opportunity Details -> parties Involved view , and is a combination of 2 fields there..Partner function and Main Partner (unchecked ). Details are as below..
    Can you please suggest easiest way for achieving this..
    Details of the Opportunity Search where I need to add a new search field
    Component : BT111S_OPPT
    Context Node : SEARCH
    View : BT111S_OPPT/Search
    Details of the new search field (Present In the Opportunity Details, there is a viewset for Parties Involved ) ..The new search field should be Employee Responsible but not the Main Partner ( kind of a substitute OR Secondary Employee Responsible )..2 employee responsible is permitted in partner determination..
    Component : BTPartner
    Context Node:  BTPartner
    View : BTPartner/Partner
    Attribute : Partner_fct
    Generic Object Type = 1Order
    +
    Component : BTPartner
    Context Node : BTPartner
    View : BTPartner/ Partner
    Attribute: MainPartner ( Not checked = 0 )
    Is there a simpler way without coding to achieve the above?
    The route that we have thought of is ...Let me know if there is an alternate simpler way...and If I am missing anything
    1.Create a custom field using EEWB ( I am not well aware of AET, and not aware how to enable this in our 
       environment as we upgraded to 7.0 recently ) For CRM Opportunity Transaction Type.
    2.This will be linked to the table CRMD_ORDERADM_H and the related structure
    3.Ask the technical team to populate this field from structure COM_DYNP_PARTNER_UI-PARTNER_FCT and COM_DYNP_PARTNER_UI-MAINPARTNER = 0 [(In Transaction crmd_order F1 on employee responsible points to structure COM_DYNP_PARTNER_UI and Mainpartner is a Boolean and hence main partner = 0 means that it is not the main partner ).
    4.Add the same field in the search-result as well.
    Thanks.
    Regards,
    Monica.

    Hello,
    I have looked at wiki below [http://wiki.sdn.sap.com/wiki/display/CRM/Howtoaddanexistingfieldtoasearchpageofadifferent+component]
    Kindly suggest ways to acheive adding new field in Opportunity Search ( employee responsible which is not the main contact like I mentioned ) which belongs to another component ...Can it be done without coding eg. adding to design layer.
    Can you please give steps to do the same.
    Thanks.
    Regards,
    Monica

  • What's the details of the return data after calling Application.RegisteredFunctions?

    Application.RegisteredFunctions returns 3 columns. The last column is described as "Strings specifying the data types of the return values, and the number and data types of the arguments". Does anybody know the details of it? Is there a table
    showing which string specifies which data type? Thanks!

    From MSDN:
    Data Types
    The pxTypeText argument specifies the data type of the return value and the data types of all arguments to the DLL function or code resource. The first character of
    pxTypeText specifies the data type of the return value. The remaining characters indicate the data types of all the arguments. For example, a DLL function that returns a floating-point number and takes an integer and a floating-point number as
    arguments would require "BIB" for the pxTypeText argument.
    The data types and structures used by Excel to exchange data with XLLs are summarized in the following two tables.
    The first table lists the types supported in all versions of Excel.
    Data type
    Pass by value
    Pass by ref (pointer)
    Comments
    Boolean
    A
    L
    short [int] (0=false or 1=true)
    double
    B
    E
    char *
    C, F
    Null-terminated ASCII byte string
    unsigned char *
    D, G
    Counted ASCII byte string
    unsigned short [int]
    H
    16-bit WORD
    [signed] short [int]
    I
    M
    16-bit signed integer
    [signed long] int
    J
    N
    32-bit signed integer
    FP
    K
    Floating-point array structure
    Array
    O
    Three arguments are passed:
    unsigned short int *
    unsigned short int *
    double []
    XLOPER
    P
    Variable-type worksheet values and arrays
    R
    Values, arrays, and range references
    In Excel 2007 the following data types were introduced to support the larger grids and long Unicode strings.
    Data type
    Pass by value
    Pass by ref (pointer)
    Comments
    unsigned short *
    C%, F%
    Null-terminated Unicode wide-character string
    unsigned short *
    D%, G%
    Counted Unicode wide-character string
    FP12
    K%
    Larger grid floating-point array structure
    Array
    O%
    Three arguments are passed:
    signed int * / RW *
    signed int * / COL *
    double []
    XLOPER12
    Q
    Variable-type worksheet values and arrays
    U
    Values, arrays, and range references
    Starting in Excel 2010 the following data types were introduced:
    Data Type
    Pass by value
    Pass by ref (pointer)
    Comments
    XLOPER12
    X
    The asynchronous handle is used to track a pending asynchronous function call by Excel and the XLL.The existence of the parameter type in the type string also designates the function as asynchronous.For more information about asynchronous functions, see
    Asynchronous User-Defined Functions.
    The string types F, F%, G, and G% are used for arguments that are modified-in-place.
    When working with the data types displayed in the previous table, be aware of the following:
    The C-language declarations assume that your compiler uses 8-byte doubles, 2-byte short integers, and 4-byte long integers by default.
    All functions in DLLs and code resources are called using the __stdcall calling convention.
    Any function that returns a data type by reference, that is, that returns a pointer to something, can safely return a null pointer. Excel interprets a null pointer as a #NUM! error.
    Charles Excel MVP The Excel Calculation Site http://www.decisionmodels.com/

Maybe you are looking for

  • How to use MS Office w/iCloud?

    Hi guys, I am using MS Office for Mac because of compatibility issues with my clients. IDisk worked just perfectly for me now I understand that I can retrieve my documents in the cloud thru iWorks only and not directly by "opening" the iDisk folder.

  • How do I "link" my music folders to the iTunes Library?

    I have recently upgraded my computer. I have formated my disk and installed a new XP, Office, iTunes etc. Now I have all my music files on a disk D: and my iTunes at C: but I can't manage to "add"/"link" my music folders to the iTunes Library. After

  • How can I get my music transferred from my ipod classic back to my computer?

    I have a 5th generation Ipod classic that is cracked on the surface but works still on a docking station at home in which I can select the music through my tv.  My problem is that certain music and ablums show they are on my itunes but do not play on

  • Java class on jsp

    how can we call a java class on click of submit button in jsp page?

  • How to reduce the amount of transparency levels in photoshop

    So I am making a t-shirt design and I have some transparent images (I cannot control the opacity) and since it's for a t-shirt it cannot have half transparent pixels, so is there any kind of filter or operation to make it so that there are only two l