error C2733: second C linkage of overloaded function 'Imprime' not allowed

GCartopel
GCartopel used Ask the Experts™
on
Hi,

Im building a dll with MVC++ 6.0, however when I build the project I got the next message:

--------------------Configuration: TcpDll - Win32 Debug--------------------
Compiling...
TcpDll.cpp
C:\Program Files\Microsoft Visual Studio\MyProjects\TcpDll\TcpDll.cpp(78) : error C2733: second C linkage of overloaded function 'Imprime' not allowed
        C:\Program Files\Microsoft Visual Studio\MyProjects\TcpDll\TcpDll.cpp(77) : see declaration of 'Imprime'
Error executing cl.exe.

TcpDll.dll - 1 error(s), 0 warning(s)
-----------------------------------------------------------------------------------------


The code is the next:

TcpDll.cpp:
-----------------
// TcpDll.cpp : Defines the initialization routines for the DLL.
#include "stdafx.h"
#include "TcpDll.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
BEGIN_MESSAGE_MAP(CTcpDllApp, CWinApp)
END_MESSAGE_MAP()
CTcpDllApp::CTcpDllApp()
{
      
}
CTcpDllApp theApp;

extern "C"
int WINAPI Imprime(char IP[14], char BUFFER[8])
{
      int RESULTADO;
      WSADATA data;
      SOCKET sock;
      struct linger Linger;
      struct sockaddr_in addr;
      /* Initialize windows socket */
      WSAStartup(0x0101, &data);
      /* Create socket */
      if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET) {
            fprintf(stderr, "Error socket(): %d\n", WSAGetLastError());
            exit(1);
      }
      /* Set connection timeout */
      Linger.l_onoff = 1;
      Linger.l_linger = 60;
      setsockopt(sock, SOL_SOCKET, SO_LINGER, (char*)&Linger, sizeof(struct linger));
      /* initialize the parameter */
      memset(&addr, 0, sizeof(addr));
      addr.sin_family = AF_INET;
      addr.sin_port = htons(9100);
      addr.sin_addr.s_addr = inet_addr(IP);
      /* connect */
      if (connect(sock, (struct sockaddr*)&addr, sizeof(addr)) < 0) {
            fprintf(stderr, "Error connect(): %d\n", WSAGetLastError());
            exit(1);
      }
      /* send data */
      send(sock, BUFFER, 8, 0);
      /* gracefully close */
      shutdown(sock, 1);/* SD_SEND */
      while (1) {
      char buf[64];
      int n = recv(sock, buf, 64, 0);
      if (n = SOCKET_ERROR || n == 0)
      break;
      } shutdown(sock, 2);/* SD_BOTH */
      /* close socket */
      closesocket(sock);
      return (RESULTADO);
};

TcpDll.def:
-----------------
; TcpDll.def : Declares the module parameters for the DLL.
LIBRARY      "TcpDll"
DESCRIPTION  'TcpDll Windows Dynamic Link Library'
EXPORTS
    Imprime

TcpDll.h:
-----------------
// TcpDll.h : main header file for the TCPDLL DLL
#if !defined(AFX_TCPDLL_H__218CC154_9176_4972_A4B2_451D6DC15936__INCLUDED_)
#define AFX_TCPDLL_H__218CC154_9176_4972_A4B2_451D6DC15936__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#ifndef __AFXWIN_H__
      #error include 'stdafx.h' before including this file for PCH
#endif
#include "resource.h"            // main symbols
      #include "stdio.h"
      #include "winsock.h"
class CTcpDllApp : public CWinApp
{
public:
      CTcpDllApp();
      DECLARE_MESSAGE_MAP()
};
#ifdef __cplusplus
extern "C" {
#endif
int Imprime(char, char);
#ifdef __cplusplus
}
#endif
#endif


I test the code, building an .exe file before and the app works very well.

Please your support.

Regards.

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Author

Commented:
I'm sorry, but the correct TcpDll.h code is:
-----------------------------------------------------------

// TcpDll.h : main header file for the TCPDLL DLL
#if !defined(AFX_TCPDLL_H__218CC154_9176_4972_A4B2_451D6DC15936__INCLUDED_)
#define AFX_TCPDLL_H__218CC154_9176_4972_A4B2_451D6DC15936__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#ifndef __AFXWIN_H__
      #error include 'stdafx.h' before including this file for PCH
#endif
#include "resource.h"            // main symbols
      #include "stdio.h"
      #include "winsock.h"
class CTcpDllApp : public CWinApp
{
public:
      CTcpDllApp();
      DECLARE_MESSAGE_MAP()
};
#ifdef __cplusplus
extern "C" {
#endif
int WINAPI Imprime(char, char);
#ifdef __cplusplus
}
#endif
#endif
masheikSoftware Engineer

Commented:
Hi,
   Try changing the API name in the .H file from int WINAPI Imprime(char, char); to int WINAPI Imprime(char *ip, char *buffer);

Author

Commented:
I changed the .H file from int WINAPI Imprime(char, char); to int WINAPI Imprime(char *ip, char *buffer); but I got the next error message:

--------------------Configuration: TcpDll - Win32 Debug--------------------
Compiling...
TcpDll.cpp
C:\Program Files\Microsoft Visual Studio\MyProjects\TcpDll\TcpDll.cpp(71) : warning C4700: local variable 'RESULTADO' used without having been initialized
Linking...
   Creating library Debug/TcpDll.lib and object Debug/TcpDll.exp
TcpDll.obj : error LNK2001: unresolved external symbol _closesocket@4
TcpDll.obj : error LNK2001: unresolved external symbol _recv@16
TcpDll.obj : error LNK2001: unresolved external symbol _shutdown@8
TcpDll.obj : error LNK2001: unresolved external symbol _send@16
TcpDll.obj : error LNK2001: unresolved external symbol _connect@12
TcpDll.obj : error LNK2001: unresolved external symbol _inet_addr@4
TcpDll.obj : error LNK2001: unresolved external symbol _htons@4
TcpDll.obj : error LNK2001: unresolved external symbol _setsockopt@20
TcpDll.obj : error LNK2001: unresolved external symbol _WSAGetLastError@0
TcpDll.obj : error LNK2001: unresolved external symbol _socket@12
TcpDll.obj : error LNK2001: unresolved external symbol _WSAStartup@8
Debug/TcpDll.dll : fatal error LNK1120: 11 unresolved externals
Error executing link.exe.

TcpDll.dll - 12 error(s), 1 warning(s)
Software Engineer
Commented:
Okay, you did not add the win32 socket lib in the project

  To fix this problem add all the linker libraries in to the visual studio project solution properly,
 Project ->Right click-->Properties-->Linker --> input --> Additional include directories --> ws2_32.lib
eevs9.jpg

Author

Commented:
GREAT!!!

It was worked...

Thanks a lot.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial