error LNK2019 unresolved external symbol __imp__*** 的原因之一

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/gengxt2003/article/details/6393734

今天遇到了一个error LNK2019 unresolved external symbol __imp__**** 问题,在把其他原因都排除掉,仍然是有问题,

最后在属性中把它的Character Set 由 Unicode 改为 Multi-Byte  后,能够正常运行。

 

 

怪不得之前看到 它的 Property--》C/C++ --》Command Line 中 有很多Unicode 字样。

 

 

 

阅读更多

error LNK2019: unresolved external symbol __imp__报错

08-28

我定义了外部的DLL,定义如下rnlib.hrn[code=C/C++]rnextern "C"_declspec(dllexport) bool PrintStrings(HANDLE hOut,...);rnextern "C"_declspec(dllexport) bool PrintMsg(HANDLE hOut,LPCTSTR pMsg);rn[/code]rnlib.cpprn[code=C/C++]#include"Envirmnt.h"rn#includern#includern#includern#includern#include"lib.h"rnrn//write message the output handlern/*rnPrintString:该函数具有不定的参数列表,rnva_list 定义了一个保存可变参数列表的变量,它将指向一个串结构rnva_start 将特定参数之后的参数列表保存到va_list指向的串结构rnva_arg 从串结构中取回一个制定类型的元素返回,并指向串中的下一个元素rnWriteConsole 将字符串写入制定的控制台字符缓冲rn*/rnrnbool PrintStrings(HANDLE hOut,...)rnrn DWORD MsgLen,Count;rn LPCTSTR pMsg;rn va_list pMsgList;//current message stringrn va_start(pMsgList,hOut);//start processing the messagern while((pMsg=va_arg(pMsgList,LPCTSTR))!=NULL)rn rn MsgLen=_tcslen(pMsg);rn if(!WriteConsole(hOut,pMsg,MsgLen,&Count,NULL)&&!WriteFile(hOut,pMsg,MsgLen*sizeof(TCHAR),&Count,NULL))rn rn return false;rn rn rn va_end(pMsgList);rn return true;rnrnrnrnrnbool PrintMsg(HANDLE hOut,LPCTSTR pMsg)rnrn return PrintStrings(hOut,pMsg,NULL);rnrnrnrn/*prompt the user at the console and get a response*/rnbool ConsolePrompt(LPCTSTR pPromptMsg,LPTSTR pResponse,DWORD MaxTchar,bool Echo)rnrn HANDLE hStdIn,hStdOut;rn DWORD TcharIn,EchoFlag;rn bool Success;rn hStdIn=CreateFile(_T("CONIN$"),GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);rn hStdOut=CreateFile(_T("CONOUT$"),GENERIC_WRITE,0,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);rn EchoFlag=Echo?ENABLE_ECHO_INPUT:0;rn Success=SetConsoleMode(hStdIn,ENABLE_LINE_INPUT|EchoFlag|ENABLE_PROCESSED_INPUT)&&SetConsoleMode(hStdOut,ENABLE_WRAP_AT_EOL_OUTPUT|ENABLE_PROCESSED_OUTPUT)&&PrintStrings(hStdOut,pPromptMsg)&&ReadConsole(hStdIn,pResponse,MaxTchar,&TcharIn,NULL);rn if(Success)rn rn pResponse[TcharIn-2]='\0';rn rn CloseHandle(hStdIn);rn CloseHandle(hStdOut);rn return Success;rnrn[/code]rnReportError是要调用该DLL的一个工程,我将DLL和lib都考到了ReportError的路径中,还是报错rn[code=C/C++]rn#pragma comment(lib,"PrintDll.lib")rn#include"EvryThng.h"rnrnVOID ReportError(LPCTSTR UserMessage,DWORD ExitCode,BOOL PrintErrorMsg);rnint _tmain()rnrn ReportError("hello",1,true);rn return 0;rnrnrnVOID ReportError(LPCTSTR UserMessage,DWORD ExitCode,BOOL PrintErrorMsg)rnrn DWORD eMsgLen,LastErr=GetLastError();rn LPTSTR lpvSysMsg;rn HANDLE hStdErr=GetStdHandle(STD_ERROR_HANDLE);rn PrintMsg(hStdErr,UserMessage);rn if(PrintErrorMsg)rn rn eMsgLen=FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM,NULL,LastErr,MAKELANGID(LANG_NEUTRAL,SUBLANG_DEFAULT),(LPTSTR)&lpvSysMsg,0,NULL);rn PrintStrings(hStdErr,_T("\n"),lpvSysMsg,_T("\n"),NULL);rn HeapFree(GetProcessHeap(),0,lpvSysMsg);rn rn if(ExitCode>0)rn rn ExitProcess(ExitCode);rn rn elsern return ;rnrn[/code]rnEvryThng.h的定义: rn[code=C/C++] #include"Envirmnt.h" #include #include #include #include #include"Support.h" #ifdef _MT #include #if !defined(_Wp64) #define DWORD_PTR DWORD #define LONG_PTR LONG #define INT_PTR INT #endif #endifrn[/code]rnrnSupport.h的定义:rnrn[code=C/C++]rnrn #if defined(PRINTDLL_EXPORTS) #define LIBSPEC _declspec(dllexport) #elif defined(__cplusplus) #define LIBSPEC extern "C" _declspec(dllimport) #else #define LIBSPEC _declspec(dllimport) #endif #define EMPTY _T("") #define YES _T("y") #define NO _T("n") #define CR 0x0D #define LF 0x0A #define TSIZE sizeof(TCHAR) /*limits and constants*/ #define TYPE_FILE 1 #define TYPE_DIR 2 #define TYPE_DOT 3 #define MAX_OPTIONS 20 #define MAX_ARG 1000 #define MAX_COMMAND_LINE MAX_PATH+50 /*Commonly used functions*/ LIBSPEC BOOL ConsolePrompt(LPCTSTR,LPTSTR,DWORD,BOOL); LIBSPEC BOOL PrintStrings(HANDLE,...); LIBSPEC BOOL PrintMsg(HANDLE,LPCTSTR); LIBSPEC VOID ReportError(LPCTSTR,DWORD,BOOL); LIBSPEC VOID ReportException(LPCTSTR,DWORD); LIBSPEC DWORD Options(int,LPCTSTR*,LPCTSTR,...); LIBSPEC LPTSTR SkipArg(LPCTSTR); LIBSPEC VOID GetArgs(LPCTSTR,int *,LPTSTR *); LIBSPEC LPCTSTR wmemchr(LPCTSTR,TCHAR,DWORD); #ifdef _UNICODE #define _tstrrchr wcsrchr #else #define _tstrrchr strrchr #endif #ifdef _UNICODE #define _memtchr wmemchr #else #define _memtchr memchr #endif /*security functions*/ LPSECURITY_ATTRIBUTES InitializeUnixSA(DWORD,LPTSTR,LPTSTR,LPDWORD,LPHANDLE); LPSECURITY_ATTRIBUTES InitializeAccessOnlySA(DWORD,LPTSTR,LPTSTR,LPDWORD,LPHANDLE); DWORD ReadFilePermissions(LPTSTR,LPTSTR,LPTSTR); BOOL ChangeFilePermissions(DWORD,LPTSTR,LPDWORD,LPDWORD); #define LUSIZE 1024 #define ACCT_NAME_SIZE LUSIZErnrn[/code]rnrn

没有更多推荐了,返回首页