Okay, So I am new to programming and am trying to transfer data from a machine via RS232 to an "adapter" program that allows connection to a "client or agent" program that sends the data to the web(localhost) in .xml format. Basically a socket setup. Both programs seem to be working fine, but when I connected the client program to the "adapter", it says CreateFile Failed.
When I run the first program, executeable window pops up and says:
Server Started, waiting on port 7878
Then when I connect to the localhost it says:
Server Started, waiting on port 7878
Connected to: 127.0.0.1 on port 2816
CreateFile Failed
I am pretty sure the port numbers do not need to match since I am trying to view this data on the local host. 7878 is just the default port number in the adapter program.
I am not sure which section of code to look at so can someone tell me where to look to fix this problem? I am not sure if it is an .xml proble, schema problem, or what the problem is. Thanks for any advice or help you can give me.
How do I call the GetLastError()? Sorry, this is all very new to me
Seriously, how can you not know how to call a function when the code you posted is full of other function calls?? What about that call to CreateFile(), strcpy, etc.? You seem to be doing fine calling those functions.
GetLastError() is just another function you call when you get an error. Just call the function and see what the value that is returned to you is. That value is the error condition.
Regards,
Paul McKenzie
Last edited by Paul McKenzie; September 7th, 2010 at 11:18 AM.
I am not getting any message, they are running the same way. No errors pop up in the call stack for either program. Nothing happens when I inserted the GetLastError function
I am not getting any message, they are running the same way. No errors pop up in the call stack for either program. Nothing happens when I inserted the GetLastError function
Step through your code in a debugger and look at the dwError value.
I am not getting any message, they are running the same way. No errors pop up in the call stack for either program. Nothing happens when I inserted the GetLastError function
The GetLastError() function returns to you a value -- that value is the error code. You are to do with that error code whatever you need to do with it -- log it, display it in your own window, inspect it, who knows.
You are under the misconception that GetLastError() should only be used when you have an error in your program. That is false. It should be called every time you call a Windows API function and that function fails. It should be part of your program, and right now, it isn't. You are calling many Windows API functions in the code you posted, and you don't call GetLastError() even once for when they fail.
Yes, you are checking for a return value from the functions you're calling themselves, but you must call the "second line of defense", which is the GetLastError() function to tell you exactly why the function failed. In addition, you should also learn to use FormatMessage() in conjuction with GetLastError(). Therefore your code is not really complete.
Secondly, if you think about it for a moment, why would an API function such as GetLastError() want to display error boxes? That is up to the programmer and application as to how to display or record errors. What if I don't want error messages popping up all over the place, and instead just want to log the error number in a file?
Ok, so when I try to step through in debug and putting @err,h in Watch window I get:
Watch:
@err,h CXX0026: Error: bad format string
CallStack:
> haas.exe!main(int aArgc, char * * aArgv) Line 40 C++
haas.exe!__tmainCRTStartup() Line 555 + 0x17 bytes C
kernel32.dll!7c817077()
[Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll]
Code:
#include "internal.hpp"
#include "haas_adapter.hpp"
#include "server.hpp"
#include "string_buffer.hpp"
int main(int aArgc, char *aArgv[])
{
int port = 7878;
int i = 0;
bool debug = false;
bool positions = false;
while (aArgc > 0 && aArgv[i][0] == '-')
{
if (aArgv[i][1] == 'd')
debug = true;
else if (aArgv[i][1] == 'p')
positions = true;
else
{
printf("Invalid option: %s\n", aArgv[i]);
printf("Usage: %s [-dp] <Serial_COM> [port]\n", aArgv[0]);
exit(1);
}
i++;
aArgc--;
}
if (aArgc > 2)
port = atoi(aArgv[i + 1]);
/* Construct the adapter and start the server */
HaasSerial *serial = new HaasSerial(aArgv[i], 19200, "none", 7, 1, debug);
HaasAdapter adapter(port, serial, positions);
adapter.startServer();
return 0;
}
Line 40 is:
int main(int aArgc, char *aArgv[]) Line 39
{ Line 40
Ok, so when I try to step through in debug and putting @err,h in Watch window I get:
???
What is all of this stuff? How hard is it to call the GetLastError() function and inspect the error value returned??? If you don't want to ignore what we're telling you, then why post?
Sorry, I just havent been able to get a GetLastError() function to return anything. That is why I started trying other things. Seems to only cause problems when I try putting something in there. When I do not get any problems, I also do not get any result so I am not sure what I am doing wrong.
I am a complete newb to programming, but unfortunately, have been handed a project that is dealing with a fairly complex program that was downloaded. So most of the code I have posted, I did not actually do. Just trying to get this program to run properly ASAP
Bookmarks