打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Main.obj : error LNK2001 solved
Main.cpp
 //prjCDDoorControl - Win32 Application
/*====================================================================================================
VC环境中Link时默认引入的:(Project->Setting->Link->Object/Library Module)
 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib
oleaut32.lib uuid.lib odbc32.lib odbccp32.lib
其中:没有 Winmm.lib
而:MSDN中注释中写到:要引入库:Winmm.lib,如下:
 QuickInfo
 Windows NT: Requires version 3.1 or later.
 Windows: Requires Windows 95 or later.
 Windows CE: Unsupported.
 Header: Declared in mmsystem.h.
 Import Library: Use winmm.lib. //要引入库:Winmm.lib
 Unicode: Implemented as Unicode and ANSI versions on Windows NT.
所以:编译时会报错:
 Main.obj : error LNK2001: unresolved external symbol __imp__mciSendStringA@16
 Debug/prjCDDoorControl.exe : fatal error LNK1120: 1 unresolved externals
 Error executing link.exe.
 Creating browse info file...
 prjCDDoorControl.exe - 2 error(s), 0 warning(s)
解决方法:
1、在:Project->Setting->Link->Object/Library Module 中加入:Winmm.lib
2、在程序头部加上:#pragma comment(lib,"Winmm.lib")
-----------------------------------------------------------------------------------------------------
#pragma comment(lib,"Winmm.lib")
原形:
 #pragma comment( comment-type [, commentstring] )
当comment-type 为:lib 时:的意思是:
 Places a library-search record in the object file. This comment type must be accompanied by a
commentstring parameter containing the name (and possibly the path) of the library that you want
the linker to search. Since the library name precedes the default library-search records in the
object file, the linker searches for this library just as if you had named it on the command line.
 You can place multiple library-search records in the same source file; each record appears in
the object file in the same order in which it is encountered in the source file.
-----------------------------------------------------------------------------------------------------
另:
1、.lib : Win32下的静态库
 用VC新建项目时选WIN32 STATIC LIBRARY就可以生成,它是:生成程序是要链接到程序内部的!
2、.dll : Win32下的动态库
 他是程序运行时,所动态加载的!
-----------
1、.h :是类,函数,常量,类型,外部变量声明的地方,使用 #include 包含的原文件中。
2、.dll :是动态连接库,可以包含函数,类,控件的实现代码(已编译)
3、.lib :是静态连接库,或者是动态连接库的引入库,存放函数、类等的实现(静态连接库)或实现的 存根/代理(动态连接库的引入库)。
-----------
1、 .lib:导出函数的列表,他标示了到处函数在动态库中的位置,程序编译时使用。
2、 .h :是导出函数的申明。
3、 .dll:是导出函数所在的位置,运行时使用。
 ====================================================================================================*/
//#pragma comment(lib,"Winmm.lib")
#include <Windows.h>
#include <mmsystem.h>
 
int WINAPI WinMain(
 HINSTANCE hInstance, // handle to current instance
 HINSTANCE hPrevInstance, // handle to previous instance
 LPSTR lpCmdLine, // pointer to command line
 int nCmdShow // show state of window
)
{
 
::mciSendString("Set CDAudio Door Open Wait",NULL,NULL,NULL); //Open
 //::mciSendString("set cdaudio door closed wait",NULL,0,NULL); //Close
 return 0;
}

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/HackerJLY/archive/2008/03/03/2144834.aspx
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
dll的概念、dll导出类(转)
#pragma comment 用法
动态链接库创建与使用
怎样在C++ Builder中创建使用DLL
[原创]VC++调用易编DLL的方法(静态库导入)|易语言俱乐部
c运行库、c标准库、windows API的区别和联系
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服