HelloWorld 善戰者,求之于勢,不責于人;故能擇人而任勢。

          知止而后有定,定而后能靜,靜而后能安,安而后能慮,慮而后能得。物有本末,事有終始。知所先后,則近道矣。

            BlogJava :: 首頁 ::  :: 聯系 ::  :: 管理 ::
            167 隨筆 :: 1 文章 :: 40 評論 :: 0 Trackbacks
          <2007年11月>
          28293031123
          45678910
          11121314151617
          18192021222324
          2526272829301
          2345678

          留言簿(5)

          隨筆分類(156)

          隨筆檔案(159)

          文章分類(1)

          相冊

          收藏夾(1)

          聯接技術類文章

          最新隨筆

          搜索

          最新評論

          import java.lang.reflect.Field;
          import java.lang.reflect.Method;
          import java.util.Iterator;
          import java.util.Vector;

          public class FreeDynamicDll {
           static {
            // 首先確保這些dll文件存在
            System.load("c:/test/Decode.dll");
           }

           /**
            * 卸載已經裝載的dll
            *
            * @param dllName
            *            庫名,如Decode.dll
            */
           

           private synchronized void freeDll(String dllName) {
            try {
             ClassLoader classLoader = this.getClass().getClassLoader();
             Field field = ClassLoader.class.getDeclaredField("nativeLibraries");
             field.setAccessible(true);
             Vector<Object> libs = (Vector<Object>) field.get(classLoader);
             Iterator<Object> it = libs.iterator();
             Object o;
             while (it.hasNext()) {
              o = it.next();
              Field[] fs = o.getClass().getDeclaredFields();
              boolean hasInit = false;
              for (int k = 0; k < fs.length; k++) {
               if (fs[k].getName().equals("name")) {
                fs[k].setAccessible(true);
                String dllPath = fs[k].get(o).toString();
                if (dllPath.endsWith(dllName)) {
                 hasInit = true;
                }
               }
              }
              if (hasInit) {
               Method finalize = o.getClass().getDeclaredMethod(
                 "finalize", new Class[0]);
               finalize.setAccessible(true);
               finalize.invoke(o, new Object[0]);
               it.remove();       
               libs.remove(o);
              }
             }

            } catch (Exception e) {
             e.printStackTrace();
            }
           }

           
           public static void main(String args[]) {
            FreeDynamicDll t = new FreeDynamicDll();
            t.freeDll("Decode.dll");
           }
          }



          </script>

          posted on 2007-11-26 14:31 helloworld2008 閱讀(1314) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 疏勒县| 昂仁县| 邵阳县| 望谟县| 西畴县| 青冈县| 夹江县| 尚志市| 安西县| 张家口市| 鄯善县| 西丰县| 绥芬河市| 涟源市| 镇康县| 景泰县| 西盟| 北川| 岳普湖县| 望都县| 西宁市| 临沧市| 垦利县| 彰武县| 澄城县| 兴宁市| 利辛县| 区。| 江油市| 宜黄县| 视频| 凤台县| 嘉黎县| 西平县| 军事| 宣城市| 晋江市| 凤阳县| 聊城市| 子长县| 临沧市|