I am making a DLL file for delphi applicaton in visual studio. I am following http://rvelthuis.de/articles/articles-cppobjs.html link to make the dll.My code is as follows
DLL_CLASS.h
#pragma once
using namespace std ;
#include "stdafx.h"
class DLL_CLASS
{
private:
public:
int TestValue;
char* getConnectedInverters (char* path);
char* getInverterParameters (int Device_Handle);
char* getInverter_SPOT_READINGS(int Device_Handle);
char* getPassword_varification();
char* get_Inverter_password();
char* get_Device_name(int Device_handle);
int get_Device_handel();
char* setAllInverterParameters(int Device_Handle,char* path_to_XML);
char* setYasdi_Reset_and_Shutdown();
char* get_Encryption(char* string_to_encrypt);
char* deviceXmlname();
char* RegExp(string Device_type);
int Get_inst_code_Channel(int Device_Handle);
char* set_One_InverterParameters(int Device_Handle,int Channel_handle,string Value);
DLL_CLASS();
virtual ~DLL_CLASS();
};
and other file code is as below
#include "stdafx.h"
#include "DLL_CLASS.h"
#include <tchar.h>
#include <windows.h>;
// define a macro for the calling convention and export type
#define EXPORTCALL __declspec(dllexport) __stdcall
typedef DLL_CLASS *ConsoleHandle;
extern "C"
{
ConsoleHandle EXPORTCALL NewConsole(void)
{
return new DLL_CLASS();
}
void EXPORTCALL DeleteConsole(ConsoleHandle handle)
{
delete handle;
}
char* EXPORTCALL NEW_getConnectedInverters(ConsoleHandle handle ,char* path)
{
handle->getConnectedInverters (path);
}
char* EXPORTCALL NEW_getInverterParameters (ConsoleHandle handle ,int Device_Handle)
{
handle->getInverterParameters(Device_Handle);
}
char* EXPORTCALL NEW_getInverter_SPOT_READINGS(ConsoleHandle handle,
int Device_Handle)
{
handle->getInverter_SPOT_READINGS(Device_Handle);
}
char* EXPORTCALL NEW_getPassword_varification(ConsoleHandle handle)
{
handle->getPassword_varification();
}
char* EXPORTCALL NEW_get_Inverter_password(ConsoleHandle handle)
{
handle->get_Inverter_password();
}
char* EXPORTCALL NEW_get_Device_name(ConsoleHandle handle,
int Device_handle)
{
handle->get_Device_name(Device_handle);
}
int EXPORTCALL NEW_get_Device_handel(ConsoleHandle handle)
{
return handle->get_Device_handel();
}
char* EXPORTCALL NEW_setAllInverterParameters(ConsoleHandle handle,int Device_Handle,char* path_to_XML)
{
return handle->setAllInverterParameters( Device_Handle, path_to_XML);
}
char* EXPORTCALL NEW_setYasdi_Reset_and_Shutdown(ConsoleHandle handle)
{
handle->setYasdi_Reset_and_Shutdown();
}
char* EXPORTCALL NEW_get_Encryption(ConsoleHandle handle,
char* string_to_encrypt)
{
handle->get_Encryption(string_to_encrypt);
}
char* EXPORTCALL NEW_deviceXmlname(ConsoleHandle handle)
{
handle->deviceXmlname();
}
char* EXPORTCALL RegExp(ConsoleHandle handle,
string Device_type)
{
handle->RegExp( Device_type);
}
char* EXPORTCALL NEW_set_One_InverterParameters(ConsoleHandle handle,
int Device_Handle,int Channel_handle,string Value)
{
handle->set_One_InverterParameters( Device_Handle,Channel_handle, Value);
}
int EXPORTCALL NEW_Get_inst_code_Channel(ConsoleHandle handle,
int Device_Handle)
{
handle->Get_inst_code_Channel(Device_Handle);
}
} // extern "C"
#pragma argsused
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
{
return 1;
}
But this Give me error as below
1>------ Build started: Project: inverter_library, Configuration: Release Win32 ------
1> flatten.cpp
1>flatten.cpp(5): warning C4067: unexpected tokens following preprocessor directive - expected a newline
1>flatten.cpp(26): error C2059: syntax error : '__declspec(dllexport)'
1>flatten.cpp(27): error C2143: syntax error : missing ';' before '{'
1>flatten.cpp(27): error C2447: '{' : missing function header (old-style formal list?)
1>flatten.cpp(31): error C2059: syntax error : '__declspec(dllexport)'
1>flatten.cpp(32): error C2143: syntax error : missing ';' before '{'
1>flatten.cpp(32): error C2447: '{' : missing function header (old-style formal list?)
1>flatten.cpp(36): error C2059: syntax error : '__declspec(dllexport)'
1>flatten.cpp(38): error C2143: syntax error : missing ';' before '{'
1>flatten.cpp(38): error C2447: '{' : missing function header (old-style formal list?)
1>flatten.cpp(42): error C2059: syntax error : '__declspec(dllexport)'
1>flatten.cpp(43): error C2143: syntax error : missing ';' before '{'
1>flatten.cpp(43): error C2447: '{' : missing function header (old-style formal list?)
1>flatten.cpp(47): error C2059: syntax error : '__declspec(dllexport)'
1>flatten.cpp(48): error C2143: syntax error : missing ';' before '{'
1>flatten.cpp(48): error C2447: '{' : missing function header (old-style formal list?)
1>flatten.cpp(52): error C2059: syntax error : '__declspec(dllexport)'
1>flatten.cpp(54): error C2143: syntax error : missing ';' before '{'
1>flatten.cpp(54): error C2447: '{' : missing function header (old-style formal list?)
1>flatten.cpp(63): error C2059: syntax error : '__declspec(dllexport)'
1>flatten.cpp(64): error C2143: syntax error : missing ';' before '{'
1>flatten.cpp(64): error C2447: '{' : missing function header (old-style formal list?)
1>flatten.cpp(68): error C2059: syntax error : '__declspec(dllexport)'
1>flatten.cpp(69): error C2143: syntax error : missing ';' before '{'
1>flatten.cpp(69): error C2447: '{' : missing function header (old-style formal list?)
1>flatten.cpp(73): error C2059: syntax error : '__declspec(dllexport)'
1>flatten.cpp(75): error C2143: syntax error : missing ';' before '{'
1>flatten.cpp(75): error C2447: '{' : missing function header (old-style formal list?)
1>flatten.cpp(78): error C2059: syntax error : '__declspec(dllexport)'
1>flatten.cpp(79): error C2143: syntax error : missing ';' before '{'
1>flatten.cpp(79): error C2447: '{' : missing function header (old-style formal list?)
1>flatten.cpp(82): error C2059: syntax error : '__declspec(dllexport)'
1>flatten.cpp(84): error C2143: syntax error : missing ';' before '{'
1>flatten.cpp(84): error C2447: '{' : missing function header (old-style formal list?)
1>flatten.cpp(87): error C2059: syntax error : '__declspec(dllexport)'
1>flatten.cpp(89): error C2143: syntax error : missing ';' before '{'
1>flatten.cpp(89): error C2447: '{' : missing function header (old-style formal list?)
1>flatten.cpp(99): warning C4068: unknown pragma
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Can anyone suggest me Why this error is coming
I tried to find the solution but I could not find it....
You need to place the __declspec(dllexport) before the return value, and the __stdcall after the return value. For example:
__declspec(dllexport) int __stdcall foo(...)
Your macro places them together, after the function return value. Hence the syntax error. So if you want both in a single macro, you need a parameterized macro that takes the return type as a parameter.
It's simpler and clear to be explicit and skip the macros and write it out longhand, in my view. I suggest that you shun macros unless they give significant benefit in comparison to non-macro alternatives. In this case I see no such benefit.
Note that some of your flattening functions are missing return statements. And you also need to be clear on the lifetime of the char* pointers that you return. I trust you are already on top of that.
Related
I'm trying to create a wrapper class for a C# dll and am coming across a compiler error in my definition. I've tried finding a solution and reading MSDN help but so far nothing works.
Error 2 error C2059: syntax error : 'public' 7
Error 3 error C2143: syntax error : missing ';' before '{' 8
Error 4 error C2447: '{' : missing function header (old-style formal list?) 8
Error 5 error C2059: syntax error : 'public' 7
Error 6 error C2143: syntax error : missing ';' before '{' 8
Error 7 error C2447: '{' : missing function header (old-style formal list?) 8
ASComms.h
#pragma once
#include "IPADDRESS.h"
namespace DataComms
{
public ref class CASComms
{
public:
void Connect(IPADDRESS ipaddr);
void Write(const char* plcTAG, const char* data);
private:
AutomatedSolutions::Win::Comm::AB::Logix::Net::Channel ^m_channel;
AutomatedSolutions::Win::Comm::AB::Logix::Device ^m_device;
AutomatedSolutions::Win::Comm::AB::Logix::Group ^m_group;
AutomatedSolutions::Win::Comm::AB::Logix::Item ^m_item;
};
}
ASComms.cpp
#include "stdafx.h"
#include "ASComms.h"
#include "IPADDRESS.h"
using namespace AutomatedSolutions::Win::Comm::AB::Logix;
void DataComms::CASComms::Connect(IPADDRESS ipaddr)
{
// do stuff
}
void DataComms::CASComms::Write(const char* plcTAG, const char* data)
{
// do stuff
}
Quite a while back I was playing around with C code for a POS device. I could develop and build in Visual Studio 2008. Then to test I could go into cygwin, make the code and load onto the device, or use the included simulator. Somewhere along the lines that virtual box was lost.
I want to start up again in dabbling with this device but am having an awful time trying to get the code to build in Visual Studio 2008 C++ Express.
I created a new project from existing code, set it to compile as C code and tried to build. It complained that it could not find system.h, so I added the directory in the include directories under tools.
Now it gives 408 errors. Example as shown below:
------ Build started: Project: TestHelloWorld, Configuration: Debug Win32 ------
Compiling...
sysutil.c
c:\cygwin\home\creon_sdk_v2.3\program\lib\system.h(105) : error C2054: expected '(' to follow '__pcs'
c:\cygwin\home\creon_sdk_v2.3\program\lib\system.h(105) : error C2085: 'disable_interrupt' : not in formal parameter list
c:\cygwin\home\creon_sdk_v2.3\program\lib\system.h(106) : error C2082: redefinition of formal parameter '__pcs'
c:\cygwin\home\creon_sdk_v2.3\program\lib\system.h(106) : error C2143: syntax error : missing ';' before 'type'
c:\cygwin\home\creon_sdk_v2.3\program\lib\system.h(106) : error C2085: 'enable_interrupt' : not in formal parameter list
c:\cygwin\home\creon_sdk_v2.3\program\lib\system.h(107) : error C2085: 'call_app_func' : not in formal parameter list
c:\cygwin\home\creon_sdk_v2.3\program\lib\system.h(108) : error C2082: redefinition of formal parameter '__pcs'
c:\cygwin\home\creon_sdk_v2.3\program\lib\system.h(108) : error C2146: syntax error : missing ',' before identifier 'DWORD'
c:\cygwin\home\creon_sdk_v2.3\program\lib\system.h(108) : error C2146: syntax error : missing ',' before identifier 'os_switch_app'
c:\cygwin\home\creon_sdk_v2.3\program\lib\system.h(108) : error C2143: syntax error : missing ';' before '('
c:\cygwin\home\creon_sdk_v2.3\program\lib\system.h(108) : error C2059: syntax error : ')'
c:\cygwin\home\creon_sdk_v2.3\program\lib\system.h(109) : error C2054: expected '(' to follow '__pcs'
c:\cygwin\home\creon_sdk_v2.3\program\lib\system.h(109) : error C2085: 'app5_call' : not in formal parameter list
c:\cygwin\home\creon_sdk_v2.3\program\lib\system.h(110) : error C2082: redefinition of formal parameter '__pcs'
c:\cygwin\home\creon_sdk_v2.3\program\lib\system.h(110) : error C2146: syntax error : missing ',' before identifier 'DWORD'
c:\cygwin\home\creon_sdk_v2.3\program\lib\system.h(110) : error C2146: syntax error : missing ',' before identifier 'app6_call'
c:\cygwin\home\creon_sdk_v2.3\program\lib\system.h(110) : error C2143: syntax error : missing ';' before '('
c:\cygwin\home\creon_sdk_v2.3\program\lib\system.h(110) : error C2059: syntax error : ')'
c:\cygwin\home\creon_sdk_v2.3\program\lib\system.h(111) : error C2054: expected '(' to follow '__pcs'
c:\cygwin\home\creon_sdk_v2.3\program\lib\system.h(111) : error C2085: 'app7_call' : not in formal parameter list
c:\cygwin\home\creon_sdk_v2.3\program\lib\system.h(112) : error C2082: redefinition of formal parameter '__pcs'
c:\cygwin\home\creon_sdk_v2.3\program\lib\system.h(112) : error C2146: syntax error : missing ',' before identifier 'DWORD'
c:\cygwin\home\creon_sdk_v2.3\program\lib\system.h(112) : error C2146: syntax error : missing ',' before identifier 'app8_call'
c:\cygwin\home\creon_sdk_v2.3\program\lib\system.h(112) : error C2143: syntax error : missing ';' before '('
c:\cygwin\home\creon_sdk_v2.3\program\lib\system.h(112) : error C2059: syntax error : ')'
c:\cygwin\home\creon_sdk_v2.3\program\lib\system.h(113) : error C2054: expected '(' to follow '__pcs'
c:\cygwin\home\creon_sdk_v2.3\program\lib\system.h(113) : error C2085: 'app9_call' : not in formal parameter list
c:\cygwin\home\creon_sdk_v2.3\program\lib\system.h(114) : error C2082: redefinition of formal parameter '__pcs'
c:\cygwin\home\creon_sdk_v2.3\program\lib\system.h(114) : error C2146: syntax error : missing ',' before identifier 'DWORD'
c:\cygwin\home\creon_sdk_v2.3\program\lib\system.h(114) : error C2146: syntax error : missing ',' before identifier 'app10_call'
c:\cygwin\home\creon_sdk_v2.3\program\lib\system.h(114) : error C2143: syntax error : missing ';' before '('
c:\cygwin\home\creon_sdk_v2.3\program\lib\system.h(114) : error C2059: syntax error : ')'
Does anybody have any idea how I can get this working.
The code is from the sample code that comes with the SDK for the device.
Also the SDK comes with cygwin which is installed and I can make the sample program no problem, however I am more of a C# developer and so like my IDE. I had this working before but cannot remember how I got it working before.
Please, any suggestions would be appreciated.
Kind regards,
Neill
Edit - As request line 101 - 115 from system.h
#ifndef _SYSTEM_H_
#define _SYSTEM_H_
#include "common.h"
extern __pcs void disable_interrupt();
extern __pcs void enable_interrupt();
extern DWORD call_app_func(void * ptr,DWORD param1,DWORD param2,DWORD param3);
extern __pcs DWORD os_switch_app(BYTE app_id,DWORD param1,DWORD param2,DWORD param3);
extern __pcs DWORD app5_call(DWORD func_no,DWORD param1,DWORD param2, DWORD param3);
extern __pcs DWORD app6_call(DWORD func_no,DWORD param1,DWORD param2, DWORD param3);
extern __pcs DWORD app7_call(DWORD func_no,DWORD param1,DWORD param2, DWORD param3);
extern __pcs DWORD app8_call(DWORD func_no,DWORD param1,DWORD param2, DWORD param3);
extern __pcs DWORD app9_call(DWORD func_no,DWORD param1,DWORD param2, DWORD param3);
extern __pcs DWORD app10_call(DWORD func_no,DWORD param1,DWORD param2, DWORD param3);
Thanks!
This particular compiler error message of the form of error C2054: expected '(' to follow '__pcs' indicates that the compile is attempting to decode the line of source as if __pcs is the beginning of a function name and it is expecting parenthesis to follow the identifier because it is expecting a function parameter list.
Whenever I have seen this it is because there is a define missing which will define __pcs to some function behavior modifier. For instance in Windows you may have something that will specify the calling sequence (C standard versus Pascal) or another one will be for DLL linkage.
I suggest you do a search through your header files looking for a define for __pcs to see where it might be defined.
It really looks like there is some kind of a -D compiler directive to define __pcs or a header file that needs to be included to define __pcs.
Here is a sample header file include dependency graph for a Cygwin application that might be helpful.
I have some errors in my header file, which I don't know how to fix because I am fairly new to C++.
Here is the code of the header file:
#pragma once
typedef unsigned int uint;
class DCEncryption
{
public:
static char* manageData(char*, char*, uint);
private:
static int max(int, int);
static uint leftRotate(uint, int);
};
And here are the errors:
- dcencryption.h(12): error C2062: type 'int' unexpected
- dcencryption.h(12): error C2334: unexpected token(s) preceding ':'; skipping apparent function body
- dcencryption.h(12): error C2760: syntax error : expected '{' not ';'
- dcencryption.h(13): error C2144: syntax error : 'uint' should be preceded by '}'
- dcencryption.h(13): error C2143: syntax error : missing ')' before ';'
- dcencryption.h(13): error C2059: syntax error : ')'
- dcencryption.h(13): error C2143: syntax error : missing ';' before ')'
- dcencryption.h(13): error C2238: unexpected token(s) preceding ';'
You are probably on Windows and you have included windef.h directly or indirectly (through windows.h, maybe) from your main .cpp file before including the shown file.
It so happens that max is a macro defined in windef.h that does not expand nicely in your context.
This can quite easily happen on some other platforms as well.
I want to create an async. server.
i succeed to do that, but now i want to bind async_read/asyn_write functions to caller object function. So i tried to do that with boost::function
here you have my code :
Server.cpp
#include "Server.h"
#include "Client.h"
#include "Network.h"
void Server::accept(void)
{
Network::ptr connection = Network::create(this->my_acceptor.get_io_service());
this->my_acceptor.async_accept(connection->getSocket(), bind(&Server::endCmd, this, connection, placeholders::error));
}
void Server::endCmd(Network::ptr connection, const boost::system::error_code& error)
{
if (!error)
{
std::cout << "Recu un client!" << std::endl;
this->client.push_back(new Client(connection));
this->client[client.size() - 1]->checkAuthentification();
std::cout << "Envoie du message de securisation" << std::endl;
std::cout << "Nouvelle ecoute" << std::endl;
this->accept();
}
}
Client.h and .cpp
#include "Network.h"
class Client
{
private:
Network::ptr connection;
public:
Client(Network::ptr);
~Client();
void checkAuthentification(void);
void endRead(const error_code& error, size_t nbytes);
void endWrite(const error_code &error);
};
#include "Client.h"
Client::Client(Network::ptr connect)
{
this->connection = connect;
this->connection->assignFunction(this);
}
Client::~Client()
{
this->connection->close();
}
void Client::checkAuthentification(void)
{
this->connection->Swrite("BIENVENUE", this);
}
void Client::endRead(const error_code& error, size_t nbytes)
{
if (!error && nbytes != 0)
{
std::cout << this->connection->getRcvMsg() << std::endl;
this->connection->Sread(this);
}
else
this->connection->close();
}
void Client::endWrite(const error_code &error)
{
if (!error)
this->connection->Sread(this);
else
this->connection->close();
}
and Network.cpp and .h
#include "Client.h"
class Network : public boost::enable_shared_from_this<Network>
{
private:
tcp::socket socket;
std::string rcv_msg;
std::string msg;
boost::array<char, 6> rbuffer;
boost::function<void (Client *, const error_code &, size_t)> fread;
boost::function<void (Client *, const error_code &)> fwrite;
public:
typedef boost::shared_ptr<Network> ptr;
Network(io_service &);
~Network();
void assignFunction(void);
void close(void);
void Sread(Client *cli);
void Swrite(std::string msg, Client *cli);
tcp::socket& getSocket(void);
std::string getRcvMsg(void);
static ptr create(io_service &);
};
#include "Client.h"
#include "Network.h"
Network::Network(io_service &ios) : socket(ios)
{
}
Network::~Network()
{
this->close();
}
void Network::assignFunction(void)
{
this->fread = &Client::endRead;
this->fwrite = &Client::endWrite;
}
void Network::close(void)
{
if (this->socket.is_open())
{
std::cout << "Connection closed" << std::endl;
this->socket.close();
}
}
void Network::Sread(Client *cli)
{
async_read(this->socket, buffer(this->rbuffer), bind(&Network::fread, cli, placeholders::error, placeholders::bytes_transferred));
}
void Network::Swrite(std::string msg, Client *cli)
{
this->msg = msg;
async_write(this->socket, buffer(this->msg, (int)this->msg.size()), bind(&Network::fwrite, cli, placeholders::error));
}
std::string Network::getRcvMsg(void)
{
return (std::string(this->rbuffer.c_array(), this->rbuffer.size()));
}
tcp::socket& Network::getSocket(void)
{
return (this->socket);
}
Network::ptr Network::create(io_service &ios)
{
return (ptr(new Network(ios)));
}
When i want to compile that, i have the following errors :
Client.h(10): error C2653: 'Network' : is not a class or namespace name
Client.h(10): error C2146: syntax error : missing ';' before identifier 'connection'
Client.h(10): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Client.h(10): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Client.h(13): error C2653: 'Network' : is not a class or namespace name
Client.h(13): error C2653: 'Network' : is not a class or namespace name
Client.h(13): error C2460: 'Client::ptr' : uses 'Client', which is being defined
Client.h(8) : see declaration of 'Client'
1>Client.cpp(6): error C2511: 'Client::Client(Network::ptr)' : overloaded member function not found in 'Client'
Client.h(8) : see declaration of 'Client'
1>Client.cpp(13): error C2039: 'connection' : is not a member of 'Client'
Client.h(8) : see declaration of 'Client'
1>Client.cpp(13): error C2227: left of '->close' must point to class/struct/union/generic type
1>Client.cpp(18): error C2039: 'connection' : is not a member of 'Client'
Client.h(8) : see declaration of 'Client'
1>Client.cpp(18): error C2227: left of '->Swrite' must point to class/struct/union/generic type
1>Client.cpp(25): error C2039: 'connection' : is not a member of 'Client'
Client.h(8) : see declaration of 'Client'
1>Client.cpp(25): error C2227: left of '->getRcvMsg' must point to class/struct/union/generic type
1>Client.cpp(26): error C2039: 'connection' : is not a member of 'Client'
Client.h(8) : see declaration of 'Client'
1>Client.cpp(26): error C2227: left of '->Sread' must point to class/struct/union/generic type
1>Client.cpp(29): error C2039: 'connection' : is not a member of 'Client'
Client.h(8) : see declaration of 'Client'
1>Client.cpp(29): error C2227: left of '->close' must point to class/struct/union/generic type
1>Client.cpp(35): error C2039: 'connection' : is not a member of 'Client'
Client.h(8) : see declaration of 'Client'
1>Client.cpp(35): error C2227: left of '->Sread' must point to class/struct/union/generic type
1>Client.cpp(37): error C2039: 'connection' : is not a member of 'Client'
Client.h(8) : see declaration of 'Client'
1>Client.cpp(37): error C2227: left of '->close' must point to class/struct/union/generic type
Commande.cpp
main.cpp
Client.h(10): error C2653: 'Network' : is not a class or namespace name
Client.h(10): error C2146: syntax error : missing ';' before identifier 'connection'
Client.h(10): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Client.h(10): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Client.h(13): error C2653: 'Network' : is not a class or namespace name
Client.h(13): error C2653: 'Network' : is not a class or namespace name
Client.h(13): error C2460: 'Client::ptr' : uses 'Client', which is being defined
Client.h(8) : see declaration of 'Client'
My_exception.cpp
Network.cpp
Network.h(14): error C2065: 'Client' : undeclared identifier
Network.h(14): error C2059: syntax error : ','
Network.h(15): error C2065: 'Client' : undeclared identifier
Network.h(15): error C2059: syntax error : ','
Network.h(25): error C2065: 'Client' : undeclared identifier
Network.h(25): error C2065: 'cli' : undeclared identifier
Network.h(25): error C2143: syntax error : missing ',' before ')'
Network.h(29): error C2143: syntax error : missing ';' before '}'
Client.h(8): error C2143: syntax error : missing ';' before '{'
Client.h(18): error C2143: syntax error : missing ';' before '}'
1>Network.cpp(6): error C2143: syntax error : missing ';' before '{'
1>Network.cpp(7): error C2143: syntax error : missing ';' before '}'
1>Network.cpp(10): error C2143: syntax error : missing ';' before '{'
1>Network.cpp(12): error C2143: syntax error : missing ';' before '}'
1>Network.cpp(15): error C2143: syntax error : missing ';' before '{'
1>Network.cpp(16): error C2653: 'Client' : is not a class or namespace name
1>Network.cpp(17): error C2653: 'Client' : is not a class or namespace name
1>Network.cpp(18): error C2143: syntax error : missing ';' before '}'
1>Network.cpp(21): error C2143: syntax error : missing ';' before '{'
1>Network.cpp(23): error C2143: syntax error : missing ';' before '{'
1>Network.cpp(26): error C2143: syntax error : missing ';' before '}'
1>Network.cpp(27): error C2143: syntax error : missing ';' before '}'
1>Network.cpp(30): error C2143: syntax error : missing ';' before '{'
1>Network.cpp(31): error C2355: 'this' : can only be referenced inside non-static member functions
1>Network.cpp(31): error C2227: left of '->rbuffer' must point to class/struct/union/generic type
1>Network.cpp(31): error C2065: 'cli' : undeclared identifier
1>Network.cpp(31): error C2143: syntax error : missing ',' before ')'
1>Network.cpp(32): error C2143: syntax error : missing ';' before '}'
1>Network.cpp(35): error C2065: 'Client' : undeclared identifier
1>Network.cpp(35): error C2065: 'cli' : undeclared identifier
1>Network.cpp(35): error C2143: syntax error : missing ',' before ')'
1>Network.cpp(36): error C2143: syntax error : missing ';' before '{'
1>Network.cpp(38): error C2355: 'this' : can only be referenced inside non-static member functions
1>Network.cpp(38): error C2227: left of '->msg' must point to class/struct/union/generic type
1>Network.cpp(38): error C2355: 'this' : can only be referenced inside non-static member functions
1>Network.cpp(38): error C2227: left of '->msg' must point to class/struct/union/generic type
1>Network.cpp(38): error C2228: left of '.size' must have class/struct/union
1>Network.cpp(38): error C2065: 'cli' : undeclared identifier
1>Network.cpp(38): error C2143: syntax error : missing ',' before ')'
1>Network.cpp(39): error C2143: syntax error : missing ';' before '}'
1>Network.cpp(42): error C2143: syntax error : missing ';' before '{'
1>Network.cpp(43): error C2355: 'this' : can only be referenced inside non-static member functions
1>Network.cpp(43): error C2227: left of '->rbuffer' must point to class/struct/union/generic type
1>Network.cpp(43): error C2228: left of '.size' must have class/struct/union
1>Network.cpp(43): error C2143: syntax error : missing ',' before ')'
1>Network.cpp(44): error C2143: syntax error : missing ';' before '}'
1>Network.cpp(47): error C2143: syntax error : missing ';' before '{'
1>Network.cpp(49): error C2143: syntax error : missing ';' before '}'
1>Network.cpp(52): error C2143: syntax error : missing ';' before '{'
1>Network.cpp(54): error C2143: syntax error : missing ';' before '}'
1>Network.cpp(55): error C2143: syntax error : missing ';' before '}'
1>Network.cpp(55): fatal error C1004: unexpected end-of-file found
Server.cpp
Client.h(10): error C2653: 'Network' : is not a class or namespace name
Client.h(10): error C2146: syntax error : missing ';' before identifier 'connection'
Client.h(10): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Client.h(10): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Client.h(13): error C2653: 'Network' : is not a class or namespace name
Client.h(13): error C2653: 'Network' : is not a class or namespace name
Client.h(13): error C2460: 'Client::ptr' : uses 'Client', which is being defined
Client.h(8) : see declaration of 'Client'
1>Server.cpp(22): error C2664: 'Client::Client(const Client &)' : cannot convert parameter 1 from 'Network::ptr' to 'const Client &'
Reason: cannot convert from 'Network::ptr' to 'const Client'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
After so many hours of "googlings" and reflexion, i didn't found why i have these errors.
Anyone can help me plz ?
Mmm.. Maybe you have left them out but you failed to include the headers:
Edit That seems to obvious. If it's not that then
Edit 2 Note that these suggestions have been typed when full information about the include structure wasn't given. The problems has been resolved now, but these hints are good general troubleshooting advice whenever strange issues arise with the compiler not 'seeing' your declarations:
check precompiled header settings (disable them, e.g.)
check you header include guards (if they are incorrect, e.g.
#ifndef __NETWORK_H
#define __NETWORK_H
...
#endif // __NETWORK_H
in your Client.h...
check namespace issues
accidentally declared Network in a namespace
included Network.h from within a namespace { ... } block
check preprocessor issues (#defines wreaking havoc?)
Server.cpp
include "Network.h"
include "Server.h"
//....
Client.cpp
include "Network.h"
include "Server.h"
Network.cpp
include "Network.h"
And probably (form looking at the errors):
Client.h
include "Network.h"
too
In Network.h, do not include Client.h, but instead forward declare class Client.
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 11 years ago.
Im writing a project in C with visual studio that contains these files:
multiThreadServer.cpp
myLib.cpp
myLib.h
The 1st (multiThreadServer.cpp) includes these
#include <WinSock2.h>
#include <Windows.h>
#include <stdio.h>
#include "myLib.h"
2nd (myLib.cpp) these
#include <WinSock2.h>
#include <stdio.h>
#include "myLib.h"
3nd (myLib.h) includes nothing
In .h file i have these functions defined:
// Starts up the server.
INT start_server(const unsigned short port);
// Accept Connections.
BOOL accept_connections();
// Accept Client.
BOOL AcceptClient(PCLIENT current_client);
// Receiver Function for the thread.
DWORD WINAPI Receiver(LPVOID lpParam);
// Receive data from client.
BOOL recv_data(PCLIENT current_client, char *buffer, int size);
// End server.
VOID end_server();
// Send data.
BOOL send_data(PCLIENT current_client, char *buffer, int size);
// Disconnect Client.
VOID disconnect_client(PCLIENT current_client);
// Send Data to all clients.
BOOL send_data_to_all(char *message);
Here is part of myLib.cpp:
typedef struct _client{
SOCKADDR_IN address; // internal data structure regarding this client
SOCKET socket; // this clients socket
BOOL connected; // is this client connected
char IP[20]; // this clients IP address
int address_length; // internal data structure regarding this client
} CLIENT, *PCLIENT;
Now, when im going to compile the whole project these annoying syntax errors returned:
1> myLib.cpp
\mylib.h(8): error C2146: syntax error : missing ')' before identifier 'current_client'
\mylib.h(8): error C2061: syntax error : identifier 'current_client'
\mylib.h(8): error C2059: syntax error : ';'
\mylib.h(8): error C2059: syntax error : ')'
\mylib.h(14): error C2146: syntax error : missing ')' before identifier 'current_client'
\mylib.h(14): error C2061: syntax error : identifier 'current_client'
\mylib.h(14): error C2059: syntax error : ';'
\mylib.h(14): error C2059: syntax error : ','
\mylib.h(14): error C2059: syntax error : ')'
\mylib.h(20): error C2146: syntax error : missing ')' before identifier 'current_client'
\mylib.h(20): error C2061: syntax error : identifier 'current_client'
\mylib.h(20): error C2059: syntax error : ';'
\mylib.h(20): error C2059: syntax error : ','
\mylib.h(20): error C2059: syntax error : ')'
\mylib.h(23): error C2146: syntax error : missing ')' before identifier 'current_client'
\mylib.h(23): error C2061: syntax error : identifier 'current_client'
\mylib.h(23): error C2059: syntax error : ';'
\mylib.h(23): error C2059: syntax error : ')'
\mylib.cpp(103): warning C4013: 'AcceptClient' undefined; assuming extern returning int
\mylib.cpp(168): warning C4013: 'recv_data' undefined; assuming extern returning int
\mylib.cpp(188): warning C4013: 'send_data' undefined; assuming extern returning int
\mylib.cpp(189): warning C4013: 'disconnect_client' undefined; assuming extern returning int
\mylib.cpp(270): error C2371: 'disconnect_client' : redefinition; different basic types
1> multiThreadServer.cpp
\mylib.h(8): error C2146: syntax error : missing ')' before identifier 'current_client'
1\mylib.h(8): error C2061: syntax error : identifier 'current_client'
\mylib.h(8): error C2059: syntax error : ';'
\mylib.h(8): error C2059: syntax error : ')'
\mylib.h(14): error C2146: syntax error : missing ')' before identifier 'current_client'
\mylib.h(14): error C2061: syntax error : identifier 'current_client'
\mylib.h(14): error C2059: syntax error : ';'
\mylib.h(14): error C2059: syntax error : ','
\mylib.h(14): error C2059: syntax error : ')'
\mylib.h(20): error C2146: syntax error : missing ')' before identifier 'current_client'
\mylib.h(20): error C2061: syntax error : identifier 'current_client'
\mylib.h(20): error C2059: syntax error : ';'
\mylib.h(20): error C2059: syntax error : ','
\mylib.h(20): error C2059: syntax error : ')'
\mylib.h(23): error C2146: syntax error : missing ')' before identifier 'current_client'
\mylib.h(23): error C2061: syntax error : identifier 'current_client'
\mylib.h(23): error C2059: syntax error : ';'
\mylib.h(23): error C2059: syntax error : ')'
I m searching 1.30 hour now on net but i cannot find a way to fix it.
What the problem could be ?
Alternatively to what's suggested here, you fix the problem in the header file without actually moving the definition of PCLIENT into the header:
...
struct _client;
...
// Accept Client.
BOOL AcceptClient(struct _client* current_client);
...
// Receive data from client.
BOOL recv_data(struct _client* current_client, char *buffer, int size);
...
// Send data.
BOOL send_data(struct _client* current_client, char *buffer, int size);
// Disconnect Client.
VOID disconnect_client(struct _client* current_client);
...