急切求助!!VS 2005的类型转换,请教高手!

tianjiao85 2008-04-13 12:31:34
在学网络编程,参考原文:http://www.kuqin.com/networkprog/0001.html
出现问题:
1>spider.cpp
1>d:\my documents\visual studio 2005\projects\spider\spider\spider.cpp(27) : error C2664: 'wsprintfW' : cannot convert parameter 1 from 'char [256]' to 'LPWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>d:\my documents\visual studio 2005\projects\spider\spider\spider.cpp(28) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'char [256]' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
请为小弟解疑,在线等待,谢谢。
代码:

#include <Windows.h>
#include <WinSock.h>

int WSAReturn;
WSADATA WSAData;
HOSTENT *hostEntry;
char hostName[256];
char hostAddress[256];//host ip

int APIENTRY WinMain( __in HINSTANCE hInstance,
__in_opt HINSTANCE hPrevInstance,
__in_opt LPSTR lpCmdLine,
__in int nShowCmd )
{
WSAReturn = WSAStartup(0x0101,&WSAData);

if (WSAReturn == 0)
{
gethostname(hostName,256);
hostEntry = gethostbyname(hostName);
if (hostEntry != 0)
{
wsprintf(hostAddress,"%d.%d.%d.%d",
(hostEntry->h_addr_list[0][0]&0x00ff),
(hostEntry->h_addr_list[0][1]&0x00ff),
(hostEntry->h_addr_list[0][2]&0x00ff),
(hostEntry->h_addr_list[0][3]&0x00ff));
MessageBox(NULL,hostAddress,hostName,MB_OK);
}
}
WSACleanup();
return 0;
}
...全文
165 11 打赏 收藏 举报
写回复
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
tianjiao85 2008-04-14
  • 打赏
  • 举报
回复
自己顶
tianjiao85 2008-04-13
  • 打赏
  • 举报
回复
问题是解决了,可是又出来新问题了,(时间有限)直接问大家了,对大侠是小问题了,
spider.obj : error LNK2019: unresolved external symbol _WSACleanup@0 referenced in function _WinMain@16
1>spider.obj : error LNK2019: unresolved external symbol _gethostbyname@4 referenced in function _WinMain@16
1>spider.obj : error LNK2019: unresolved external symbol _gethostname@8 referenced in function _WinMain@16
1>spider.obj : error LNK2019: unresolved external symbol _WSAStartup@8 referenced in function _WinMain@16
1>D:\My Documents\Visual Studio 2005\Projects\spider\Debug\spider.exe : fatal error LNK1120: 4 unresolved externals
我是按照原来的代码做的,一模一样,又是VC的设置吗?
Kratos 2008-04-13
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 baihacker 的回复:]
项目->属性->配置属性->字符集->使用多字节字符集
[/Quote]
baihacker 2008-04-13
  • 打赏
  • 举报
回复
项目->属性->配置属性->字符集->使用多字节字符集
tianjiao85 2008-04-13
  • 打赏
  • 举报
回复
WINDOWS下各种类型该如何转换?
C++ primer中有说类型转换有:
static_cast,dynamic_cast,const_cast,reinterpret_cast,这里该如何转换?


tianjiao85 2008-04-13
  • 打赏
  • 举报
回复
编译成功了:
按下绿色的debug 按钮:
出现:
'spider.exe': Loaded 'D:\My Documents\Visual Studio 2005\Projects\spider\debug\spider.exe', Symbols loaded.
。。。。。
。。。。。
'spider.exe': Loaded 'G:\系统常用软件\Downloads\360安全卫士3.64\360safe_3.5\safemon\safemon.dll', Binary was not built with debug information.
。。。。。
。。。。。
想问的是,我是运行了安全卫士,可是关安全卫士什么事情呢,safemon.dll'是什么东西呢?
这条信息什么意思呢。
tianjiao85 2008-04-13
  • 打赏
  • 举报
回复
谢谢飞雪,
以前看到过这种方法,怎么就没想起来用呢,看来要多多实践。
VC 6.0下的设置大家都知道了,
VC 2005下是这样设置的:
project->configuration properties->linker->input->additional dependencies;
jeff_nie 2008-04-13
  • 打赏
  • 举报
回复
路过学习.
tianjiao85 2008-04-13
  • 打赏
  • 举报
回复
请看下面的示例:

复制代码
// LNK2019c.cpp
// LNK2019 expected
extern int i;
extern void g();
void f() {
i++;
g();
}
int main() {}


如果在生成中包含的某个文件中没有定义 i 和 g,链接器将生成 LNK2019。可以添加这些定义,方法是将包含这些定义的源代码文件包括为编译的一部分。或者可以将包含这些定义的 .obj 或 .lib 文件传递给链接器。
baihacker 2008-04-13
  • 打赏
  • 举报
回复

#pragma comment( lib , "ws2_32.lib")//加上这个
tianjiao85 2008-04-13
  • 打赏
  • 举报
回复
看了msdn,好像要加入.lib文件,VS 2005在哪里弄呢?
发帖
C++ 语言

6.3w+

社区成员

C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
帖子事件
创建了帖子
2008-04-13 12:31
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下