bcb中的dll调用dll例子

bcb中的dll调用dll例子

#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>

你可能感兴趣的:(bcb中的dll调用dll例子)