前面的几篇文章中的代码都是在公司电脑上创建和编写的,今天回到家中在网上下载了自己上传的源码后,
想用自己电脑上的VS2012打开并添加新功能,结果出问题了。
我自己电脑上也安装了Directx SDK,环境变量也添加了:
使用VS2012创建工程,选择的是Visual C++->General->Empty Project,输入工程名后,点击确定,
则创建成功。
然后我把sdk的include目录和Lib目录添加配置好。如下图所示:
配置好directx sdk后,我将上一篇文章中上传的源码,下载并解压后,将里面的文件添加到自己新创建的工程中,
编译时,出现了下列错误,百度了很久,也没查出个所以然来。
1>------ Build started: Project: XAudio3, Configuration: Debug Win32 ------ 1> WaveFile.cpp 1>e:\qt学习\xaudio3\xaudio3\wavefile.cpp(53): error C2664: 'HMMIO mmioOpenA(LPSTR,LPMMIOINFO,DWORD)' : cannot convert argument 1 from 'LPWSTR' to 'LPSTR' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>e:\qt学习\xaudio3\xaudio3\wavefile.cpp(63): error C2664: 'HRSRC FindResourceA(HMODULE,LPCSTR,LPCSTR)' : cannot convert argument 2 from 'LPWSTR' to 'LPCSTR' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>e:\qt学习\xaudio3\xaudio3\wavefile.cpp(65): error C2664: 'HRSRC FindResourceA(HMODULE,LPCSTR,LPCSTR)' : cannot convert argument 2 from 'LPWSTR' to 'LPCSTR' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>e:\qt学习\xaudio3\xaudio3\wavefile.cpp(66): error C2664: 'HRESULT DXTraceA(const char *,DWORD,HRESULT,const char *,BOOL)' : cannot convert argument 4 from 'const wchar_t [13]' to 'const char *' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>e:\qt学习\xaudio3\xaudio3\wavefile.cpp(70): error C2664: 'HRESULT DXTraceA(const char *,DWORD,HRESULT,const char *,BOOL)' : cannot convert argument 4 from 'const wchar_t [13]' to 'const char *' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>e:\qt学习\xaudio3\xaudio3\wavefile.cpp(73): error C2664: 'HRESULT DXTraceA(const char *,DWORD,HRESULT,const char *,BOOL)' : cannot convert argument 4 from 'const wchar_t [15]' to 'const char *' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>e:\qt学习\xaudio3\xaudio3\wavefile.cpp(76): error C2664: 'HRESULT DXTraceA(const char *,DWORD,HRESULT,const char *,BOOL)' : cannot convert argument 4 from 'const wchar_t [13]' to 'const char *' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>e:\qt学习\xaudio3\xaudio3\wavefile.cpp(80): error C2664: 'HRESULT DXTraceA(const char *,DWORD,HRESULT,const char *,BOOL)' : cannot convert argument 4 from 'const wchar_t [4]' to 'const char *' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>e:\qt学习\xaudio3\xaudio3\wavefile.cpp(96): error C2664: 'HRESULT DXTraceA(const char *,DWORD,HRESULT,const char *,BOOL)' : cannot convert argument 4 from 'const wchar_t [9]' to 'const char *' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>e:\qt学习\xaudio3\xaudio3\wavefile.cpp(100): error C2664: 'HRESULT DXTraceA(const char *,DWORD,HRESULT,const char *,BOOL)' : cannot convert argument 4 from 'const wchar_t [10]' to 'const char *' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>e:\qt学习\xaudio3\xaudio3\wavefile.cpp(109): error C2664: 'HMMIO mmioOpenA(LPSTR,LPMMIOINFO,DWORD)' : cannot convert argument 1 from 'LPWSTR' to 'LPSTR' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>e:\qt学习\xaudio3\xaudio3\wavefile.cpp(111): error C2664: 'HRESULT DXTraceA(const char *,DWORD,HRESULT,const char *,BOOL)' : cannot convert argument 4 from 'const wchar_t [9]' to 'const char *' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>e:\qt学习\xaudio3\xaudio3\wavefile.cpp(116): error C2664: 'HRESULT DXTraceA(const char *,DWORD,HRESULT,const char *,BOOL)' : cannot convert argument 4 from 'const wchar_t [10]' to 'const char *' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>e:\qt学习\xaudio3\xaudio3\wavefile.cpp(120): error C2664: 'HRESULT DXTraceA(const char *,DWORD,HRESULT,const char *,BOOL)' : cannot convert argument 4 from 'const wchar_t [10]' to 'const char *' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>e:\qt学习\xaudio3\xaudio3\wavefile.cpp(163): error C2664: 'HRESULT DXTraceA(const char *,DWORD,HRESULT,const char *,BOOL)' : cannot convert argument 4 from 'const wchar_t [12]' to 'const char *' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>e:\qt学习\xaudio3\xaudio3\wavefile.cpp(168): error C2664: 'HRESULT DXTraceA(const char *,DWORD,HRESULT,const char *,BOOL)' : cannot convert argument 4 from 'const wchar_t [11]' to 'const char *' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>e:\qt学习\xaudio3\xaudio3\wavefile.cpp(173): error C2664: 'HRESULT DXTraceA(const char *,DWORD,HRESULT,const char *,BOOL)' : cannot convert argument 4 from 'const wchar_t [12]' to 'const char *' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>e:\qt学习\xaudio3\xaudio3\wavefile.cpp(178): error C2664: 'HRESULT DXTraceA(const char *,DWORD,HRESULT,const char *,BOOL)' : cannot convert argument 4 from 'const wchar_t [22]' to 'const char *' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>e:\qt学习\xaudio3\xaudio3\wavefile.cpp(183): error C2664: 'HRESULT DXTraceA(const char *,DWORD,HRESULT,const char *,BOOL)' : cannot convert argument 4 from 'const wchar_t [9]' to 'const char *' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>e:\qt学习\xaudio3\xaudio3\wavefile.cpp(191): error C2664: 'HRESULT DXTraceA(const char *,DWORD,HRESULT,const char *,BOOL)' : cannot convert argument 4 from 'const wchar_t [7]' to 'const char *' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>e:\qt学习\xaudio3\xaudio3\wavefile.cpp(202): error C2664: 'HRESULT DXTraceA(const char *,DWORD,HRESULT,const char *,BOOL)' : cannot convert argument 4 from 'const wchar_t [9]' to 'const char *' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>e:\qt学习\xaudio3\xaudio3\wavefile.cpp(206): error C2664: 'HRESULT DXTraceA(const char *,DWORD,HRESULT,const char *,BOOL)' : cannot convert argument 4 from 'const wchar_t [4]' to 'const char *' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>e:\qt学习\xaudio3\xaudio3\wavefile.cpp(217): error C2664: 'HRESULT DXTraceA(const char *,DWORD,HRESULT,const char *,BOOL)' : cannot convert argument 4 from 'const wchar_t [9]' to 'const char *' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>e:\qt学习\xaudio3\xaudio3\wavefile.cpp(225): error C2664: 'HRESULT DXTraceA(const char *,DWORD,HRESULT,const char *,BOOL)' : cannot convert argument 4 from 'const wchar_t [11]' to 'const char *' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>e:\qt学习\xaudio3\xaudio3\wavefile.cpp(263): error C2664: 'HRESULT DXTraceA(const char *,DWORD,HRESULT,const char *,BOOL)' : cannot convert argument 4 from 'const wchar_t [9]' to 'const char *' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>e:\qt学习\xaudio3\xaudio3\wavefile.cpp(268): error C2664: 'HRESULT DXTraceA(const char *,DWORD,HRESULT,const char *,BOOL)' : cannot convert argument 4 from 'const wchar_t [12]' to 'const char *' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>e:\qt学习\xaudio3\xaudio3\wavefile.cpp(277): error C2664: 'HRESULT DXTraceA(const char *,DWORD,HRESULT,const char *,BOOL)' : cannot convert argument 4 from 'const wchar_t [16]' to 'const char *' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>e:\qt学习\xaudio3\xaudio3\wavefile.cpp(280): error C2664: 'HRESULT DXTraceA(const char *,DWORD,HRESULT,const char *,BOOL)' : cannot convert argument 4 from 'const wchar_t [12]' to 'const char *' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>e:\qt学习\xaudio3\xaudio3\wavefile.cpp(334): error C2664: 'HRESULT DXTraceA(const char *,DWORD,HRESULT,const char *,BOOL)' : cannot convert argument 4 from 'const wchar_t [12]' to 'const char *' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>e:\qt学习\xaudio3\xaudio3\wavefile.cpp(348): error C2664: 'HRESULT DXTraceA(const char *,DWORD,HRESULT,const char *,BOOL)' : cannot convert argument 4 from 'const wchar_t [12]' to 'const char *' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>e:\qt学习\xaudio3\xaudio3\wavefile.cpp(351): error C2664: 'HRESULT DXTraceA(const char *,DWORD,HRESULT,const char *,BOOL)' : cannot convert argument 4 from 'const wchar_t [19]' to 'const char *' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>e:\qt学习\xaudio3\xaudio3\wavefile.cpp(360): error C2664: 'HRESULT DXTraceA(const char *,DWORD,HRESULT,const char *,BOOL)' : cannot convert argument 4 from 'const wchar_t [12]' to 'const char *' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>e:\qt学习\xaudio3\xaudio3\wavefile.cpp(392): error C2664: 'HRESULT DXTraceA(const char *,DWORD,HRESULT,const char *,BOOL)' : cannot convert argument 4 from 'const wchar_t [12]' to 'const char *' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>e:\qt学习\xaudio3\xaudio3\wavefile.cpp(397): error C2664: 'HRESULT DXTraceA(const char *,DWORD,HRESULT,const char *,BOOL)' : cannot convert argument 4 from 'const wchar_t [11]' to 'const char *' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>e:\qt学习\xaudio3\xaudio3\wavefile.cpp(401): error C2664: 'HRESULT DXTraceA(const char *,DWORD,HRESULT,const char *,BOOL)' : cannot convert argument 4 from 'const wchar_t [11]' to 'const char *' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>e:\qt学习\xaudio3\xaudio3\wavefile.cpp(406): error C2664: 'HRESULT DXTraceA(const char *,DWORD,HRESULT,const char *,BOOL)' : cannot convert argument 4 from 'const wchar_t [12]' to 'const char *' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>e:\qt学习\xaudio3\xaudio3\wavefile.cpp(420): error C2664: 'HRESULT DXTraceA(const char *,DWORD,HRESULT,const char *,BOOL)' : cannot convert argument 4 from 'const wchar_t [11]' to 'const char *' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>e:\qt学习\xaudio3\xaudio3\wavefile.cpp(451): error C2664: 'HRESULT DXTraceA(const char *,DWORD,HRESULT,const char *,BOOL)' : cannot convert argument 4 from 'const wchar_t [16]' to 'const char *' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>e:\qt学习\xaudio3\xaudio3\wavefile.cpp(461): error C2664: 'HRESULT DXTraceA(const char *,DWORD,HRESULT,const char *,BOOL)' : cannot convert argument 4 from 'const wchar_t [16]' to 'const char *' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>e:\qt学习\xaudio3\xaudio3\wavefile.cpp(468): error C2664: 'HRESULT DXTraceA(const char *,DWORD,HRESULT,const char *,BOOL)' : cannot convert argument 4 from 'const wchar_t [10]' to 'const char *' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>e:\qt学习\xaudio3\xaudio3\wavefile.cpp(476): error C2664: 'HRESULT DXTraceA(const char *,DWORD,HRESULT,const char *,BOOL)' : cannot convert argument 4 from 'const wchar_t [10]' to 'const char *' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>e:\qt学习\xaudio3\xaudio3\wavefile.cpp(481): error C2664: 'HRESULT DXTraceA(const char *,DWORD,HRESULT,const char *,BOOL)' : cannot convert argument 4 from 'const wchar_t [11]' to 'const char *' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>e:\qt学习\xaudio3\xaudio3\wavefile.cpp(489): error C2664: 'HRESULT DXTraceA(const char *,DWORD,HRESULT,const char *,BOOL)' : cannot convert argument 4 from 'const wchar_t [16]' to 'const char *' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>e:\qt学习\xaudio3\xaudio3\wavefile.cpp(493): error C2664: 'HRESULT DXTraceA(const char *,DWORD,HRESULT,const char *,BOOL)' : cannot convert argument 4 from 'const wchar_t [10]' to 'const char *' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>e:\qt学习\xaudio3\xaudio3\wavefile.cpp(497): error C2664: 'HRESULT DXTraceA(const char *,DWORD,HRESULT,const char *,BOOL)' : cannot convert argument 4 from 'const wchar_t [11]' to 'const char *' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 1>e:\qt学习\xaudio3\xaudio3\wavefile.cpp(526): error C2664: 'HRESULT DXTraceA(const char *,DWORD,HRESULT,const char *,BOOL)' : cannot convert argument 4 from 'const wchar_t [12]' to 'const char *' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
后来想了一会,发现我原来在公司时创建工程貌似都是选择的,win32 console project,然后选择建立空工程,
然后我就又新建了一个工程,将文件拷贝到新工程目录下,然后在VS添加到工程中,配置好sdk,编译,通过了。
第二次新建(win32->Empty project)是Use Unicode Character Set,
第一次新建(general->empty project)是:Use Multi-Byte Character Set。
出现错误是因为编码方式不一样,从而导致类型有差别:LPSTR是ASCII编码,LPWSTR是Unicode编码。知道这个就好办了。
问题解决。
备注:请尊重版权,转载请联系作者QQ:1245178753。
交流请加:
群名称:XAudio2 交流群
群 号:233537460