有一个DLL文件TEST.dll,它里面有一个名称为TEST1()的函数,在我的程序里如何来调用呢?我很菜,请指点一下,谢谢

解决方案 »

  1.   

    1、包含该DLL接口的头文件,设置好DLL库的路径;
    2、调用该DLL的函数。
      

  2.   

    // A simple program that uses LoadLibrary and 
    // GetProcAddress to access myPuts from Myputs.dll. 
     
    #include <stdio.h> 
    #include <windows.h> 
     
    typedef int (*MYPROC)(LPTSTR); 
     
    VOID main(VOID) 

        HINSTANCE hinstLib; 
        MYPROC ProcAdd; 
        BOOL fFreeResult, fRunTimeLinkSuccess = FALSE; 
     
        // Get a handle to the DLL module.
     
        hinstLib = LoadLibrary(TEXT("myputs")); 
     
        // If the handle is valid, try to get the function address.
     
        if (hinstLib != NULL) 
        { 
            ProcAdd = (MYPROC) GetProcAddress(hinstLib, TEXT("myPuts")); 
     
            // If the function address is valid, call the function.
     
            if (NULL != ProcAdd) 
            {
                fRunTimeLinkSuccess = TRUE;
                (ProcAdd) (TEXT("Message via DLL function\n")); 
            }
     
            // Free the DLL module.
     
            fFreeResult = FreeLibrary(hinstLib); 
        } 
     
        // If unable to call the DLL function, use an alternative.
     
        if (! fRunTimeLinkSuccess) 
            printf("Message via alternative method\n"); 
    }
      

  3.   

    若是没有DLL的头文件可不可以调用啊?
      

  4.   

    没有头文件可以,但是需要知道DLL中函数的原型,方法就是mynamelj说的那种
      

  5.   

    HINSTANCE hin=LoadLibrary("Test.dll");
    typedef  int (__stdcall *Fun)();
    Fun fun=(Fun)GetProcAddress(hin,"test");
    int r=fun();
      

  6.   

    问这个问题需要勇气你为什么不先找找以前别人的答案?菜鸟要会学习,csdn的搜索很有用的