LoadLibrary GetProcAddress  FreeLibrary

解决方案 »

  1.   

    // A simple program that uses LoadLibrary and 
    // GetProcAddress to access myPuts from Myputs.dll. 
     
    #include <windows.h> 
    #include <stdio.h> 
     
    typedef int (__cdecl *MYPROC)(LPWSTR); 
     
    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, "myPuts"); 
     
            // If the function address is valid, call the function.
     
            if (NULL != ProcAdd) 
            {
                fRunTimeLinkSuccess = TRUE;
                (ProcAdd) (L"Message sent to the DLL function\n"); 
            }
     
            // Free the DLL module.
     
            fFreeResult = FreeLibrary(hinstLib); 
        } 
     
        // If unable to call the DLL function, use an alternative.
     
        if (! fRunTimeLinkSuccess) 
            printf("Message printed from executable\n"); 
    }
    MSDN 
      

  2.   

    你可以用vc2012等,一样支持VC
    不需要.net framework
      

  3.   

    楼上正解,VisualStudio的任何版本中的VC++都不依赖.net framework,除非你明确的新建了一个C++/CLR项目,除非是需要维护VC6.0写的一堆老代码,否则没必要抱着VC6.0不放了。自行定义的方法是先安装高版本的VisualStudio,从里面找到头文件,复制粘贴过去,但这仅限于一些数值型的宏定义,如果是函数没有的话,还是只能用一楼的方法了,结构体也不好处理,直接改头文件可能导致链接器报错,总之很麻烦,对初学者来说更是雪上加霜
      

  4.   

    谢谢,追问一下,使用vb.net 或者 c# 是做界面相关的,有没有可能不需要.net framework?
      

  5.   

    不行,VB.NET和C#必须用.net framework。
    不过2014年微软发布的.NET Native可以将C#程序编译为本机代码而脱离.net运行,不过目前还属于实验性产品,限制非常多,只支持VisualStudio2013,只支持ARM 或 x64 架构,只支持 Windows 商店应用程序开发
    http://developer.51cto.com/art/201404/434924.htm