日期:2014-05-20 浏览次数:21311 次
#define MYLIBAPI extern "C" __declspec( dllexport ) #define CLIENT_INPUT_SIZE 4 struct UserStruct{ long id; wchar_t* name; int age; }; MYLIBAPI void sayUser(UserStruct* pUserStruct);
#include "stdafx.h" #include "dlljna2.h" #include "iostream" void sayUser(UserStruct* pUserStruct){ std::wcout.imbue(std::locale("chs")); std::wcout<<L"ID:"<<pUserStruct->id<<std::endl; std::wcout<<L"姓名:"<<pUserStruct->name<<std::endl; std::wcout<<L"年龄:"<<pUserStruct->age<<std::endl; }
package test.cn; import test.cn.TestDll1Service.TestDll1.UserStruct; import com.sun.jna.Library; import com.sun.jna.NativeLong; import com.sun.jna.Structure; import com.sun.jna.Native; import com.sun.jna.WString; public class TestDll1Service { public final static int CLIENT_INPUT_SIZE = 4; public interface TestDll1 extends Library { TestDll1 INSTANCE = (TestDll1) Native.loadLibrary("dlljna2", TestDll1.class); public void say(WString value); public static class UserStruct extends Structure { public NativeLong id; public WString name; public int age; } public void sayUser(UserStruct struct); } public TestDll1Service() { } public static void main(String[] args) { UserStruct userStruct = new UserStruct(); userStruct.id = new NativeLong(100); userStruct.age = 30; userStruct.name = new WString("沈东良"); TestDll1.INSTANCE.sayUser(userStruct); } }
#include "stdafx.h" #include "dlljna2.h" #include "iostream" void sayUser(UserStruct* pUserStruct){ std::wcout.imbue(std::locale("chs")); for(int i = 0; i < CLIENT_INPUT_SIZE; i++) { std::wcout<<L"ID:"<<pUserStruct[i].id<<std::endl; std::wcout<<L"姓名:"<<pUserStruct[i].name<<std::endl; std::wcout<<L"年龄:"<<pUserStruct[i].age<<std::endl; }
package test.cn; import test.cn.TestDll1Service.TestDll1.UserStruct; import com.sun.jna.Library; import com.sun.jna.NativeLong; import com.sun.jna.Structure; import com.sun.jna.Native; import com.sun.jna.WString; public class TestDll1Service { public final static int CLIENT_INPUT_SIZE = 4; public interface TestDll1 extends Library { TestDll1 INSTANCE = (TestDll1) Native.loadLibrary("dlljna2", TestDll1.class); public void say(WString value); public static class UserStruct extends Structure { public NativeLong id; public WString name; public int age; } public void sayUser(UserStruct[] struct); } public TestDll1Service() { } public static void main(String[] args) { UserStruct[] userStructs = new UserStruct[CLIENT_INPUT_SIZE]; for(int i = 0; i < CLIENT_INPUT_SIZE; i++) { userStructs[i] =new UserStruct(); userStructs[i].id = new NativeLong(100); userStructs[i].age = 30; userStructs[i].name = new WString("沈东良"); } TestDll1.INSTANCE.sayUser(userStructs); } }