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

Fix variant constructors that threw an error immediately #404

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Bug Fixes
* [#382](https://github.com/twall/jna/pull/382): Fixed memory allocation in `com.sun.jna.platform.win32.WTypes.LPWSTR` and `LPSTR` constructors - [@junak-michal](https://github.com/junak-michal).
* Fix publish doc links - [@bhamail](https://github.com/bhamail).
* [#388](https://github.com/twall/jna/issues/388): Ensure native library always opened with provided flags - [@zolyfarkas](https://github.com/zolyfarkas).
* [#404](https://github.com/twall/jna/pull/404): Fix VARIANT constructors for int, short, and long - [@lwahonen](https://github.com/lwahonen).

Release 4.1
===========
Expand Down
32 changes: 29 additions & 3 deletions contrib/platform/src/com/sun/jna/platform/win32/Variant.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,32 @@ public static class VARIANT extends Union {

public static class ByReference extends VARIANT implements
Structure.ByReference {
public ByReference(VARIANT variant) {
setValue(variant.getVarType(), variant.getValue());
}

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

public ByReference() {
super();
}
}

public static class ByValue extends VARIANT implements
Structure.ByValue {
public ByValue(VARIANT variant) {
setValue(variant.getVarType(), variant.getValue());
}

public ByValue(Pointer variant) {
super(variant);
}

public ByValue() {
super();
}
}

public _VARIANT _variant;
Expand Down Expand Up @@ -170,17 +196,17 @@ public VARIANT(DATE value) {

public VARIANT(short value) {
this();
this.setValue(VT_I2, value);
this.setValue(VT_I2, new SHORT(value));
}

public VARIANT(int value) {
this();
this.setValue(VT_I4, value);
this.setValue(VT_I4, new LONG(value));
}

public VARIANT(long value) {
this();
this.setValue(VT_I8, value);
this.setValue(VT_I8, new LONGLONG(value));
}

public VARIANT(float value) {
Expand Down
22 changes: 17 additions & 5 deletions contrib/platform/test/com/sun/jna/platform/win32/VariantTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import com.sun.jna.platform.win32.WinNT.HRESULT;
import com.sun.jna.ptr.DoubleByReference;

import java.util.Date;

public class VariantTest extends TestCase {

public static void main(String[] args) {
Expand Down Expand Up @@ -56,15 +58,25 @@ public void testVariantDate() {

VARIANT variantDate = new VARIANT(new DATE(pvtime.getValue()));
}

public void testVariantRecord() {
VARIANT._VARIANT.__VARIANT.BRECORD pvRecord = new VARIANT._VARIANT.__VARIANT.BRECORD();
VARIANT._VARIANT.__VARIANT.BRECORD pvRecord = new VARIANT._VARIANT.__VARIANT.BRECORD();
VARIANT._VARIANT.__VARIANT.BRECORD pvRecord2;

VARIANT variant = new VARIANT();
variant.setValue(Variant.VT_RECORD, pvRecord);

pvRecord2 = (VARIANT._VARIANT.__VARIANT.BRECORD)variant.getValue();
}


public void testVariantConstructors() {
VARIANT variant = new VARIANT((short) 1);
variant = new VARIANT((int) 1);
variant = new VARIANT((long) 1);
variant = new VARIANT((float) 1);
variant = new VARIANT((double) 1);
variant = new VARIANT("1");
variant = new VARIANT(true);
variant = new VARIANT(new Date());
}
}