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


高手帮解决!!!实现功能读取驱动数据!!
...全文
222 8 打赏 收藏 转发到动态 举报
写回复
用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
笔记本的风扇控制 ---------------------------------------- 09 November 2006. Summary of changes for version 20061109: 1) ACPI CA Core Subsystem: Optimized the Load ASL operator in the case where the source operand is an operation region. Simply map the operation region memory, instead of performing a bytewise read. (Region must be of type SystemMemory, see below.) Fixed the Load ASL operator for the case where the source operand is a region field. A buffer object is also allowed as the source operand. BZ 480 Fixed a problem where the Load ASL operator allowed the source operand to be an operation region of any type. It is now restricted to regions of type SystemMemory, as per the ACPI specification. BZ 481 Additional cleanup and optimizations for the new Table Manager code. AcpiEnable will now fail if all of the required ACPI tables are not loaded (FADT, FACS, DSDT). BZ 477 Added #pragma pack(8/4) to acobject.h to ensure that the structures in this header are always compiled as aligned. The ACPI_OPERAND_OBJECT has been manually optimized to be aligned and will not work if it is byte-packed. Example Code and Data Size: These are the sizes for the OS- independent acpica.lib produced by the Microsoft Visual C++ 6.0 32- bit compiler. The debug version of the code includes the debug output trace mechanism and has a much larger code and data size. Previous Release: Non-Debug Version: 78.1K Code, 17.1K Data, 95.2K Total Debug Version: 155.4K Code, 63.1K Data, 218.5K Total Current Release: Non-Debug Version: 77.9K Code, 17.0K Data, 94.9K Total Debug Version: 155.2K Code, 63.1K Data, 218.3K Total 2) iASL Compiler/Disassembler and Tools: Fixed a problem where the presence of the _OSI predefined control method within complex expressions could cause an internal compiler error. AcpiExec: Implemented full region support for multiple address spaces. SpaceId is now part of the REGION object. BZ 429 ---------------------------------------- 11 Oc

69,378

社区成员

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

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