vc++6.0如何调用.h和.lib里的函数啊
4个回答
展开全部
你下的.h和.lib没有例程的吗?
我这里有个例子,你看看吧
hinstCadIO =LoadLibrary( "CadIO.dll" );
bool result;
result = true;
result &= ((dxfWriteParamString = (BOOL(*)(HDXF, int, LPCTSTR))
GetProcAddress( hinstCadIO, "dxfWriteParamString" )) != NULL);
result &= ((dxfWriteParamInteger = (BOOL(*)(HDXF, int, int))
GetProcAddress( hinstCadIO, "dxfWriteParamInteger" )) != NULL);
result &= ((dxfWriteParamDouble = (BOOL(*)(HDXF, int, double))
GetProcAddress( hinstCadIO, "dxfWriteParamDouble" )) != NULL);
result &= ((dxfCreateFile = (HDXF(*)(LPCTSTR))
GetProcAddress( hinstCadIO, "dxfCreateFile" )) != NULL);
result &= ((dxfCloseFile = (BOOL(*)(HDXF))
GetProcAddress( hinstCadIO, "dxfCloseFile" )) != NULL);
result &= ((dxfSetCurrentColor = (BOOL(*)(HDXF, int))
GetProcAddress( hinstCadIO, "dxfSetCurrentColor" )) != NULL);
result &= ((dxfSectionBegin = (BOOL(*)(HDXF hDxf, DWORD dwSection))
GetProcAddress( hinstCadIO, "dxfSectionBegin" )) != NULL);
result &= ((dxfSectionEnd = (BOOL(_cdecl*)(HDXF hDxf))
GetProcAddress( hinstCadIO, "dxfSectionEnd" )) != NULL);
result &= ((dxfTableTypeBegin = (BOOL(_cdecl*)(HDXF hDxf, DWORD dwTableType))
GetProcAddress( hinstCadIO, "dxfTableTypeBegin" )) != NULL);
result &= ((dxfTableTypeEnd = (BOOL(_cdecl*)(HDXF hDxf))
GetProcAddress( hinstCadIO, "dxfTableTypeEnd" )) != NULL);
result &= ((dxfAddLayer = (BOOL(_cdecl*)( HDXF hDxf, char* Name, int Color, char* Linetype ))
GetProcAddress( hinstCadIO, "dxfAddLayer" )) != NULL);
result &= ((dxfSetCurrentLayer = (BOOL(_cdecl*)(HDXF hDxf, char* Name, char* LineType))
GetProcAddress( hinstCadIO, "dxfSetCurrentLayer" )) != NULL);
result &= ((dxfAddLinetype = (BOOL(_cdecl*)(HDXF hDxf, PDXFLTYPE pLineType))
GetProcAddress( hinstCadIO, "dxfAddLinetype" )) != NULL);
result &= ((dxfSetCurrentLinetype = (BOOL(_cdecl*)(HDXF hDxf, char* Name))
GetProcAddress( hinstCadIO, "dxfSetCurrentLinetype" )) != NULL);
result &= ((dxfAddTextStyle = (BOOL(_cdecl*)(HDXF hDxf, PDXFSTYLE pTextStyle))
GetProcAddress( hinstCadIO, "dxfAddTextStyle" )) != NULL);
result &= ((dxfSetCurrentTextStyle = (BOOL(_cdecl*)(HDXF hDxf, char* Name))
GetProcAddress( hinstCadIO, "dxfSetCurrentTextStyle" )) != NULL);
result &= ((dxfAddDimStyle = (BOOL(_cdecl*)(HDXF, PDXFDIMSTYLE))
GetProcAddress( hinstCadIO, "dxfAddDimStyle" )) != NULL);
result &= ((dxfSetCurrentDimStyle = (BOOL(_cdecl*)(HDXF, LPCTSTR))
GetProcAddress( hinstCadIO, "dxfSetCurrentDimStyle" )) != NULL);
result &= ((dxfLine = (BOOL(_cdecl*)(HDXF hDxf, double x1, double y1, double x2, double y2))
GetProcAddress( hinstCadIO, "dxfLine" )) != NULL);
result &= ((dxfCircle = (BOOL(_cdecl*)(HDXF hDxf, double cx, double cy, double r))
GetProcAddress( hinstCadIO, "dxfCircle" )) != NULL);
result &= ((dxfSolid = (BOOL(_cdecl*)(HDXF hDxf, REALPOINT& Point0, REALPOINT& Point1, REALPOINT& Point2, REALPOINT& Point3))
GetProcAddress( hinstCadIO, "dxfSolid" )) != NULL);
result &= ((dxfText = (BOOL(_cdecl*)( HDXF hDxf, LPCTSTR Text, double x1, double y1, double x2, double y2, double Height, double Rotation, DWORD Justification, double WidthFactor, LPCTSTR StyleName ))
GetProcAddress( hinstCadIO, "dxfText" )) != NULL);
result &= ((dxfDimLinear = (BOOL(_cdecl*)( HDXF, double, double, double, double, double, double, double, LPCTSTR))
GetProcAddress( hinstCadIO, "dxfDimLinear" )) != NULL);
result &= ((dxfArc = (BOOL(_cdecl*)( HDXF, double, double, double, double, double, double ))
GetProcAddress( hinstCadIO, "dxfArc" )) != NULL);
result &= ((dxfInsertBlock = (BOOL(_cdecl*)( HDXF hDxf, LPCTSTR BlockName, double x, double y, double xScale, double yScale, double Rotation ))
GetProcAddress( hinstCadIO, "dxfInsertBlock" )) != NULL);
result &= ((dxfBlockBegin = (BOOL(_cdecl*)( HDXF hDxf, LPCTSTR BlockName, LPCTSTR LayerName, double bx, double by, char flags ))
GetProcAddress( hinstCadIO, "dxfBlockBegin" )) != NULL);
result &= ((dxfBlockEnd = (BOOL(_cdecl*)( HDXF hDxf ))
GetProcAddress( hinstCadIO, "dxfBlockEnd" )) != NULL);
if(!result)
{
// Cannot load all functions from library
return;
}
说明:先loadlibrary把库加进去,然后再把你要用的函数一个个添加进来
其中hinstCadIO是一个HINSTANCE,
(BOOL(_cdecl*)( HDXF hDxf ))是一个强制类型转换成指定类型函数指针
我不知道要解释到什么程度,你要是看得懂最好,看不懂再追问
展开全部
没有楼上说的那么麻烦,把h文件放入include目录,lib文件放入lib目录,就是在你的编译器目录下或者加bin/目录下可以找到这两个目录
然后在你的工程里,写#include <!h文件名.h>,就可以向库函数一样用了,编译器在编译时会自动链接lib文件
或者用#pragma comment(lib ,"!lib文件名.lib")来进行强制连接
因为lib文件是静态库,所以只需要正确引用,编译器就会自动将之连编到exe文件中(前提是编译器能找到该文件)
然后在你的工程里,写#include <!h文件名.h>,就可以向库函数一样用了,编译器在编译时会自动链接lib文件
或者用#pragma comment(lib ,"!lib文件名.lib")来进行强制连接
因为lib文件是静态库,所以只需要正确引用,编译器就会自动将之连编到exe文件中(前提是编译器能找到该文件)
追问
也不行 试来试去都弄不对 报错:No such file or directory
追答
你发给我试试,如果我能用说明是你的vc不完整,qq邮箱,id一样,或者分享到百度云盘也行
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
只提供了.h和.lib?说明是静态链接库
只需要导入头文件,然后导入lib库就行了
#include "abcd.h"
#pragma comment(lib, "abcd.lib")
接下来就可以使用了
当然,也可以直接设置编译器选项,将.lib添加到外部链接里面
只需要导入头文件,然后导入lib库就行了
#include "abcd.h"
#pragma comment(lib, "abcd.lib")
接下来就可以使用了
当然,也可以直接设置编译器选项,将.lib添加到外部链接里面
追问
不行啊 一大堆错误 vc6.0这个真心不会弄啊
追答
链接库的使用方法就是这样的,把错误发出来看看
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include "temp.h"
#include "temp.lib"
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询