JNATIVE 호출 dll 메서드
4288 단어 jnative
C 언어 코드:
#include "stdafx.h"
#include <Windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <string.h>
typedef int (*bOpenUsb20Video)();
typedef int (*sGetBarData)(char *out);
typedef int (*bCloseUsb20)();
int main(int argc, char* argv[])
{
HINSTANCE hDll; //DLL
bOpenUsb20Video DllbOpenUsb20Video;
sGetBarData DllsGetBarData;
bCloseUsb20 DllbCloseUsb20;
hDll = LoadLibrary("dllLpDecode.dll");
if (hDll != NULL)
{
DllbOpenUsb20Video = (bOpenUsb20Video)GetProcAddress(hDll,"bOpenUsb20Video");
if(DllbOpenUsb20Video==NULL)
return 0;
DllsGetBarData = (sGetBarData)GetProcAddress(hDll,"sGetBarData");
if(DllsGetBarData==NULL)
return 0;
DllbCloseUsb20 = (bCloseUsb20)GetProcAddress(hDll,"bCloseUsb20");
if(DllbCloseUsb20==NULL)
return 0;
}
if (0 != DllbOpenUsb20Video ())
return 0;
int ret;
char out[256];
int count=10;
while (count)
{
ret = DllsGetBarData (out);
if (ret == 1)
{
printf ("result:%s\r
",out);
count --;
}
Sleep (100);
}
DllbCloseUsb20 ();
FreeLibrary(hDll);
return 0;
}
jnative를 사용하여 덮어쓰는 방법:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.tfsm.movie.camera;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.xvolks.jnative.JNative;
import org.xvolks.jnative.Type;
import org.xvolks.jnative.pointers.Pointer;
import org.xvolks.jnative.pointers.memory.MemoryBlockFactory;
/**
*
* @author Administrator
*/
public class HY100CameraDecoder {
static {
// HY100
System.loadLibrary("lib/dllLpDecode");
}
public boolean openCamera() {
try {
JNative openCamera = new JNative("lib/dllLpDecode", "bOpenUsb20Video");
openCamera.setRetVal(Type.INT);
openCamera.invoke();
return openCamera.getRetValAsInt() == 0;
} catch (Exception ex) {
Logger.getLogger(HY100CameraDecoder.class.getName()).log(Level.SEVERE, null, ex);
return false;
}
}
public CameraDecodeResult getDecodeData() {
try {
JNative decodeData = new JNative("lib/dllLpDecode", "sGetBarData");
Pointer p = new Pointer(MemoryBlockFactory.createMemoryBlock(4 * 256));
decodeData.setParameter(0, p);
decodeData.setRetVal(Type.INT);
decodeData.invoke();
int resultCode = decodeData.getRetValAsInt();
CameraDecodeResult reuslt = new CameraDecodeResult();
// 1
if (resultCode == 1) {
String result = new String(p.getAsString().getBytes(), "UTF-8");
return reuslt.setSuccess(true).setResult(result);
}else{
return reuslt;
}
} catch (Exception ex) {
Logger.getLogger(HY100CameraDecoder.class.getName()).log(Level.SEVERE, null, ex);
return new CameraDecodeResult();
}
}
public void closeCamera() {
try {
JNative closeCamera = new JNative("lib/dllLpDecode", "bCloseUsb20");
closeCamera.setRetVal(Type.INT);
closeCamera.invoke();
} catch (Exception ex) {
Logger.getLogger(HY100CameraDecoder.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
JNative에서 DLL에 전송되는 배열텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.