|
CPPUNIT_PLUGIN_IMPLEMENT macro internally implements the dllmain function. I have delcared this macro in cpp file.
|
|
|
|
|
then did u should comment out the actuall dllMain()
Also ensure u havent used the macro twice.
nave
|
|
|
|
|
I have written the following code in visual C++. it worked like it should. But know i want it to work in linux. I thought that C++ worked the same under every platform. But I included for example winsocket.h en wsock32.lib. Do I have to rewrite my complete code or is there a nother way to let my code work? I use Vi in linux.
in linux I include these files:
#include <fstream.h>
#include <sstream.h>
#include <iostream.h>
#include <logger.h>
#include <net socket.h="">
#include <process.h>
#include <stringutil.h>
#include <typenames.h>
#include <sys socket.h="">
#include <sys time.h="">
in windows i included those files:
#include "Socket.h"
#include <iostream>
#include <process.h>
#include <sstream>
#include <fstream>
#include <string>
#include <windows.h>
#include <winsock.h>
#include <winsock2.h>
#include <cstdio>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
double setpoint = 20;
int open_connection(const string& hostname, int portnr) {
SOCKET mySocket = socket(AF_INET, SOCK_STREAM, 0);
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) {
// No, try to resolve the name
struct hostent* hostEnt; // server host entry
if (!(hostEnt = gethostbyname(hostname.c_str()))) {
return (-2);
}
// Check type
if (hostEnt->h_addrtype != AF_INET) {
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);
int result = connect(mySocket, (struct sockaddr *)&itsTCPAddr, sizeof(struct sockaddr_in));
return (mySocket);
}
struct StuurUitlezen { // (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 Function3; //:15 = 1 bytes
short ReferenceNumber; // = 2 bytes
short WordCount; // = 2 bytes
} StuurUitlezen_t;
///////////////////////////////////////////////////////////////////////
#pragma pack(1)
struct StuurUitpt { // (14 bytes) Declare Modbus_TCP struct type
short TransactionIdentifie; // = 2 bytes
short ProtocolIdentifie; // = 2 bytes
short Lengt; // = 2 bytes
byte UnitIdentifie; // = 1 byte
// -modbus = 6 bytes
byte Functio; //:15 = 1 bytes
byte ByteCount; // = 1 byte
short T1; // = 2 bytes
short T2; // = 2 bytes
short T3; // = 2 bytes
short T4; // = 2 bytes
short T5; // = 2 bytes
short T6; // = 2 bytes
short T7; // = 2 bytes
WORD Data[22]; // = rest data 22 bytes over
} StuurUitpt_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 h = 0;
while(h < 10) {
h++;
int connection;
connection = open_connection("10.151.218.1", 502);
struct StuurUitlezen demand;
demand.TransactionIdentifier = htons(0);
demand.ProtocolIdentifier = htons(0);
demand.Length = htons(8); //moeten 4 bits zijn
demand.UnitIdentifier = 01;
demand.Function3 = 3;
demand.ReferenceNumber = 0;
demand.WordCount = htons(18);
int result = send(connection, (char*)&demand, sizeof(demand), 0);
struct StuurUitpt receiv;
receiv.TransactionIdentifie;
receiv.ProtocolIdentifie;
receiv.Lengt;
receiv.UnitIdentifie;
receiv.Functio;
receiv.ByteCount;
receiv.T1;
receiv.T2;
receiv.T3;
receiv.T4;
receiv.T5;
receiv.T6;
receiv.T7;
receiv.Data;
int uitpt = recv(connection, (char*)&receiv, sizeof(receiv), 0);
short HT1 = htons(receiv.T1);
short HT2 = htons(receiv.T2);
short HT3 = htons(receiv.T3);
short HT4 = htons(receiv.T4);
short HT5 = htons(receiv.T5);
short HT6 = htons(receiv.T6);
short HT7 = htons(receiv.T7);
double RT1 = (HT1 - 16384) / 327.6;
double RT2 = (HT2 - 16384) / 327.6;
double RT3 = (HT3 - 16384) / 327.6;
double RT4 = (HT4 - 16384) / 327.6;
double RT5 = (HT5 - 16384) / 327.6;
double RT6 = (HT6 - 16384) / 327.6;
double RT7 = (HT7 - 16384) / 327.6;
fprintf(stderr,"RT1: %3.2f\n", RT1);
fprintf(stderr,"RT2: %3.2f\n", RT2);
fprintf(stderr,"RT3: %3.2f\n", RT3);
fprintf(stderr,"RT4: %3.2f\n", RT4);
fprintf(stderr,"RT5: %3.2f\n", RT5);
fprintf(stderr,"RT6: %3.2f\n", RT6);
fprintf(stderr,"RT7: %3.2f\n", RT7);
//Temperatuur is readed, from this point send
double MaxTemp = setpoint + 0.5;
double MinTemp = setpoint - 0.5;
int RTH1;
int RTH2;
int RTH3;
int RTH4;
int RTH5;
int RTH6;
int RTH7;
if (RT1 > MaxTemp) { RTH1 = 1; };
if (RT2 > MaxTemp) { RTH2 = 1; };
if (RT3 > MaxTemp) { RTH3 = 1; };
if (RT4 > MaxTemp) { RTH4 = 1; };
if (RT5 > MaxTemp) { RTH5 = 1; };
if (RT6 > MaxTemp) { RTH6 = 1; };
if (RT7 > MaxTemp) { RTH7 = 1; };
if (RT1 < MinTemp) { RTH1 = 0; };
if (RT2 < MinTemp) { RTH2 = 0; };
if (RT3 < MinTemp) { RTH3 = 0; };
if (RT4 < MinTemp) { RTH4 = 0; };
if (RT5 < MinTemp) { RTH5 = 0; };
if (RT6 < MinTemp) { RTH6 = 0; };
if (RT7 < MinTemp) { RTH7 = 0; };
struct Modbus_TCP { // (14 bytes) Declare Modbus_TCP struct type
short TransactionIdentifiers; // = 2 bytes
short ProtocolIdentifiers; // = 2 bytes
short Lengths; // = 2 bytes
byte UnitIdentifiers; // = 1 byte
// -modbus
byte FunctionForceMultipleCoilss; //:15 = 1 bytes
short ReferenceNumbers; // = 2 bytes
short BitCounts; // = 2 bytes
byte ByteCounts; // = 1 byte
byte Datas; // = 1 byte (hier bepaal je wat aan en uit gaat)
} Modbus_TCP_t;
connection = open_connection("10.151.218.2", 502);
struct Modbus_TCP command;
command.TransactionIdentifiers = htons(0);
command.ProtocolIdentifiers = htons(0);
command.Lengths = htons(8); //moeten 4 bits zijn
command.UnitIdentifiers = 01;
command.FunctionForceMultipleCoilss = 15;
command.ReferenceNumbers = htons(16);
command.BitCounts = htons(6);
command.ByteCounts = 01;
command.Datas = RTH1+(RTH2*2)+(RTH3*4)+(RTH4*8)+(RTH5*16)+(RTH6*32)+(RTH6*64);
result = send(connection, (char*)&command, sizeof(command), 0);
Sleep (5000);
}
return 0;
}
Errors in linux:
Which are A lot.
make all-recursive
make[1]: Entering directory `/home/tauber/LOFAR/MAC/APL/StsMisc/build/gnu_debug'
Making all in src
make[2]: Entering directory `/home/tauber/LOFAR/MAC/APL/StsMisc/build/gnu_debug/src'
if /usr/bin/g++32 -DHAVE_CONFIG_H -I. -I/home/tauber/LOFAR/MAC/APL/StsMisc/src -I.. -I/home/tauber/LOFAR/MAC/APL/StsMisc/build/gnu_debug/pkginc -I/home/tauber/LOFAR/MAC/APL/StsMisc/build/gnu_debug/pkgbldinc -I/home/tauber/LOFAR/MAC/APL/StsMisc/build/gnu_debug -I/home/tauber/LOFAR/MAC/APL/StsMisc/include -DUSE_DEBUG -DUSE_THREADS -pthread -D_GNU_SOURCE -I/usr/local/log4cplus/gnu/include -I/home/tauber/LOFAR/installed/gnu_debug/include -g -W -Wall -Woverloaded-virtual -Wno-unknown-pragmas -MT ModBusRead.o -MD -MP -MF ".deps/ModBusRead.Tpo" -c -o ModBusRead.o /home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc; \
then mv -f ".deps/ModBusRead.Tpo" ".deps/ModBusRead.Po"; else rm -f ".deps/ModBusRead.Tpo"; exit 1; fi
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:31: 'byte' is used as a
type, but is not defined as a type.
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:34: 'byte' is used as a
type, but is not defined as a type.
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:49: 'byte' is used as a
type, but is not defined as a type.
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:52: 'byte' is used as a
type, but is not defined as a type.
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:53: 'byte' is used as a
type, but is not defined as a type.
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:61: syntax error before `[
' token
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:68: ISO C++ forbids
declaration of `hostname' with no type
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc: In function `int
open_connection(int, std::string&, int)':
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:70: `mySocket' undeclared
(first use this function)
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:70: (Each undeclared
identifier is reported only once for each function it appears in.)
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:78: request for member `
c_str' in `hostname', which is of non-aggregate type `int'
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:78: `inet_addr' undeclared
(first use this function)
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:82: request for member `
c_str' in `hostname', which is of non-aggregate type `int'
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:82: `gethostbyname'
undeclared (first use this function)
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:89: invalid use of
undefined type `struct hostent'
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:81: forward declaration of
`struct hostent'
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:93: invalid use of
undefined type `struct hostent'
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:81: forward declaration of
`struct hostent'
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:99: warning: unused
variable `int result'
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc: In function `int main()':
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:108: `WORD' undeclared
(first use this function)
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:108: syntax error before `
=' token
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:109: `WSADATA' undeclared
(first use this function)
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:112: `wVersionRequested'
undeclared (first use this function)
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:112: `wsaData' undeclared
(first use this function)
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:112: `WSAStartup'
undeclared (first use this function)
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:127: invalid conversion
from `const char*' to `int'
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:127: could not convert `
502' to `std::string&'
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:68: in passing argument 2
of `int open_connection(int, std::string&, int)'
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:129: aggregate `
StuurUitlezen demand' has incomplete type and cannot be defined
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:147: `struct StuurUitpt'
has no member named `UnitIdentifie'
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:148: `struct StuurUitpt'
has no member named `Functio'
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:149: `struct StuurUitpt'
has no member named `ByteCount'
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:157: `struct StuurUitpt'
has no member named `Data'
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:225: 'byte' is used as a
type, but is not defined as a type.
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:228: 'byte' is used as a
type, but is not defined as a type.
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:231: 'byte' is used as a
type, but is not defined as a type.
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:232: 'byte' is used as a
type, but is not defined as a type.
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:237: invalid conversion
from `const char*' to `int'
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:237: could not convert `
502' to `std::string&'
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:68: in passing argument 2
of `int open_connection(int, std::string&, int)'
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:244: `struct
main()::Modbus_TCP' has no member named `UnitIdentifiers'
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:245: `struct
main()::Modbus_TCP' has no member named `FunctionForceMultipleCoilss'
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:248: `struct
main()::Modbus_TCP' has no member named `ByteCounts'
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:249: `struct
main()::Modbus_TCP' has no member named `Datas'
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:253: `Sleep' undeclared
(first use this function)
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:160: warning: unused
variable `int uitpt'
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:234: warning: unused
variable `main()::Modbus_TCP Modbus_TCP_t'
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:144: warning: statement
with no effect
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:145: warning: statement
with no effect
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:146: warning: statement
with no effect
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:150: warning: statement
with no effect
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:151: warning: statement
with no effect
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:152: warning: statement
with no effect
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:153: warning: statement
with no effect
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:154: warning: statement
with no effect
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:155: warning: statement
with no effect
/home/tauber/LOFAR/MAC/APL/StsMisc/src/ModBusRead.cc:156: warning: statement
with no effect
make[2]: *** [ModBusRead.o] Error 1
make[2]: Leaving directory `/home/tauber/LOFAR/MAC/APL/StsMisc/build/gnu_debug/src'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/tauber/LOFAR/MAC/APL/StsMisc/build/gnu_debug'
make: *** [all] Error 2
It would help a lot if somboddy knows any answer
thnx, Dorbeck
|
|
|
|
|
The above pgm will not work in linux. Because it uses many windows function, such as functions in winsocket.h. Those function are windows api. Linux will not be having such function.
dorbeck wrote: I thought that C++ worked the same under every platform
C++ works.. but not vc++
nave
|
|
|
|
|
There are differences.
I would solve them like this:
VS defines WIN32 by default.
So i you use
#ifdef WIN32
// Win32 code
#else
// Linux code
#endif
Then you can easily code for the differences.
Many of the errors here depends on the fact that 'byte' isn't defined in linux.
Try this:
#ifdef WIN32
#else
#define byte unsigned char
#endif
The you can go on with the rest of the differences/errors. It shouldn't be too hard IMO.
Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson
|
|
|
|
|
This helped a lot, I will try to do this on a few more errors. and some things i probebly have to solve by writing them down on a complete diferend way.
Thanx a lot
Dorbeck
|
|
|
|
|
Hi, I need to implement a checkbox control in Visual c++ that able/disable an other control.
Some one can hlp me please
|
|
|
|
|
Uuh ? And what's the problem ? Where are you stuck ? Why don't you simply drop a check box on your window with the resource editor ?
|
|
|
|
|
Hi,
To checkbox add BN_CLICKED handler. If GetCheck() == BST_CHECKED, checkbox is checked and EnableWindow disables or enables selected controls.
-----------
Mila
|
|
|
|
|
how can i get the address of a Clist Control and translate to another Class & using it
a beginner
|
|
|
|
|
So you have CList in a func, or in a header?
Just use the & operator to get the address, then cast that adress to another class.
You can store the address in any pointer or 4byte variable (on a 32 bit PC).
DWORD myaddress = (DWORD)&myListCtl;
((CWind*)myListCtl)->someCWindFunc();
Truth is the subjection of reality to an individuals perception
|
|
|
|
|
Hi,
Can somebody help me,how to fix the above the error ?
I am getting this error when i tried to build a vc6 project.
Thanks in advance.
Appu..
"If you judge people, you have no time to love them."
|
|
|
|
|
u need to install microsoft platform SDK to get this header file.
nave
|
|
|
|
|
Are you sure you have this file
|
|
|
|
|
Hi all,
I'm sorry this is the last silly question of the day
To disable tabstop i do
ModifyStyle(WS_TABSTOP,0,0);
What should i do to enable tabstop again ?
Thanx,
Desmo16.
|
|
|
|
|
ModifyStyle(0, WS_TABSTOP, 0);
it is this easy
|
|
|
|
|
Hi all
do you know a macro to understand during compiling if I'm using the Visual C++6.0 compiler or the latest Visual Studio.Net compilers instead of another compiler like TASKING or BORLAND CPP?
I need to make difference for them to use in some of my #ifdef #endif definitions.
Reagards
MAnu
|
|
|
|
|
Yes, you can use the _MSC_VER macro. Search it on this page[^] for more details.
|
|
|
|
|
Hi Cèdric
Many Thanks and have a nice day!
Manu
|
|
|
|
|
#if _MSC_VER <= 1200 // Visual C++ 6 or less
|
|
|
|
|
There is a message box window and I need to find it among the other Win windows, should bi FindWindow to search for its specfic "title" and then it has 2 buttons in it "Cancel" and "Ok" I need to send a message button_click to one of them.
How to find that message box window by its title, find the handles of the "Ok" and "Cancel" buttons and send a message to one of them? I dont remember all the windows API for this
9ine
|
|
|
|
|
HWND hwndParent = FindWindow(NULL, "title");
HWND hwndOK = FindWindowEx(hwndParent , NULL, NULL, "OK");
SendMessage(hwndOK, BM_CLICK , 0,0);
|
|
|
|
|
Or post/send message to hwndParent, WM_COMMAND, IDOK, or IDCANCEL.
Truth is the subjection of reality to an individuals perception
|
|
|
|
|
I have created a function display a dialog. When I try to show a previously selected window, it causes error. :(What seems to be the problem? Here’s my code:
void CProjectView::SetSelectedDialog(CDialog* dialog)
{
if(m_pSelectedDialog)
{ //Hide previously selected window
m_pSelectedDialog->ShowWindow(SW_HIDE);
}
if(dialog)
{ // show Selected Window
CRect rect;
GetClientRect( &rect );
m_pSelectedDialog = dialog;
m_pSelectedDialog->MoveWindow(rect, TRUE);
m_pSelectedDialog->ShowWindow(SW_SHOW);
}
}
|
|
|
|
|
romuzu wrote: it causes error
What error ? Be more specific.
|
|
|
|
|