前提・実現したいこと
現在、JNIを使用してGUIを作っています。しかし、2つ問題が発生しました。
発生している問題・エラーメッセージ
1つ目 Exceptionのスロー
Exception in thread "main" java.lang.UnsatisfiedLinkError: org.yukkuri.jyl.base.swing.JylF rame.testDot(II)V at org.yukkuri.jyl.base.swing.JylFrame.testDot(Native Method) at org.yukkuri.jyl.base.swing.JylFrame.<init>(JylFrame.java:18) at Test.main(Test.java:7)
2つ目 ドットが表示されない
なし
該当のソースコード
C++(C?)
1#include <windows.h> 2#include <tchar.h> 3 4#include "jni.h" 5#include "org_yukkuri_jyl_base_swing_JylFrame.h" 6 7static HWND hwnd; 8HDC hdc; 9PAINTSTRUCT ps; 10 11static int R = 255; 12static int G = 255; 13static int B = 255; 14 15LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM ); 16 17JNIEXPORT void JNICALL Java_org_yukkuri_jyl_base_swing_JylFrame_nInitFrame( JNIEnv *env, jobject obj, jint x, jint y, jint width, jint height ) 18{ 19 HINSTANCE hInstance = GetModuleHandle( 0 ); 20 21 WNDCLASS wnd; MSG msg; 22 23 wnd.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; // 縦、横方向にサイズ変更時再描画 24 wnd.lpfnWndProc = WndProc; 25 wnd.cbClsExtra = wnd.cbWndExtra; 26 wnd.hInstance = hInstance; 27 wnd.hIcon = LoadIcon( NULL, IDI_APPLICATION ); 28 wnd.hCursor = LoadCursor( NULL, IDC_ARROW ); 29 wnd.hbrBackground = (HBRUSH)GetStockObject( BLACK_BRUSH ); 30 wnd.lpszMenuName = NULL; 31 wnd.lpszClassName = ( "STATIC" ); 32 33 if( !RegisterClass( &wnd ) ){ 34 MessageBox( NULL, TEXT( "window option error" ), TEXT( "error" ), MB_ICONSTOP ); 35 return; 36 } 37 38 hwnd = CreateWindow( 39 TEXT( "STATIC" ), TEXT( "frame" ), 40 WS_OVERLAPPEDWINDOW, 41 (int)x, (int)y, 42 (int)width, (int)height, 43 NULL, NULL, 44 hInstance, NULL 45 ); 46 47 if( hwnd == NULL ){ 48 MessageBox( NULL, TEXT( "window error" ), TEXT( "error" ), MB_ICONSTOP ); 49 return; 50 } 51 52 ShowWindow( hwnd, SW_SHOW ); 53 54// MessageBox( NULL, TEXT( "window created" ), TEXT( "message" ), MB_ICONINFORMATION ); 55 56 while( GetMessage( &msg, NULL, 0, 0 ) ) DispatchMessage( &msg ); 57} 58 59LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam ) 60{ 61 switch( msg ){ 62 case WM_DESTROY: 63 PostQuitMessage( 0 ); 64 return 0; 65 } 66 return DefWindowProc( hwnd, msg, wParam, lParam ); 67} 68 69JNIEXPORT void JNICALL Java_yukkuri_jyl_base_swing_JylFrame_testDot( JNIEnv *env, jobject obj, jint x, jint y ) 70{ 71 hdc = GetDC( hwnd ); 72 73 SetPixel( hdc, (int)x, (int)y, RGB( R, G, B ) ); 74 75 ReleaseDC( hwnd, hdc ); 76}
Java
1package org.yukkuri.jyl.base.swing; 2 3public class JylFrame 4{ 5 private String title = "frame"; 6 private int x = 100; private int y = 100; 7 private int width = 640; private int height = 480; 8 9 static 10 { 11 System.load( System.getProperty( "user.dir" ) + "\native\windows\Frame.dll" ); 12 } 13 14 public JylFrame() 15 { 16 nInitFrame( x, y, width, height ); 17 18 testDot( 100, 100 ); 19 } 20 21 private native void nInitFrame( int x, int y, int width, int height ); 22 23 private native void testDot( int x, int y ); 24} 25
試したこと
1つ目は、パッケージに問題がある、と書いてあるのが見受けられましたが、パッケージには問題ないようです。
2つ目は、外部から描画関数を呼び出すために、関数ごとにGetDCを使用しています。
補足情報(FW/ツールのバージョンなど)
Windows、MinGW、Java8を使用しています。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/10/29 11:15
2018/10/29 16:41
2018/11/01 11:22
2018/11/01 16:29 編集
2018/11/04 07:51
2018/11/04 15:13
2018/11/04 15:34
2018/11/04 15:37
2018/11/04 16:00 編集
2018/11/04 16:05