char c-style 的转换。。

时间:2021-08-25 22:25:26
错误如下:

WIN32_FIND_DATA fd;
(strstr(lpszFileName, ".dat") 

LPCTSTR lpszFileName;
if(strcmp(fd.cFileName, ".") )



error C2664: 'strcmp' : cannot convert parameter 1 from 'unsigned short [260]' to 'const char *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

error C2664: 'strstr' : cannot convert parameter 1 from 'const unsigned short *' to 'const char *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast


怎样修改?谢谢!!

20 个解决方案

#1


强制转换一下不就行了

#2


强制转换

#3


具体怎样??

#4


试试看这样:
    char string;
    wsprintf(string,lpszFileName);
    strstr(string,".dat")

#5


不行:
'wsprintfW' : cannot convert parameter 1 from 'char ' to 'unsigned short *'

if char* string
'wsprintfW' : cannot convert parameter 1 from 'char *' to 'unsigned short *'


#6


>>WIN32_FIND_DATA fd;
>>(strstr(lpszFileName, ".dat") 
请一定改写为:_tcsstr(lpszFileName, _T(".dat"))

>>LPCTSTR lpszFileName;
你怎么把lpszFileName放下面了,我晕!!


>>if(strcmp(fd.cFileName, ".") )
请改写为:
if(_tcscmp(fd.cFileName,_T(".") )

=====================================
问题所在:你用了UNICODE编译程序,却仍用ANSI的函数。
建议不管是UNICODE还是ANSI,都用上_T函数
如:_tcsstr, _tcscmp (和ANSI一样,只是前面的str改成了_tcs)
这样,编译器就可以根据宏定义决定用strxxx还是wcsstr了。
而常量字串请用_T("")括起,也是同样的原因。
:)

#7


can't not found mfc42u.lib
=== 
找到mfc427.lib之后,连上,
但是:

Linking...
H:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\VC_TEMPLATE\mfc42u.lib : 
fatal error LNK1112: module machine type "IA64" conflicts with target machine type "IX86"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
Error executing link.exe.


请问 Muf(沐枫) 怎样解决?
http://www.csdn.net/expert/topic/654/654121.xml?temp=.2101862

#8


既然提示你cannot convert parameter 1 from 'unsigned short [260]' to 'const char *'
你就在第一个变量前加上(const char*)强制转换一下不就可以了?

#9


不管这个程序逻辑如何,我在Win32控制台下用UNICODE方式编译该段代码没有问题.

//请记住在stdafx.h的一开始:
//#define UNICODE
//#define _UNICODE

#include "stdafx.h"
#include "windows.h"
#include "tchar.h"

int main(int argc, char* argv[])
{
   WIN32_FIND_DATA fd;
   LPCTSTR lpszFileName=NULL;

   _tcsstr(lpszFileName,_TEXT(".dat"));
   
   if(_tcscmp(fd.cFileName, _TEXT(".")))
   {
      //....
   }

   return 0;
}

#10


To: wwtmw(剑重无锋 大巧不工)
你一定是在Windows98系统下编译你的程序,并且选择了UNICODE吧。
你可以在WindowsNT/2000/XP下编译,
或者在Win98下不要用UNICODE,改用MBCS。因为Win98不支持UNICODE,因此安装VC时,也没有装对应的库。

==================================
不过我没在Win98下编译过UNICODE程序,我总在NT/2000下编译UNICODE程序,
所以也不知道如何在Win98下增加VC对UNICODE的支持。
你可以考虑用NT/2000
或者重新运行VC安装程序,并且增加UNICODE库,也许可以也不一定。
:)

#11


2:Muf(沐枫) :

其实我也是的2000下面做的,

是这样的:
我按照你的方法,
==
问题所在:你用了UNICODE编译程序,却仍用ANSI的函数。
建议不管是UNICODE还是ANSI,都用上_T函数
如:_tcsstr, _tcscmp (和ANSI一样,只是前面的str改成了_tcs)
这样,编译器就可以根据宏定义决定用strxxx还是wcsstr了。
而常量字串请用_T("")括起,也是同样的原因。
==done

then compile, display the errer massage:
can't not found mfc42u.lib
说我没有mfc427.lib, 我就搜索到mfc427.lib之后,在option选项上连上,
=== done

then compile again:
但是:

Linking...
H:\...\mfc42u.lib : 
fatal error LNK1112: module machine type "IA64" conflicts with target machine type "IX86"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
Error executing link.exe.

so....

help, thanks!


#12


to opentuxedo(开缝的燕尾服): 不行噢

#13


???你还用 64 Bit的处理器(Intel® IA64 series processors)???
>>Visual C++ 概念:生成 C/C++ 程序   
>>链接器工具错误 LNK1112模块计算机类型“IA64”与目标计算机类型“IX86”冲突
>>指定为输入的对象文件是为其他计算机类型编译的。

====================================================
也就是说,你用的mfc42u.lib是为IA64处理器而编译的。请换一个吧。

#14


On Windows NT platforms, MFC supports the Unicode standard for encoding wide characters. Unicode is not presently supported on Windows 95.

Note   The Unicode versions of the MFC libraries are not copied to your hard drive unless you select them during a Custom installation. They are not copied during other types of installation. If you attempt to build or run an MFC Unicode application without the MFC Unicode files, you may get errors.

To copy the files to your hard drive, rerun Setup, choose Custom installation, clear all other components except "Microsoft Foundation Class Libraries," click the Details button, and select both "Static Library for Unicode" and "Shared Library for Unicode."

===============================================================
大概意思:
MFC库的Unicode版本没有安装到你的硬盘上。因此当你编译Unicode程序时,将会出错。
要安装这些库文件,你可以重新运行安装程序,并选择“定制安装”, 去掉所有选项除了“Microsoft Foundation Class Libraries” (因为其它组件你已经安装了),然后点“Details”按钮,同时选中“Static Library for Unicode”和“Shared Library for Unicode”。

#15


谢谢 沐枫,

还没有试,不过我相信就这样做就可以的。我加了30分了,谢谢。


请问我怎样才能的MSDN得到 那段  “On Windows NT platforms。。。”?

我input: fatal error LNK1112,只有:
Visual C++ Concepts: Building a C/C++ Program   

Linker Tools Error LNK1112
module machine type 'type1' conflicts with target machine type 'type2'

The object files specified as input were compiled for different machine types.


应该的哪里呢? Thanks again.

#16


上次还看你只有4个3角,又升级了。

#17


:) 那一段话在MSDN 2000.07版是没有的。我是在VS.net上找出来的。
你也可以到msdn.microsoft.com上找。

#18


错了,我又找到了,是在MSDN Library 2000年7月版上面的。位置如下:

MSDN Library - July 2000
+ Visual Studio 6.0 Documentation
  + Visual C++ Documentation
    + Using Visual C++
      + Visual C++ Programmer's Guide
        + Adding Program Functionality
          + Details
            + Unicode Topics

因为是Unicode和MFC的问题,所有我去查找Unicode及MFC都相关的内容。结果找到了。

#19


我记得上次这问题好像已经给了分了。。没有结帐吗?再给一次,


谢谢关注!

#20


(?还没有给分吗?),(现在再给吧)


谢谢关注。

#1


强制转换一下不就行了

#2


强制转换

#3


具体怎样??

#4


试试看这样:
    char string;
    wsprintf(string,lpszFileName);
    strstr(string,".dat")

#5


不行:
'wsprintfW' : cannot convert parameter 1 from 'char ' to 'unsigned short *'

if char* string
'wsprintfW' : cannot convert parameter 1 from 'char *' to 'unsigned short *'


#6


>>WIN32_FIND_DATA fd;
>>(strstr(lpszFileName, ".dat") 
请一定改写为:_tcsstr(lpszFileName, _T(".dat"))

>>LPCTSTR lpszFileName;
你怎么把lpszFileName放下面了,我晕!!


>>if(strcmp(fd.cFileName, ".") )
请改写为:
if(_tcscmp(fd.cFileName,_T(".") )

=====================================
问题所在:你用了UNICODE编译程序,却仍用ANSI的函数。
建议不管是UNICODE还是ANSI,都用上_T函数
如:_tcsstr, _tcscmp (和ANSI一样,只是前面的str改成了_tcs)
这样,编译器就可以根据宏定义决定用strxxx还是wcsstr了。
而常量字串请用_T("")括起,也是同样的原因。
:)

#7


can't not found mfc42u.lib
=== 
找到mfc427.lib之后,连上,
但是:

Linking...
H:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\VC_TEMPLATE\mfc42u.lib : 
fatal error LNK1112: module machine type "IA64" conflicts with target machine type "IX86"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
Error executing link.exe.


请问 Muf(沐枫) 怎样解决?
http://www.csdn.net/expert/topic/654/654121.xml?temp=.2101862

#8


既然提示你cannot convert parameter 1 from 'unsigned short [260]' to 'const char *'
你就在第一个变量前加上(const char*)强制转换一下不就可以了?

#9


不管这个程序逻辑如何,我在Win32控制台下用UNICODE方式编译该段代码没有问题.

//请记住在stdafx.h的一开始:
//#define UNICODE
//#define _UNICODE

#include "stdafx.h"
#include "windows.h"
#include "tchar.h"

int main(int argc, char* argv[])
{
   WIN32_FIND_DATA fd;
   LPCTSTR lpszFileName=NULL;

   _tcsstr(lpszFileName,_TEXT(".dat"));
   
   if(_tcscmp(fd.cFileName, _TEXT(".")))
   {
      //....
   }

   return 0;
}

#10


To: wwtmw(剑重无锋 大巧不工)
你一定是在Windows98系统下编译你的程序,并且选择了UNICODE吧。
你可以在WindowsNT/2000/XP下编译,
或者在Win98下不要用UNICODE,改用MBCS。因为Win98不支持UNICODE,因此安装VC时,也没有装对应的库。

==================================
不过我没在Win98下编译过UNICODE程序,我总在NT/2000下编译UNICODE程序,
所以也不知道如何在Win98下增加VC对UNICODE的支持。
你可以考虑用NT/2000
或者重新运行VC安装程序,并且增加UNICODE库,也许可以也不一定。
:)

#11


2:Muf(沐枫) :

其实我也是的2000下面做的,

是这样的:
我按照你的方法,
==
问题所在:你用了UNICODE编译程序,却仍用ANSI的函数。
建议不管是UNICODE还是ANSI,都用上_T函数
如:_tcsstr, _tcscmp (和ANSI一样,只是前面的str改成了_tcs)
这样,编译器就可以根据宏定义决定用strxxx还是wcsstr了。
而常量字串请用_T("")括起,也是同样的原因。
==done

then compile, display the errer massage:
can't not found mfc42u.lib
说我没有mfc427.lib, 我就搜索到mfc427.lib之后,在option选项上连上,
=== done

then compile again:
但是:

Linking...
H:\...\mfc42u.lib : 
fatal error LNK1112: module machine type "IA64" conflicts with target machine type "IX86"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~`
Error executing link.exe.

so....

help, thanks!


#12


to opentuxedo(开缝的燕尾服): 不行噢

#13


???你还用 64 Bit的处理器(Intel® IA64 series processors)???
>>Visual C++ 概念:生成 C/C++ 程序   
>>链接器工具错误 LNK1112模块计算机类型“IA64”与目标计算机类型“IX86”冲突
>>指定为输入的对象文件是为其他计算机类型编译的。

====================================================
也就是说,你用的mfc42u.lib是为IA64处理器而编译的。请换一个吧。

#14


On Windows NT platforms, MFC supports the Unicode standard for encoding wide characters. Unicode is not presently supported on Windows 95.

Note   The Unicode versions of the MFC libraries are not copied to your hard drive unless you select them during a Custom installation. They are not copied during other types of installation. If you attempt to build or run an MFC Unicode application without the MFC Unicode files, you may get errors.

To copy the files to your hard drive, rerun Setup, choose Custom installation, clear all other components except "Microsoft Foundation Class Libraries," click the Details button, and select both "Static Library for Unicode" and "Shared Library for Unicode."

===============================================================
大概意思:
MFC库的Unicode版本没有安装到你的硬盘上。因此当你编译Unicode程序时,将会出错。
要安装这些库文件,你可以重新运行安装程序,并选择“定制安装”, 去掉所有选项除了“Microsoft Foundation Class Libraries” (因为其它组件你已经安装了),然后点“Details”按钮,同时选中“Static Library for Unicode”和“Shared Library for Unicode”。

#15


谢谢 沐枫,

还没有试,不过我相信就这样做就可以的。我加了30分了,谢谢。


请问我怎样才能的MSDN得到 那段  “On Windows NT platforms。。。”?

我input: fatal error LNK1112,只有:
Visual C++ Concepts: Building a C/C++ Program   

Linker Tools Error LNK1112
module machine type 'type1' conflicts with target machine type 'type2'

The object files specified as input were compiled for different machine types.


应该的哪里呢? Thanks again.

#16


上次还看你只有4个3角,又升级了。

#17


:) 那一段话在MSDN 2000.07版是没有的。我是在VS.net上找出来的。
你也可以到msdn.microsoft.com上找。

#18


错了,我又找到了,是在MSDN Library 2000年7月版上面的。位置如下:

MSDN Library - July 2000
+ Visual Studio 6.0 Documentation
  + Visual C++ Documentation
    + Using Visual C++
      + Visual C++ Programmer's Guide
        + Adding Program Functionality
          + Details
            + Unicode Topics

因为是Unicode和MFC的问题,所有我去查找Unicode及MFC都相关的内容。结果找到了。

#19


我记得上次这问题好像已经给了分了。。没有结帐吗?再给一次,


谢谢关注!

#20


(?还没有给分吗?),(现在再给吧)


谢谢关注。

#21