|
Well, even if there only exist one window of any given class in the entire universe, Windows still needs to know these things. And since there may exists hundreds of windows of the same class (a static text control is a good example) you may as well put these common things into a windows class instead of defining them for each instance of the class. It's analogous to defining the member functions of a C++ class each time you declare an instance - that would not be efficient either.
The bottom line is that your Windows program won't work if you don't register your window classes. Live with it.
Cheers
Steen.
"Are you gonna check your makeup when you're done whining?" John Simmons, 05/31/2006
|
|
|
|
|
|
Thank you.
I have to look deep inside this.
- NS -
|
|
|
|
|
Don't confuse a Windows class with a C++ class. They are totally different.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
No confusion
But confusion is only in the reason for such an idea of having a class registered to create a window. I dont know the reason (that cannot be avoided) behind this idea.
- NS -
|
|
|
|
|
// File: struct-test.cpp
#include "Socket.h"
#include <iostream>
#include <process.h>
#include <sstream>
#include <fstream>
#include <string>
#include <winsock.h>
#include <winsock2.h>
#include <windows.h>
#include <cstdio>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
//TCP/IP
int open_connection(const string& hostname, int portnr) {
SOCKET mySocket = socket(AF_INET, SOCK_STREAM, 0);
cout << "errno = " << errno << endl;
cout << "socket = " << mySocket << endl;
struct sockaddr_in itsTCPAddr;
memset (&itsTCPAddr, 0, sizeof(itsTCPAddr));
itsTCPAddr.sin_family = AF_INET;
unsigned int IPbytes;
// try if hostname is hard ip address
if ((IPbytes = inet_addr(hostname.c_str())) == INADDR_NONE) {
cout << "inet_addr return INADDR_NONE" << endl;
// No, try to resolve the name
struct hostent* hostEnt; // server host entry
if (!(hostEnt = gethostbyname(hostname.c_str()))) {
cout << "Socket:Hostname (" << hostname << ") can not be resolved" << endl;
return (-2);
}
// Check type
if (hostEnt->h_addrtype != AF_INET) {
cout << "Socket:Hostname(" << hostname << ") is not of type AF_INET"<< endl;
return (-3);
}
memcpy (&IPbytes, hostEnt->h_addr, sizeof (IPbytes));
}
memcpy ((char*) &itsTCPAddr.sin_addr.s_addr, (char*) &IPbytes, sizeof(IPbytes));
itsTCPAddr.sin_port = htons(portnr);
printf ("IPbytes = %04x\n", IPbytes);
printf ("sin_addr:%x", itsTCPAddr.sin_addr);
printf ("sin_port:%d", itsTCPAddr.sin_port);
printf ("sin_fami:%d", itsTCPAddr.sin_family);
int result = connect(mySocket, (struct sockaddr *)&itsTCPAddr, sizeof(struct sockaddr_in));
cout << "connect_errno = " << errno << endl;
cout << "result = " << result << endl;
return (mySocket);
}
struct Modbus_TCP { // (14 bytes) Declare Modbus_TCP struct type
short TransactionIdentifier; // = 2 bytes
short ProtocolIdentifier; // = 2 bytes
short Length; // = 2 bytes
byte UnitIdentifier; // = 1 byte
// -modbus
byte FunctionForceMultipleCoils; //:15 = 1 bytes
short ReferenceNumber; // = 2 bytes
short BitCount; // = 2 bytes
byte ByteCount; // = 1 byte
byte Data; // = 1 byte
} Modbus_TCP_t;
int main() {
WORD wVersionRequested = MAKEWORD(1,1);
WSADATA wsaData;
int nRet;
nRet = WSAStartup(wVersionRequested, &wsaData);
if (wsaData.wVersion != wVersionRequested)
{
fprintf(stderr,"\n Wrong version\n");
return(-1);
}
int connection;
cout << "opening connection" << endl;
connection = open_connection("10.151.218.2", 502);
cout << "connection = " << connection << endl;
cout << "errno = " << errno << endl;
struct Modbus_TCP command;
command.TransactionIdentifier = htons(0);
command.ProtocolIdentifier = htons(0);
command.Length = htons(8); //moeten 4 bits zijn
command.UnitIdentifier = 01;
command.FunctionForceMultipleCoils = 15;
command.ReferenceNumber = htons(16);
command.BitCount = htons(6);
command.ByteCount = 01;
command.Data = 8;
int result = send(connection, (char*)&command, sizeof(command), 0);
cout << "sizeof(command)=" << sizeof(command) << endl;
cout << "sendresult = "<< result << endl;
return 0;
}
this is my error
--------------------Configuration: Cpp1 - Win32 Debug--------------------
Linking...
Cpp1.exe - 0 error(s), 0 warning(s)
I have changed it (with some help) it is working now
-- modified at 3:12 Thursday 12th October, 2006
Dorbeck
|
|
|
|
|
mySocket = socket(PF_INET, SOCK_STREAM, 0);
struct sockaddr_in itsTCPAddr;
memset (&itsTCPAddr, 0, sizeof(itsTCPAddr));
itsTCPAddr.sin_family = AF_INET;
uint32 IPbytes;
if ((IPbytes = inet_addr(itsHost.c_str())) == INADDR_NONE) {
struct hostent* hostEnt;
if (!(hostEnt = gethostbyname(itsHost.c_str()))) {
LOG_ERROR(formatString("Socket:Hostname (%s) can not be resolved",
itsHost.c_str()));
return (itsErrno = BADHOST);
}
if (hostEnt->h_addrtype != AF_INET) {
LOG_ERROR(formatString("Socket:Hostname(%s) is not of type AF_INET", itsHost.c_str()));
return (itsErrno = BADADDRTYPE);
}
memcpy (&IPbytes, hostEnt->h_addr, sizeof (IPbytes));
}
memcpy ((char*) &itsTCPAddr.sin_addr.s_addr, (char*) &IPbytes, sizeof(IPbytes));
}
itsTCPAddr.sin_addr.s_addr = htonl(INADDR_ANY);
connect(mySocket, mySockAddr, sizeof(struct sockaddr_in));
}
What is doing this code outside any functions (and out of the main function) ? You cannot have code outside functions (otherwise how will you call this code ?), only variable declarations.
Furthermore, the first error ( error C2660: 'send' : function does not take 2 ) is because you don't respect the function prototype (check the doc to see how to use the function).
|
|
|
|
|
hmmm, i am a real amateur programmer so everything is quit new for me. I put it into a function but now it's even worse with my errors. I searched for a function document to find out somthing for a send function but i couldn't find anything. can you please send me a link or something so i can read and understand what i do wrong.
thanks allot
Dorbeck
|
|
|
|
|
Seems like you are lacking the basics of C++ (how to use functions is really the begining). I strongly suggest that you start from the start before trying to do complex things (like using sockets and things like that). Without understanding the concepts, you won't be able to even understand the documentation.
|
|
|
|
|
yes, but the problem is that I have to make a divece for my work. and for that i have to send a code to a server. I believe the only way to do this is to build a socket. I am in my 3th year of studing so I think that with some good documentation i will come quit far. you would make me ferry happy. If i don't make it and i have to do it al over it cost me half a year of extra study time which i don't verry like.
Dorbeck
|
|
|
|
|
Yeah I know but it is very difficult to help if you simply don't understand the basics.
And why for example are you using uint32 ?
|
|
|
|
|
It was to send an 4 byte signal.
|
|
|
|
|
That was not my question. My question was why you use uint32 ? Where are they defined ? It is not in the standard C or C++, so why are you using them ? Are they defined somewhere ?
|
|
|
|
|
well, i don't use it any more so it isn't a problem any more. but it was not defined so you are write he didn't know what to do. but now my program works but it doesn't send the write signal becaus he doesn't know what to do with short. when I want to send a 2 byte signal I use short. whitch i think is correct.
Dorbeck
|
|
|
|
|
dorbeck wrote: when I want to send a 2 byte signal I use short. whitch i think is correct.
Uuuh ?
I strongly believe that you should at least learn the basics. Otherwise we will need to write the program for you.
|
|
|
|
|
Okey, I have got a book now. I hope afther that it will go a bit better. thnx a lot.
Dorbeck
|
|
|
|
|
dorbeck wrote: i am a real amateur programmer so everything is quit new for me.
All the more reason to start with a less ambitious project. Dealing with sockets before you've mastered the basics (of C) is just a recipe for failure.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
dorbeck wrote: whats wrong with my program.
I suspect PEBKAC (Problem exists between k**boa*d and ch*ir)
Moonen's answer is enough explanatory.
Nobody can give you wiser advice than yourself. - Cicero
|
|
|
|
|
|
what is a strongly typed and loosely typed language ?
with what does it deal with, why interfaces are strongly typed ?
but not loosely typed?
Fly Like An Eagle With MIGHTY POWER.
|
|
|
|
|
May I take this opportunity to introduce you a new cool tool?[^]
Nobody can give you wiser advice than yourself. - Cicero
|
|
|
|
|
See here.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
|
HI,
i have a filedialog box, how to select mutiple files and to get the filenames in an array?
cud ne body help me out??
thnx in advance,
zari
|
|
|
|
|