Giter Club home page Giter Club logo

Comments (5)

dblock avatar dblock commented on August 22, 2024

This could be a bug in the declaration of SYSTEM_INFO.

from jna.

pakko84 avatar pakko84 commented on August 22, 2024

I took a look at the sources, but couldn´t find anything wrong in the SYSTEM_INFO structure.

from jna.

pakko84 avatar pakko84 commented on August 22, 2024

Your hint towards the SYSTEM_INFO structure was right. I finally got it working on a 64 bit-system by modifying the SYSTEM_INFO structure to the following code:

public static class SYSTEM_INFO extends Structure {

    public static class ByReference extends SYSTEM_INFO implements Structure.ByReference {

        public ByReference() {
        }

        public ByReference(Pointer memory) {
            super(memory);
        }
    }

    public SYSTEM_INFO() {
        setAlignType(Structure.ALIGN_MSVC);
    }

    public SYSTEM_INFO(Pointer memory) {
        setAlignType(Structure.ALIGN_MSVC);
        useMemory(memory);
        read();
    }

    public static class SYSTEM_UNION_STRUCT extends Structure {

        public static class ByReference extends SYSTEM_UNION_STRUCT implements Structure.ByReference {

            public ByReference() {
            }

            public ByReference(Pointer memory) {
                super(memory);
            }
        }

        public SYSTEM_UNION_STRUCT() {
            setAlignType(Structure.ALIGN_MSVC);
        }

        public SYSTEM_UNION_STRUCT(Pointer memory) {
            setAlignType(Structure.ALIGN_MSVC);
            useMemory(memory);
            read();
        }
        public WORD wProcessorArchitecture;
        public WORD wReserved;
    }

    public static class SYSTEM_UNION extends Union {

        public SYSTEM_UNION() {
        }

        public SYSTEM_UNION(Pointer memory) {
            useMemory(memory);
            read();
        }
        public DWORD dwOemId;
        public SYSTEM_UNION_STRUCT systemUnionStruct = new SYSTEM_UNION_STRUCT();
    }
    /**
     * Processor architecture.
     */
    public SYSTEM_UNION processorArchitecture = new SYSTEM_UNION();
    /**
     * Page size and the granularity of page protection and commitment.
     */
    public DWORD dwPageSize;
    /**
     * Pointer to the lowest memory address accessible to applications and dynamic-link libraries (DLLs). 
     */
    public Pointer lpMinimumApplicationAddress;
    /**
     * Pointer to the highest memory address accessible to applications and DLLs. 
     */
    public Pointer lpMaximumApplicationAddress;
    /**
     * Mask representing the set of processors configured into the system. Bit 0 is processor 0; bit 31 is processor 31. 
     */
    public DWORD_PTR dwActiveProcessorMask;
    /**
     * Number of processors in the system. 
     */
    public DWORD dwNumberOfProcessors;
    /**
     * An obsolete member that is retained for compatibility with Windows NT 3.5 and Windows Me/98/95. 
     * Use the wProcessorArchitecture, wProcessorLevel, and wProcessorRevision members to determine 
     * the type of processor. 
     *  PROCESSOR_INTEL_386
     *  PROCESSOR_INTEL_486
     *  PROCESSOR_INTEL_PENTIUM
     */
    public DWORD dwProcessorType;
    /**
     * Granularity for the starting address at which virtual memory can be allocated.
     */
    public DWORD dwAllocationGranularity;
    /**
     * System's architecture-dependent processor level. It should be used only for display purposes. 
     * To determine the feature set of a processor, use the IsProcessorFeaturePresent function.
     * If wProcessorArchitecture is PROCESSOR_ARCHITECTURE_INTEL, wProcessorLevel is defined by the CPU vendor.
     * If wProcessorArchitecture is PROCESSOR_ARCHITECTURE_IA64, wProcessorLevel is set to 1.
     */
    public WORD wProcessorLevel;
    /**
     * Architecture-dependent processor revision.
     */
    public WORD wProcessorRevision;
}

I had a look at other structures and ended up in adding the ByReference-Constructors to the Union and Structure-Objects. Furthermore i initialized Union and Structure Objects directly with the new operator instead of using the previous static ByReference-construct. Don´t know if this solution is "good jna-style" - but it works ;)

from jna.

dblock avatar dblock commented on August 22, 2024

Can you please create a failing test, apply a fix and make a pull request?

from jna.

dblock avatar dblock commented on August 22, 2024

I got a Windows 7 64-bit here and the code in 3.4.x works as expected. There were quite a few changes around these structures. I am going to close this for now, please reopen if you still see this problem in newer JNA.

from jna.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.