当前位置: 技术问答>java相关
jbuilder怎么调用VC的COM组件?我刚开始接触jbuilder
来源: 互联网 发布时间:2015-01-10
本文导语: 我想知道jbuilder可以调用com的vc组件dll嘛?怎么做呢? 谢谢. 还有我想在对话框加一个快捷键,怎么加呢.我只发现加上button. 还有打印功能怎么实现? | 1. // demo.cpp : Defines the entry point for the DLL...
我想知道jbuilder可以调用com的vc组件dll嘛?怎么做呢?
谢谢.
还有我想在对话框加一个快捷键,怎么加呢.我只发现加上button.
还有打印功能怎么实现?
谢谢.
还有我想在对话框加一个快捷键,怎么加呢.我只发现加上button.
还有打印功能怎么实现?
|
1.
// demo.cpp : Defines the entry point for the DLL application.
//
#include "stdafx.h"
#include "demo.h"
#include
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
JNIEXPORT void JNICALL Java_demo_returnByte
(JNIEnv *env, jobject obj, jint ll, jbyteArray jb)
{
jint len = ll;
jbyteArray jbyteA = env->NewByteArray(len);
jclass cls = env->GetObjectClass(obj);
jmethodID id;
jbyte* a;
int i;
a = (jbyte*)env->GetByteArrayElements(jbyteA, NULL);
for(i=0; iGetArrayLength(jbyteA); i++)
a[i] = (jbyte)(i+65);
env->SetByteArrayRegion(jbyteA, 0, len - 1, a);
id = env->GetMethodID(cls, "setByte", "(I[B)V");
if(id)
{
env->CallVoidMethod(obj, id, len, jbyteA);
printf("hello");
}
else
{
printf("In class demo: void setByte(int,byte[]) not definedn");
}
env->ReleaseByteArrayElements(jbyteA, a, 0);
}
//:demo.java
public class demo
{
int len = 0;
byte[] b = null;
public native void returnByte(int l,byte[] b);
static
{
System.loadLibrary("demo");
}
public void setByte(int l,byte[] b)
{
this.len = l;
this.b = b;
}
public void print()
{
System.out.println("len = "+len);
if(b != null)
{
System.out.println("byte[] = "+ new String(b));
}
else
{
System.out.println("byte[] = "+"null");
}
}
}
用javah demo.java 生成demo.h
//:testDemo.java
public class testDemo
{
public static void main(String args[])
{
String s1 = "hello";
String s2 = "test";
String s3 = "demo";
demo d1 = new demo();
demo d2 = new demo();
demo d3 = new demo();
d1.returnByte(5,s1.getBytes());
d2.returnByte(4,s2.getBytes());
d3.returnByte(3,s3.getBytes());
d1.print();
d2.print();
d3.print();
}
}
// demo.cpp : Defines the entry point for the DLL application.
//
#include "stdafx.h"
#include "demo.h"
#include
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
JNIEXPORT void JNICALL Java_demo_returnByte
(JNIEnv *env, jobject obj, jint ll, jbyteArray jb)
{
jint len = ll;
jbyteArray jbyteA = env->NewByteArray(len);
jclass cls = env->GetObjectClass(obj);
jmethodID id;
jbyte* a;
int i;
a = (jbyte*)env->GetByteArrayElements(jbyteA, NULL);
for(i=0; iGetArrayLength(jbyteA); i++)
a[i] = (jbyte)(i+65);
env->SetByteArrayRegion(jbyteA, 0, len - 1, a);
id = env->GetMethodID(cls, "setByte", "(I[B)V");
if(id)
{
env->CallVoidMethod(obj, id, len, jbyteA);
printf("hello");
}
else
{
printf("In class demo: void setByte(int,byte[]) not definedn");
}
env->ReleaseByteArrayElements(jbyteA, a, 0);
}
//:demo.java
public class demo
{
int len = 0;
byte[] b = null;
public native void returnByte(int l,byte[] b);
static
{
System.loadLibrary("demo");
}
public void setByte(int l,byte[] b)
{
this.len = l;
this.b = b;
}
public void print()
{
System.out.println("len = "+len);
if(b != null)
{
System.out.println("byte[] = "+ new String(b));
}
else
{
System.out.println("byte[] = "+"null");
}
}
}
用javah demo.java 生成demo.h
//:testDemo.java
public class testDemo
{
public static void main(String args[])
{
String s1 = "hello";
String s2 = "test";
String s3 = "demo";
demo d1 = new demo();
demo d2 = new demo();
demo d3 = new demo();
d1.returnByte(5,s1.getBytes());
d2.returnByte(4,s2.getBytes());
d3.returnByte(3,s3.getBytes());
d1.print();
d2.print();
d3.print();
}
}