wer.dll
에 포함 된 Windows 오류보고 API를 Win32 API의 일부로 사용할 수 있습니다.
Java에서 DLL 기반 함수를 호출하는 가장 좋은 방법은 적극적으로 개발 된 Java Native Access project을 사용하는 것입니다. 필요한 Win32 API를 호출을하기 위해
, 우리는 적어도 이러한 기능에 대해 JNA을 가르 칠해야합니다 :
HRESULT WINAPI WerReportCreate(
__in PCWSTR pwzEventType,
__in WER_REPORT_TYPE repType,
__in_opt PWER_REPORT_INFORMATION pReportInformation,
__out HREPORT *phReportHandle
);
HRESULT WINAPI WerReportSubmit(
__in HREPORT hReportHandle,
__in WER_CONSENT consent,
__in DWORD dwFlags,
__out_opt PWER_SUBMIT_RESULT pSubmitResult
);
하고이 구조체 :
typedef struct _WER_REPORT_INFORMATION {
DWORD dwSize;
HANDLE hProcess;
WCHAR wzConsentKey[64];
WCHAR wzFriendlyEventName[128];
WCHAR wzApplicationName[128];
WCHAR wzApplicationPath[MAX_PATH];
WCHAR wzDescription[512];
HWND hwndParent;
} WER_REPORT_INFORMATION, *PWER_REPORT_INFORMATION;
이 작업을 수행하기를, 우리는 WER.java를 만듭니다 :
package com.sun.jna.platform.win32;
import com.sun.jna.Native;
import com.sun.jna.Pointer;
import com.sun.jna.platform.win32.WinDef.HWND;
import com.sun.jna.platform.win32.WinNT.HANDLE;
import com.sun.jna.platform.win32.WinNT.HRESULT;
import com.sun.jna.ptr.PointerByReference;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;
public interface Wer extends StdCallLibrary {
Wer INSTANCE = (Wer) Native.loadLibrary("wer", Wer.class,
W32APIOptions.DEFAULT_OPTIONS);
public static class HREPORT extends HANDLE {
public HREPORT() { }
public HREPORT(Pointer p) { super(p); }
public HREPORT(int value) { super(new Pointer(value)); }
}
public static class HREPORTByReference extends ByReference {
public HREPORTByReference() {
this(null);
}
public HREPORTByReference(HREPORT h) {
super(Pointer.SIZE);
setValue(h);
}
public void setValue(HREPORT h) {
getPointer().setPointer(0, h != null ? h.getPointer() : null);
}
public HREPORT getValue() {
Pointer p = getPointer().getPointer(0);
if (p == null)
return null;
if (WinBase.INVALID_HANDLE_VALUE.getPointer().equals(p))
return (HKEY) WinBase.INVALID_HANDLE_VALUE;
HREPORT h = new HREPORT();
h.setPointer(p);
return h;
}
}
public class WER_REPORT_INFORMATION extends Structure {
public DWORD dwSize;
public HANDLE hProcess;
public char[] wzConsentKey = new char[64];
public char[] wzFriendlyEventName = new char[128];
public char[] wzApplicationName = new char[MAX_PATH];
public char[] wzDescription = new char[512];
public HWND hwndParent;
dwSize = new DWORD(size());
}
public abstract class WER_REPORT_TYPE {
public static final int WerReportNonCritical = 0;
public static final int WerReportCritical = 1;
public static final int WerReportApplicationCrash = 2;
public static final int WerReportApplicationHang = 3;
public static final int WerReportKernel = 4;
public static final int WerReportInvalid = 5;
}
HRESULT WerReportCreate(String pwzEventType, int repType, WER_REPORT_INFORMATION pReportInformation, HREPORTByReference phReportHandle);
HRESULT WerReportSubmit(HREPORT hReportHandle, int consent, DWORD dwFlags, WER_SUBMIT_RESULT.ByReference pSubmitResult);
}
난 그냥 몇 분은 MSDN dcoumentation에서 함께 그 노크 s - 불완전하거나 올바르지 않은 경우 JNA 웹 사이트에 tons of examples 및 pretty good documentation이 있습니다.
JNA를 실행하려면 jna.jar
과 platform.jar
이 필요하며 JNA 웹 사이트에서 가져올 수도 있습니다.
[NTEventLogAppender] (http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/nt/NTEventLogAppender.html) 등은 무엇입니까? 편집 : [아마도 관련 질문] (http://stackoverflow.com/questions/164879/how-to-write-from-java-to-the-windows-event-log) –
@VineetReynolds, "보내기 Microsoft에 버그 리포트 "조치? –
[Nope. 이는 충돌시에만 발생하도록 구성됩니다.] (http://support.microsoft.com/kb/310414) –