Giter Club home page Giter Club logo

Comments (2)

twall avatar twall commented on August 22, 2024

On May 21, 2012, at 5:18 PM, GiGurra wrote:

The FAQ states:
"
How do I map a native long type?
Actually, no one ever asks this question, but they really need the answer. Do not use Java long!

On Windows, you can use a Java int, since the native long type is always 32 bits. On any other platform, the type may be 32 or 64 bits, so you should use the NativeLong type to ensure the proper size is used.
"

This is incorrect. I am not aware if this was the case on previous windows version but it certainly isn't the case on my windows 7 machine (a standard i7 on windows 7 64bit).

I'm not sure what you're referring to. A "long" on windows is 32 bits whether on 32-bit or 64-bit windows. This has been the case since 64-bit windows was introduced.

ALSO MORE WORRYING

The JNA source assumes DWORD and NativeLong are always 4 byte sized, also wrong, and this leads to big errors.

Example: I cannot use mappings like

public static class MEMORY_BASIC_INFORMATION extends Structure {
public Pointer BaseAddress;
public Pointer AllocationBase;
public NativeLong AllocationProtect;
public NativeLong RegionSize;
public NativeLong State;
public NativeLong Protect;
public NativeLong Type;
}

Nor should you. The platform.jar from the contrib directory defines DWORD and SIZE_T. RegionSize is of type SIZE_T, which is equivalent to neither DWORD nor NativeLong.

I don't understand how this has not been caught ......

Perhaps because it's not a bug. I don't understand how your incorrect mappings were not caught. No, wait, you forgot to write corresponding tests, that must be it.

This issue is closed.

from jna.

GiGurra avatar GiGurra commented on August 22, 2024

Interesting!

You indeed seem to be correct here. Turns out that my eclipse somehow opened the mingw variant of winnt.h (although I use ms VC compiler in eclipse), and that defines MEMORY_BASIC_INFORMATION as:

typedef struct _MEMORY_BASIC_INFORMATION {
PVOID BaseAddress;
PVOID AllocationBase;
DWORD AllocationProtect;
DWORD RegionSize;
DWORD State;
DWORD Protect;
DWORD Type;
} MEMORY_BASIC_INFORMATION,*PMEMORY_BASIC_INFORMATION;

from msdn:

typedef struct _MEMORY_BASIC_INFORMATION {
PVOID BaseAddress;
PVOID AllocationBase;
DWORD AllocationProtect;
SIZE_T RegionSize;
DWORD State;
DWORD Protect;
DWORD Type;
} MEMORY_BASIC_INFORMATION, *PMEMORY_BASIC_INFORMATION;

I was sure I tested sizeof(long), but I can't have since it works with size_t...

With Size_T instead it all works. Thank you for pointing me in the right direction :).

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.