@
C# code
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace ConsoleApplication1
{
public static class Test
{
[DllImport("qtcpdll.dll", EntryPoint="start", CallingConvention=CallingConvention.Cdecl)]
public extern static int start();
}
}
///////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int res = Test.start();
Console.WriteLine(res);
Console.Read();
}
}
}
///////////////////////////////////////////
QT CODE
tcpserver
#ifndef SERVER_H
#define SERVER_H
#include <QObject>
#include <QTcpServer>
#include <QTcpSocket>
class server : public QObject
{
Q_OBJECT
public:
explicit server(QObject *parent = 0);
QTcpServer *tserver;
QTcpSocket *socket;
public slots:
void newConnect();
void receiveMSG();
};
#endif // SERVER_H
//server.cpp
#include "server.h"
server::server(QObject *parent) :
QObject(parent)
{
tserver = new QTcpServer;
if(tserver->listen(QHostAddress::Any, 9999))
qWarning("listing on 9999");
connect(tserver, SIGNAL(newConnection()), this, SLOT(newConnect()));
}
void server::newConnect()
{
socket = tserver->nextPendingConnection();
connect(socket, SIGNAL(readyRead()), this, SLOT(receiveMSG()));
}
void server::receiveMSG()
{
QByteArray data;
data.resize(socket->bytesAvailable());
socket->read(data.data(), data.size());
qWarning("receive# %s", data.data());
}
@
Thread running normally now. I was in the project which added a "tcpserver", used to monitor the connection and receive messages. In C # to call when the client "socket" shows the state is "already connected", but in C # where not receive data, "incomingConnection" function has not been called. If I use QT to use the DLL functions can be done, then, C # in the die. Is no event loop ah?