用vs2015打开前几天用vs2015写好的程序,该程序么有用Windows 7 SDK V7.1中的api,并且在平台工具集里也是选的v140
1>c:\program files\microsoft sdks\windows\v7.1\include\sal_supp.h(57): error C2220: 警告被视为错误 - 没有生成“object”文件。
用vs2010打开sdk中的例子,x86
1>Link:
1>正在创建库 D:\VS2010project\RenderExclusiveEventDriven\Debug\WASAPIRenderExclusiveEventDriven.lib 和对象 D:\VS2010project\RenderExclusiveEventDriven\Debug\WASAPIRenderExclusiveEventDriven.exp
1>WASAPIRenderer.obj : error LNK2019: 无法解析的外部符号 __imp__CoTaskMemFree@4,该符号在函数 "public: void __thiscall CWASAPIRenderer::Shutdown(void)" (?Shutdown@CWASAPIRenderer@@QAEXXZ) 中被引用
1>WASAPIRenderExclusiveEventDriven.obj : error LNK2001: 无法解析的外部符号 __imp__CoTaskMemFree@4
1>WASAPIRenderer.obj : error LNK2019: 无法解析的外部符号 __imp__CoUninitialize@0,该符号在函数 "private: unsigned long __thiscall CWASAPIRenderer::DoRenderThread(void)" (?DoRenderThread@CWASAPIRenderer@@AAEKXZ) 中被引用
1>WASAPIRenderExclusiveEventDriven.obj : error LNK2001: 无法解析的外部符号 __imp__CoUninitialize@0
1>WASAPIRenderer.obj : error LNK2019: 无法解析的外部符号 __imp__CoInitializeEx@8,该符号在函数 "private: unsigned long __thiscall CWASAPIRenderer::DoRenderThread(void)" (?DoRenderThread@CWASAPIRenderer@@AAEKXZ) 中被引用
1>WASAPIRenderExclusiveEventDriven.obj : error LNK2001: 无法解析的外部符号 __imp__CoInitializeEx@8
1>WASAPIRenderExclusiveEventDriven.obj : error LNK2019: 无法解析的外部符号 __imp__PropVariantClear@4,该符号在函数 "wchar_t * __cdecl GetDeviceName(struct IMMDeviceCollection *,unsigned int)" (?GetDeviceName@@YAPA_WPAUIMMDeviceCollection@@I@Z) 中被引用
1>WASAPIRenderExclusiveEventDriven.obj : error LNK2019: 无法解析的外部符号 __imp__CoCreateInstance@20,该符号在函数 "bool __cdecl PickDevice(struct IMMDevice * *,bool *,enum __MIDL___MIDL_itf_mmdeviceapi_0000_0000_0002 *)" (?PickDevice@@YA_NPAPAUIMMDevice@@PA_NPAW4__MIDL___MIDL_itf_mmdeviceapi_0000_0000_0002@@@Z) 中被引用
1>D:\VS2010project\RenderExclusiveEventDriven\Debug\WASAPIRenderExclusiveEventDriven.exe : fatal error LNK1120: 5 个无法解析的外部命令
平台改为x64
fatal error LNK1120: 100 个无法解析的外部命令
每次我都确认了VC++包含目录,库目录,确实正确的设置了sdk的对应目录。
补充一下另一种方法。
1,在头文件中添加shellapi.h,或者直接添加如下代码:
#ifndef _INC_SHELLAPI#define _INC_SHELLAPI
//
// Define API decoration for direct importing of DLL references.
//
#ifndef WINSHELLAPI
#if !defined(_SHELL32_)
#define WINSHELLAPI DECLSPEC_IMPORT
#else
#define WINSHELLAPI
#endif
#endif // WINSHELLAPI
#ifndef SHSTDAPI
#if !defined(_SHELL32_)
#define SHSTDAPI EXTERN_C DECLSPEC_IMPORT HRESULT STDAPICALLTYPE
#define SHSTDAPI_(type) EXTERN_C DECLSPEC_IMPORT type STDAPICALLTYPE
#else
#define SHSTDAPI STDAPI
#define SHSTDAPI_(type) STDAPI_(type)
#endif
#endif // SHSTDAPI
#ifndef SHDOCAPI
#if !defined(_SHDOCVW_)
#define SHDOCAPI EXTERN_C DECLSPEC_IMPORT HRESULT STDAPICALLTYPE
#define SHDOCAPI_(type) EXTERN_C DECLSPEC_IMPORT type STDAPICALLTYPE
#else
#define SHDOCAPI STDAPI
#define SHDOCAPI_(type) STDAPI_(type)
#endif
#endif // SHDOCAPI
#if ! (defined(lint) || defined(_lint) || defined(RC_INVOKED))
#if ( _MSC_VER >= 800 ) || defined(_PUSHPOP_SUPPORTED)
#pragma warning(disable:4103)
#if !(defined( MIDL_PASS )) || defined( __midl )
#pragma pack(push)
#endif
#pragma pack(1)
#else
#pragma pack(1)
#endif
#endif // ! (defined(lint) || defined(_lint) || defined(RC_INVOKED))
#ifdef __cplusplus
extern "C" { /* Assume C declarations for C++ */
#endif /* __cplusplus */
DECLARE_HANDLE(HDROP)
WINSHELLAPI UINT APIENTRY DragQueryFileA(HDROP,UINT,LPSTR,UINT)
WINSHELLAPI UINT APIENTRY DragQueryFileW(HDROP,UINT,LPWSTR,UINT)
#ifdef UNICODE
#define DragQueryFile DragQueryFileW
#else
#define DragQueryFile DragQueryFileA
#endif // !UNICODE
WINSHELLAPI BOOL APIENTRY DragQueryPoint(HDROP,LPPOINT)
WINSHELLAPI VOID APIENTRY DragFinish(HDROP)
WINSHELLAPI VOID APIENTRY DragAcceptFiles(HWND,BOOL)
#ifdef __cplusplus
}
#endif /* __cplusplus */
#if ! (defined(lint) || defined(_lint) || defined(RC_INVOKED))
#if ( _MSC_VER >= 800 ) || defined(_PUSHPOP_SUPPORTED)
#pragma warning(disable:4103)
#if !(defined( MIDL_PASS )) || defined( __midl )
#pragma pack(pop)
#else
#pragma pack()
#endif
#else
#pragma pack()
#endif
#endif // ! (defined(lint) || defined(_lint) || defined(RC_INVOKED))
#endif /* _INC_SHELLAPI */
2,对话框属性中勾选 接收文件(Accept files)
3,添加消息处理:
case WM_DROPFILES:HDROP hDropInfo = (HDROP) wParam //从WM_DROPFILES消息中获取所拖放文件的数据结构的指针
DragQueryFile(hDropInfo,0,szFilePath,_MAX_PATH) //获取文件路径
DragFinish(hDropInfo) //拖放结束后,释放内存
SendDlgItemMessage(hWnd,IDC_FILEPATH_EDIT,WM_SETTEXT,MAX_PATH,(LPARAM)szFilePath)
下面是完整代码:
#include <windows.h>#include <shellapi.h>
#include <commdlg.h>
#include "resource.h"
LRESULT CALLBACK MainDlgProc(HWND, UINT, WPARAM, LPARAM)
BOOL OpenFileDlg(HWND)
char szFilePath[MAX_PATH]
HINSTANCE hInst
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
hInst = hInstance
DialogBox(hInstance, (LPCTSTR)IDD_MAIN_DLG, NULL, (DLGPROC)MainDlgProc)
return 0
}
LRESULT CALLBACK MainDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent
switch (message)
{
case WM_COMMAND:
wmId = LOWORD(wParam)
wmEvent = HIWORD(wParam)
switch (wmId)
{
case IDC_OPEN_BTN:
if(!OpenFileDlg(hWnd))
return FALSE
SendDlgItemMessage(hWnd,IDC_FILEPATH_EDIT,WM_SETTEXT,MAX_PATH,(LPARAM)szFilePath)
return TRUE
}
break
case WM_CLOSE:
EndDialog(hWnd, 0)
break
case WM_DROPFILES:
HDROP hDropInfo = (HDROP) wParam //从WM_DROPFILES消息中获取所拖放文件的数据结构的指针
DragQueryFile(hDropInfo,0,szFilePath,MAX_PATH) //获取文件路径
DragFinish(hDropInfo) //拖放结束后,释放内存
SendDlgItemMessage(hWnd,IDC_FILEPATH_EDIT,WM_SETTEXT,MAX_PATH,(LPARAM)szFilePath)
return TRUE
break
}
return 0
}
BOOL OpenFileDlg(HWND hwnd)
{
OPENFILENAME ofn
memset(szFilePath,0,MAX_PATH)
memset(&ofn, 0, sizeof(ofn))
ofn.lStructSize =sizeof(ofn)
ofn.hwndOwner =hwnd
ofn.hInstance =GetModuleHandle(NULL)
ofn.nMaxFile =MAX_PATH
ofn.lpstrInitialDir ="."
ofn.lpstrFile =szFilePath
ofn.lpstrTitle ="Open..."
ofn.Flags =OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY
ofn.lpstrFilter ="*.*\0*.*\0"
if(!GetOpenFileName(&ofn))
{
ZeroMemory(&ofn,sizeof(OPENFILENAME)) //释放内存
return FALSE
}
ZeroMemory(&ofn,sizeof(OPENFILENAME)) //释放内存
return TRUE
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)