Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subclasses don't get constructors #117

Open
berntie opened this issue Feb 1, 2019 · 0 comments
Open

Subclasses don't get constructors #117

berntie opened this issue Feb 1, 2019 · 0 comments

Comments

@berntie
Copy link

berntie commented Feb 1, 2019

I have the following struct:

typedef struct JnaExport
{
	int AftrNr;
	int KndNr;
	int ObjectVersion;

	char* JsonData;
	tOutputStatus OutputStatus;
} AuftragskopfOutputDtoJna;

with tOutputStatus being

enum tOutputStatus
{
	OUTPUTSTATUS_OK_WITH_DATA = 100,
	OUTPUTSTATUS_ERROR_NOT_FOUND = -404, //
        // ... many more
};

From that JNAerator generates the following Java class:

public class AuftragskopfOutputDtoJna extends Structure {
	public int AftrNr;
	public int KndNr;
	public int ObjectVersion;
	public Pointer JsonData;
	public int OutputStatus;

	public AuftragskopfOutputDtoJna() {
		super();
	}

	protected List<? > getFieldOrder() {
		return Arrays.asList("AftrNr", "KndNr", "ObjectVersion", "JsonData", "OutputStatus");
	}

	public AuftragskopfOutputDtoJna(int AftrNr, int KndNr, int ObjectVersion, Pointer JsonData, int OutputStatus) {
		super();
		this.AftrNr = AftrNr;
		this.KndNr = KndNr;
		this.ObjectVersion = ObjectVersion;
		this.JsonData = JsonData;
		this.OutputStatus = OutputStatus;
	}

	public AuftragskopfOutputDtoJna(Pointer peer) {
		super(peer);
	}

	public static class ByReference extends AuftragskopfOutputDtoJna implements Structure.ByReference {
	};
	public static class ByValue extends AuftragskopfOutputDtoJna implements Structure.ByValue {
	};
}

The documentation says "JNAerated structs all get ByReference and ByValue subclasses (that have a struct-pointer-copy constructor)" but my subclasses don't get that constructor. That's annoying because I don't know how to obtain a AuftragskopfOutputDtoJna.ByReference without that constructor and I'm thus forced to rely on a deprecated method for freeing memory:

	/**
	 * ...
	 * @deprecated use the safer method {@link #deleteAuftragskopfOutputDto(AuftragskopfOutputDtoJna.ByReference[])} instead
	 */
	@Deprecated 
	void deleteAuftragskopfOutputDto(PointerByReference dto);

How am I supposed to fix this? And could someone update the documentation, please.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant