回 帖 发 新 帖 刷新版面

主题:用VC加载DLL出错?

我写的一段测试DLL的程序如下:
#include <windows.h>
#include "stdafx.h"
#include <stdio.h>
typedef  void (*MYPROC)();
int main()
{
    HINSTANCE hInst;
    MYPROC  myproc;
    hInst = LoadLibrary("cfree");
    if( hInst != NULL)
    {
        myproc = ( MYPROC )GetProcAddress( hInst,"CallFromDll" );
        myproc();
        FreeLibrary(hInst); 
    }
    return 0;
}
这段程序在cfree编译器上运行是没问题的.在VC上运行却有下面一堆的错误,Why?

D:\win32_ exercise\text_dll\text_dll.cpp(9) : error C2065: 'HINSTANCE' : undeclared identifier
D:\win32_ exercise\text_dll\text_dll.cpp(9) : error C2146: syntax error : missing ';' before identifier 'hInst'
D:\win32_ exercise\text_dll\text_dll.cpp(9) : error C2065: 'hInst' : undeclared identifier
D:\win32_ exercise\text_dll\text_dll.cpp(11) : error C2065: 'LoadLibrary' : undeclared identifier
D:\win32_ exercise\text_dll\text_dll.cpp(14) : error C2065: 'GetProcAddress' : undeclared identifier
D:\win32_ exercise\text_dll\text_dll.cpp(16) : error C2065: 'FreeLibrary' : undeclared identifier


回复列表 (共1个回复)

沙发

stdafx.h应该是第一个被#include的文件.

我来回复

您尚未登录,请登录后再回复。点此登录或注册