HelloWorld 善战者,求之于势,不责于人;故能择人而任势。

知止而后有定,定而后能静,静而后能安,安而后能虑,虑而后能得。物有本末,事有终始。知所先后,则近道矣。

  BlogJava :: 首页 ::  :: 联系 ::  :: 管理 ::
  167 随笔 :: 1 文章 :: 40 评论 :: 0 Trackbacks

#include <windows.h>
#include "string.h"
#include "Decode.h"

#pragma argsused
typedef int (__stdcall *fun_AddFun)(int Data);
HINSTANCE gLib = NULL;
fun_AddFun gFun = NULL;
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved){
        switch(reason) {
                case DLL_PROCESS_ATTACH: {
                        char tPath[255];
                        int tSize;
                        GetModuleFileName(hinst,tPath,255);
                        tSize = strlen(tPath)-1;
                        while(tPath[tSize]!='\\') {
                                --tSize;
                        }
                        tPath[tSize+1] = 0;
                        strcat(tPath,"Test.dll");

                        gLib = LoadLibrary(tPath);
                        if(gLib == NULL) {
                                MessageBox(NULL,tPath,"Load Library Failed",MB_OK);
                                return;
                        }
                        gFun = (fun_AddFun)GetProcAddress(gLib,"AddFun");
                }
                break;
                case DLL_PROCESS_DETACH: {
                        if(gLib) {
                                FreeLibrary(gLib);
                                gLib = NULL;
                        }
                }
                break;
        }
        return 1;
}

JNIEXPORT jint JNICALL Java_Encode_Add (JNIEnv *env, jclass cls, jint a, jint b) {
        if(gFun==NULL)
                return 0;
        else {
                int tRe = gFun(100);
                return a + b + tRe;
        }              
}

 int  __declspec(dllexport) __stdcall fun_x(int a,int b)
{
        if(gFun==NULL)
                return 0;
        else {
                int tRe = gFun(100);
                return a + b + tRe;
        }              

}

 



</script>

posted on 2007-11-05 15:37 helloworld2008 阅读(1169) 评论(0)  编辑  收藏 所属分类: javaLinux/C

只有注册用户登录后才能发表评论。


网站导航: