有DLL,知道里面的函数名跟参数,但是没有lib 想调用那个函数,麻烦详细说下步骤

解决方案 »

  1.   

            HINSTANCE h;
    int *fun;
    h   =   LoadLibrary("ycode.dll");
    if(h!=NULL)
    {
    fun =(int *)GetProcAddress(h,"loadcode");
    }找到这么一个代码 头一行 h 就为空
      

  2.   

    void CTestDlg::OnBtnDynamic()    
    {   
        // TODO: Add your control notification handler code here   
        // 动态加载的方法:   
        // 不需要引入头文件与lib文件,仅需要一个dll即可   
        // 注意这里的条约调用约定_stdcall不要忘记加(不然会引会esp出错)   
           
        typedef int (_stdcall *ADDPROC)(int,int);   
        typedef int (_stdcall *SUBPROC)(int,int);   
        HINSTANCE handle;   
        handle = LoadLibrary("MyDll.dll");   
        if(handle)   
        {   
            // GetProcAddress第二个参数有两种方法:   
            // 1、通过DLL中的函数名   
            // 2、通过Depend工具中Ordinal索引值来查看   
            ADDPROC MyAdd = (ADDPROC)GetProcAddress(handle,"Add");   
            SUBPROC MySub = (ADDPROC)GetProcAddress(handle,MAKEINTRESOURCE(2));   
            if( !MyAdd )   
            {   
                MessageBox("函数Add地址获取失败!");   
                return;   
            }   
            if( !MySub )   
            {   
                MessageBox("函数Sub地址获取失败!");   
                return;   
            }   
            CString str;   
            str.Format("动态加载: 1+1=%d 1-1=%d",MyAdd(1,1),MySub(1,1));   
            MessageBox(str);   
        }   
        FreeLibrary(handle);   
    }  
      

  3.   

    你的代码没错,
    如果LoadLibrary()失败,
    就使用GetLastError()看看错误是什么 ……
      

  4.   

    ---------------------------
    Error
    ---------------------------
    Not found the kernel library or the kernel library is invalid or the kernel library of this edition does not support DLL!
    ---------------------------
    确定   
    ---------------------------
    现在函数找到了 但是调用函数的时候 提示这个  为什么呢
      

  5.   

    试试看这个,WIN32版本的,在你的要调用的CPP文件开头定义一个常量段:#pragma const_seg( "CONST_SEGMENT" )
    wchar_t *wchDllFile = L"需要调用的DLL文件名.DLL";
    char *chProcName = "需要调用的函数名";
    #pragma const_seg()然后调用函数:HINSTANCE hDllInstance = ::LoadLibrary( wchDllFile );
    FARPROC hProc = ::GetProcAddress( hDllInstance, chProcName );然后就可以使用你的函数了,比如:hProc( Param1, Param2 );