主题:用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
#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