vs2008 unresolved external symbol _main referenced in function ___tmainCRTStart

朱韦刚
博客专家认证
2011-05-25 04:33:37
#include <windows.h>
#include <stdio.h>
#include <tchar.h>

void read()
{
HANDLE hDevice =
CreateFile("\\\\. \\GCpuThread",
GENERIC_READ | GENERIC_WRITE,
0, // share mode none
NULL, // no security
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL ); // no template

if (hDevice == INVALID_HANDLE_VALUE)
{
printf("Failed to obtain file handle to device: "
"%s with Win32 error code: %d\n",
"MyWDMDevice", GetLastError() );
return 1;
}

UCHAR buffer[8];
ULONG ulRead;
BOOL bRet = ReadFile(hDevice,buffer,8,&ulRead,NULL);
if (bRet)
{
printf("Read %d bytes:",ulRead);
for (int i=0;i<(int)ulRead;i++)
{
printf("%02X ",buffer[i]);
}

printf("\n");
}

CloseHandle(hDevice);
}

int main()
{
//while(1)
{
read();
}
return getchar();
}

error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup


高手帮解决!!!实现功能读取驱动数据!!
...全文
238 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
就想叫yoko 2011-05-25
  • 打赏
  • 举报
回复
ALT+F7打开项目属性
linker-system-subsystem-Console (/SUBSYSTEM:CONSOLE)
朱韦刚 2011-05-25
  • 打赏
  • 举报
回复
谢谢,给分了!
ljt3969636 2011-05-25
  • 打赏
  • 举报
回复
拷贝了,除了一个小错误没有问题,还是你工程有问题


#include <windows.h>
#include <stdio.h>
#include <tchar.h>

void read()
{
HANDLE hDevice =
CreateFile("\\\\. \\GCpuThread",
GENERIC_READ | GENERIC_WRITE,
0, // share mode none
NULL, // no security
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL ); // no template

if (hDevice == INVALID_HANDLE_VALUE)
{
printf("Failed to obtain file handle to device: "
"%s with Win32 error code: %d\n",
"MyWDMDevice", GetLastError() );
return ;//void但是你代码里这里有返回值
}

UCHAR buffer[8];
ULONG ulRead;
BOOL bRet = ReadFile(hDevice,buffer,8,&ulRead,NULL);
if (bRet)
{
printf("Read %d bytes:",ulRead);
for (int i=0;i<(int)ulRead;i++)
{
printf("%02X ",buffer[i]);
}

printf("\n");
}

CloseHandle(hDevice);
}

朱韦刚 2011-05-25
  • 打赏
  • 举报
回复
只有一个main ,你copy 下试试好吧!
ljt3969636 2011-05-25
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 zhuweigangzwg 的回复:]

没建错,要不你copy下试试!
[/Quote]
你看看你的工程,打开的文件是不是哪个里面还有WinMian函数
朱韦刚 2011-05-25
  • 打赏
  • 举报
回复
没建错,要不你copy下试试!
ljt3969636 2011-05-25
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 macrojj 的回复:]

工程建错了。
/ S U B S Y S T E M : C O N D O L E
[/Quote]
UP
macrojj 2011-05-25
  • 打赏
  • 举报
回复
工程建错了。
/ S U B S Y S T E M : C O N D O L E

70,020

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧