native已退出,代码为0(0x0)

编程入门 行业动态 更新时间:2024-10-28 18:36:04
本文介绍了native已退出,代码为0(0x0)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

大家好我正在使用serialport programm,但在运行programmin时会出现以下错误。请问任何人请帮帮我

Hello every one i am working on serialport programm , but while running programmin its give the following error. Can any one please help me out please

/** Serial.cpp * * */ #include <iostream> using namespace std; #include <windows.h> #include <tchar.h> #include <crtdbg.h> #include "serialtestdll.h" int WINAPI _tWinMain ( HINSTANCE /*hInst*/, HINSTANCE /*hInstPrev*/, LPTSTR /*lptszCmdLine*/, int /*nCmdShow*/ ){ } Serial::Serial(tstring &commPortName, int baudeRate) { commHandle = CreateFile(commPortName.c_str(), GENERIC_READ|GENERIC_WRITE, 0,NULL, OPEN_EXISTING, 0, NULL); if(commHandle == INVALID_HANDLE_VALUE) { throw("ERROR: Could not open com port"); } else { // set timeouts COMMTIMEOUTS cto = { MAXDWORD, 0, 10,100, 500}; DCB dcb; if(!SetCommTimeouts(commHandle,&cto)) { Serial::~Serial(); throw("ERROR: Could not set com port time-outs"); } // set DCB memset(&dcb,0,sizeof(dcb)); dcb.DCBlength = sizeof(dcb); dcb.BaudRate = 9600; dcb.fBinary = 1; dcb.fDtrControl = DTR_CONTROL_ENABLE; dcb.fRtsControl = RTS_CONTROL_ENABLE; dcb.Parity = NOPARITY; dcb.StopBits = ONESTOPBIT; dcb.ByteSize = 8; if(!SetCommState(commHandle,&dcb)) { Serial::~Serial(); throw("ERROR: Could not set com port parameters"); } } } Serial::~Serial() { CloseHandle(commHandle); } double Serial::write(const char *buffer) { char cmd[] = "!GV\r"; DWORD numWritten; WriteFile(commHandle, cmd, 5, &numWritten, NULL); return numWritten; } int Serial::write(const char *buffer, int buffLen) { char cmd[] = "!GV\r"; DWORD numWritten; WriteFile(commHandle, cmd, 5, &numWritten, NULL); return numWritten; } int Serial::read(char *buffer, int buffLen, bool nullTerminate) { DWORD numRead; if(nullTerminate) { --buffLen; } BOOL ret = ReadFile(commHandle, buffer, buffLen, &numRead, NULL); if(!ret) { return 0; } if(nullTerminate) { buffer[numRead] = '\r'; } return numRead; } #define FLUSH_BUFFSIZE 10 void Serial::flush() { char buffer[FLUSH_BUFFSIZE]; int numBytes = read(buffer, FLUSH_BUFFSIZE, false); while(numBytes != 0) { numBytes = read(buffer, FLUSH_BUFFSIZE, false); } }

推荐答案

您的 _tWinMain 功能是空的并立即返回。您必须向函数体添加一些代码。 Your _tWinMain function is empty and returns immediately. You must add some code to the function body.

添加到Jochen Arndt所说的内容:当您获得应用程序返回代码为零(如您所做)时,表示程序已成功完成 - 任何非零值都是错误代码。 您的应用程序入口点 _tWinMain 什么都不做,所以它成功完成,您将获得零返回代码。定义一个类不会创建它的实例,也不会执行该类中的任何代码,除非你的代码明确指示它应该执行。 To add to what Jochen Arndt says: when you get an app return code of zero (as you do) that means "Program completed successfully" - any non-zero value is an error code. Your application entry point _tWinMain does nothing, so it completes successfully and you get a zero return code. Defining a class does not create an instance of it, nor does any of the code in that class get executed unless your code specifically instructs that it should.

你好每一个我都是新手c ++中的编程语言请告诉我如何设置实例 Hello every one i am very new to programming language in c++ please do let me know how can i cerate an instance

更多推荐

native已退出,代码为0(0x0)

本文发布于:2023-07-27 15:59:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1223275.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:代码   native

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!