Avatar of GCartopel
GCartopel
 asked on

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

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.

Microsoft Legacy OSC

Avatar of undefined
Last Comment
GCartopel

8/22/2022 - Mon
GCartopel

ASKER
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
masheik

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

ASKER
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)
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
ASKER CERTIFIED SOLUTION
masheik

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
GCartopel

ASKER
GREAT!!!

It was worked...

Thanks a lot.