use of com.sun.jna.platform.win32.Ddeml.HCONV in project jna by java-native-access.
the class DdemlTest method testInitialization.
@Test
public void testInitialization() {
DdeCallback callback = new Ddeml.DdeCallback() {
public WinDef.PVOID ddeCallback(int wType, int wFmt, Ddeml.HCONV hConv, Ddeml.HSZ hsz1, Ddeml.HSZ hsz2, Ddeml.HDDEDATA hData, BaseTSD.ULONG_PTR lData1, BaseTSD.ULONG_PTR lData2) {
return new PVOID();
}
};
DWORDByReference pidInst = new DWORDByReference();
int initResult = Ddeml.INSTANCE.DdeInitialize(pidInst, callback, Ddeml.APPCMD_CLIENTONLY, 0);
assertEquals(Ddeml.DMLERR_NO_ERROR, initResult);
boolean uninitResult = Ddeml.INSTANCE.DdeUninitialize(pidInst.getValue().intValue());
assertTrue(uninitResult);
}
use of com.sun.jna.platform.win32.Ddeml.HCONV in project jna by java-native-access.
the class DdemlTest method testStringHandling.
@Test
public void testStringHandling() {
DdeCallback callback = new Ddeml.DdeCallback() {
public WinDef.PVOID ddeCallback(int wType, int wFmt, Ddeml.HCONV hConv, Ddeml.HSZ hsz1, Ddeml.HSZ hsz2, Ddeml.HDDEDATA hData, BaseTSD.ULONG_PTR lData1, BaseTSD.ULONG_PTR lData2) {
return new PVOID();
}
};
DWORDByReference pidInst = new DWORDByReference();
int initResult = Ddeml.INSTANCE.DdeInitialize(pidInst, callback, Ddeml.APPCMD_CLIENTONLY, 0);
assertEquals(Ddeml.DMLERR_NO_ERROR, initResult);
HSZ handle = Ddeml.INSTANCE.DdeCreateStringHandle(pidInst.getValue().intValue(), "Test", Ddeml.CP_WINUNICODE);
assertNotNull(handle);
// String in DDE can not exceed 255 Chars
Memory mem = new Memory(256 * 2);
Ddeml.INSTANCE.DdeQueryString(pidInst.getValue().intValue(), handle, mem, 256, Ddeml.CP_WINUNICODE);
assertEquals("Test", mem.getWideString(0));
synchronized (mem) {
}
assertTrue(Ddeml.INSTANCE.DdeFreeStringHandle(pidInst.getValue().intValue(), handle));
// Test overlong creation -- according to documentation this must fail
StringBuilder testString = new StringBuilder();
for (int i = 0; i < 30; i++) {
testString.append("0123456789");
}
HSZ handle2 = Ddeml.INSTANCE.DdeCreateStringHandle(pidInst.getValue().intValue(), testString.toString(), Ddeml.CP_WINUNICODE);
assertNull(handle2);
boolean uninitResult = Ddeml.INSTANCE.DdeUninitialize(pidInst.getValue().intValue());
assertTrue(uninitResult);
}
use of com.sun.jna.platform.win32.Ddeml.HCONV in project jna by java-native-access.
the class DdemlTest method testMemoryHandling.
@Test
public void testMemoryHandling() {
DdeCallback callback = new Ddeml.DdeCallback() {
public WinDef.PVOID ddeCallback(int wType, int wFmt, Ddeml.HCONV hConv, Ddeml.HSZ hsz1, Ddeml.HSZ hsz2, Ddeml.HDDEDATA hData, BaseTSD.ULONG_PTR lData1, BaseTSD.ULONG_PTR lData2) {
return new PVOID();
}
};
DWORDByReference pidInst = new DWORDByReference();
int initResult = Ddeml.INSTANCE.DdeInitialize(pidInst, callback, Ddeml.APPCMD_CLIENTONLY, 0);
assertEquals(Ddeml.DMLERR_NO_ERROR, initResult);
// Acquire dummy handle
HSZ hsz = Ddeml.INSTANCE.DdeCreateStringHandle(pidInst.getValue().intValue(), "Dummy", Ddeml.CP_WINUNICODE);
String testStringPart1 = "Hallo ";
String testStringPart2 = "Welt";
// Create Handle
// String in DDE can not exceed 255 Chars
Memory mem = new Memory(256 * 2);
mem.setWideString(0, testStringPart1);
HDDEDATA data = Ddeml.INSTANCE.DdeCreateDataHandle(pidInst.getValue().intValue(), mem, testStringPart1.length() * 2, 0, hsz, WinUser.CF_UNICODETEXT, Ddeml.HDATA_APPOWNED);
mem.setWideString(0, testStringPart2);
Ddeml.INSTANCE.DdeAddData(data, mem, (testStringPart2.length() + 1) * 2, testStringPart1.length() * 2);
DWORDByReference dataSize = new DWORDByReference();
Pointer resultPointer = Ddeml.INSTANCE.DdeAccessData(data, dataSize);
assertEquals((testStringPart1.length() + testStringPart2.length() + 1) * 2, dataSize.getValue().intValue());
assertEquals(testStringPart1 + testStringPart2, resultPointer.getWideString(0));
boolean result = Ddeml.INSTANCE.DdeUnaccessData(data);
int readSize = Ddeml.INSTANCE.DdeGetData(data, mem, (int) mem.size(), 0);
assertEquals((testStringPart1.length() + testStringPart2.length() + 1) * 2, readSize);
assertEquals(testStringPart1 + testStringPart2, mem.getWideString(0));
assertTrue(result);
result = Ddeml.INSTANCE.DdeFreeDataHandle(data);
assertTrue(result);
synchronized (mem) {
}
result = Ddeml.INSTANCE.DdeUninitialize(pidInst.getValue().intValue());
assertTrue(result);
}
use of com.sun.jna.platform.win32.Ddeml.HCONV in project jna by java-native-access.
the class DdemlUtilTest method testExecute.
@Test
public void testExecute() throws InterruptedException {
final String serviceName = "TestService";
final String topicName = "TestTopic";
final String testExecute = "Execute�������";
final CountDownLatch executeReceived = new CountDownLatch(1);
StandaloneDdeClient client = null;
StandaloneDdeClient server = null;
try {
client = new StandaloneDdeClient() {
{
this.initialize(Ddeml.APPCMD_CLIENTONLY | Ddeml.CBF_SKIP_REGISTRATIONS | Ddeml.CBF_SKIP_UNREGISTRATIONS);
}
};
server = new StandaloneDdeClient() {
private final ConnectHandler connectHandler = new ConnectHandler() {
public boolean onConnect(int transactionType, HSZ topic, HSZ service, Ddeml.CONVCONTEXT convcontext, boolean sameInstance) {
return topicName.equals(queryString(topic));
}
};
private final ExecuteHandler executeHandler = new ExecuteHandler() {
public int onExecute(int transactionType, HCONV hconv, HSZ topic, Ddeml.HDDEDATA commandStringData) {
Pointer[] pointer = new Pointer[] { accessData(commandStringData, null) };
try {
String commandString = pointer[0].getWideString(0);
if (testExecute.equals(commandString) && queryString(topic).equals(topicName)) {
executeReceived.countDown();
return Ddeml.DDE_FACK;
}
} finally {
synchronized (pointer) {
unaccessData(commandStringData);
}
}
return Ddeml.DDE_FNOTPROCESSED;
}
};
{
registerConnectHandler(connectHandler);
registerExecuteHandler(executeHandler);
this.initialize(Ddeml.APPCMD_FILTERINITS | Ddeml.CBF_SKIP_ALLNOTIFICATIONS);
}
};
server.nameService(serviceName, Ddeml.DNS_REGISTER);
IDdeConnection con = client.connect(serviceName, topicName, null);
con.execute(testExecute, 5 * 1000, null, null);
assertTrue(executeReceived.await(5, TimeUnit.SECONDS));
} finally {
closeQuitely(client);
closeQuitely(server);
}
}
use of com.sun.jna.platform.win32.Ddeml.HCONV in project jna by java-native-access.
the class DdemlUtilTest method testConnectDisconnect.
@Test
public void testConnectDisconnect() throws InterruptedException {
final String serviceName = "TestService";
final String topicName = "TestTopic";
final CountDownLatch connectLatch = new CountDownLatch(1);
final CountDownLatch disconnectLatch = new CountDownLatch(1);
StandaloneDdeClient client = null;
StandaloneDdeClient server = null;
try {
client = new StandaloneDdeClient() {
{
this.initialize(Ddeml.APPCMD_CLIENTONLY | Ddeml.CBF_SKIP_REGISTRATIONS | Ddeml.CBF_SKIP_UNREGISTRATIONS);
}
};
server = new StandaloneDdeClient() {
private final ConnectHandler connectHandler = new ConnectHandler() {
public boolean onConnect(int transactionType, HSZ topic, HSZ service, Ddeml.CONVCONTEXT convcontext, boolean sameInstance) {
return topicName.equals(queryString(topic));
}
};
private final ConnectConfirmHandler connectConfirmHandler = new ConnectConfirmHandler() {
public void onConnectConfirm(int transactionType, HCONV hconv, HSZ topic, HSZ service, boolean sameInstance) {
if (topicName.equals(queryString(topic))) {
connectLatch.countDown();
}
}
};
private final DisconnectHandler disconnectHandler = new DisconnectHandler() {
public void onDisconnect(int transactionType, HCONV hconv, boolean sameInstance) {
disconnectLatch.countDown();
}
};
{
registerConnectHandler(connectHandler);
registerConnectConfirmHandler(connectConfirmHandler);
registerDisconnectHandler(disconnectHandler);
this.initialize(Ddeml.APPCMD_FILTERINITS | Ddeml.CBF_SKIP_REGISTRATIONS | Ddeml.CBF_SKIP_UNREGISTRATIONS);
}
};
server.nameService(serviceName, Ddeml.DNS_REGISTER);
IDdeConnection connection = client.connect(serviceName, topicName, null);
assertTrue("Failed to connect", connectLatch.await(5, TimeUnit.SECONDS));
connection.close();
assertTrue("Failed to disconnect", disconnectLatch.await(5, TimeUnit.SECONDS));
} finally {
closeQuitely(client);
closeQuitely(server);
}
}
Aggregations