Click here to Skip to main content
15,887,027 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: porting _beginthreadex from VS2005 to VS2017 Pin
jimNLX6-Apr-18 9:03
jimNLX6-Apr-18 9:03 
AnswerRe: porting _beginthreadex from VS2005 to VS2017 Pin
leon de boer20-Mar-18 8:00
leon de boer20-Mar-18 8:00 
GeneralRe: porting _beginthreadex from VS2005 to VS2017 Pin
jimNLX6-Apr-18 9:06
jimNLX6-Apr-18 9:06 
GeneralRe: porting _beginthreadex from VS2005 to VS2017 Pin
jimNLX11-Apr-18 9:03
jimNLX11-Apr-18 9:03 
GeneralRe: porting _beginthreadex from VS2005 to VS2017 Pin
leon de boer17-Apr-18 21:45
leon de boer17-Apr-18 21:45 
GeneralRe: porting _beginthreadex from VS2005 to VS2017 Pin
jimNLX18-Apr-18 3:49
jimNLX18-Apr-18 3:49 
GeneralRe: porting _beginthreadex from VS2005 to VS2017 Pin
leon de boer18-Apr-18 15:27
leon de boer18-Apr-18 15:27 
GeneralRe: porting _beginthreadex from VS2005 to VS2017 Pin
jimNLX9-May-18 9:18
jimNLX9-May-18 9:18 
I really wish I didn't have to keep dragging this one, but I still don't know why this won't work.

It worked perfectly fine in VS2005, but now I can't make a thread? Doesn't make sense.

From what I have learned the original code was built with /CLR:pure or managed. I've tried to remove this but the error are so extensive I don't think I would ever get through them.

Is there another function I can use to create the thread? Or some other way to get this thread to run without rewriting the whole thing?
Any help would be much appreciated.

This is where I'm at now:
#include "Connection.h"
#include "Packet.h"
#include "Opcodes.h"

using Ig::Connection;
using Ig::CriticalSection;

using namespace Ig;

CriticalSection::CriticalSection()
{
...
Connection::Connection()
{
...
}

Connection::~Connection()
{
// Wait for the thread to exit.
exitThreads();

// Clear any pending opcodes.
clearPendingOpcodes();
}

bool Connection::open(const char* ip, const int port, const int timeOut)
{
// Make sure the threads are not already running.
exitThreads();

// Setup the ports

// Setup the sockets.

// Set the receive socket timeout.

// Set up the send address.

// Setup the receive address

// Change the state to connecting

// Connect to the sender address.
if (::connect(m_sendSocket, (sockaddr *)&m_sendAddress, sizeof(m_sendAddress)) == SOCKET_ERROR)
{
int error = WSAGetLastError();
closesocket(m_sendSocket);
return false;
}

// Bind to the receiver address.
if (::bind(m_receiveSocket, (sockaddr *)&m_receiveAddress, sizeof(m_receiveAddress)) == SOCKET_ERROR)
{
int error = WSAGetLastError();
closesocket(m_sendSocket);
closesocket(m_receiveSocket);
return false;
}
// Clear pending opcodes.
clearPendingOpcodes();

// Start the threads
// THIS IS WHERE ALL MY PROBLEMS BEGIN!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// //
m_sendThread = (HANDLE)_beginthreadex(NULL, 0, sendData, this, 0, &this->m_sendThreadId);
m_receiveThread = (HANDLE)_beginthreadex(NULL, 0, receiveData, this, 0, &this->m_receiveThreadId);

return true;
}


unsigned int Connection::sendData(void* param)
{
bool request_thread_exit = false;
ConnectionState state = Connection::connecting;

// The param should be an instance of the connection class.
if (param == 0) return 0;

// Cast it to a connection
Connection* connection = static_cast(param);

// Set the state to connecting.
connection->setState(Connection::connecting);

// Loop until we are told to exit.
while (state != Connection::offline)
{
// Get the current state (thread safe).
state = connection->getState();

// Send data based on the state of the connection.
switch (state)
{
// The connection is offline.
case offline: break;
// Connecting to the Ig.
case connecting: connection->processConnectingState(); break;
// Loading everything.
case loading: connection->processLoadingState(); break;
// Waiting for the Ig to set load flags.
case waiting: connection->processWaitingState(); break;
// Running.
case running: connection->processRunningState(); break;
// Unloading.
case unloading: connection->processUnloadingState(); break;
// Disconnecting.
case disconnecting: connection->processDisconnectingState(); break;
}

// Take a break...
Sleep(15);
}

// Close the socket.
closesocket(connection->m_sendSocket);

return 0;
}

unsigned int Connection::receiveData(void* param)
{
bool request_thread_exit = false;
ConnectionState state = Connection::connecting;

// The param should be an instance of the connection class.
if (param == 0) return 0;

// Cast it to a connection
Connection* connection = static_cast(param);

DWORD lastResponseTime = GetTickCount();
DWORD elapsedTime = 0;
const int max_buffer_size = 66000;
char buffer[max_buffer_size];
DWORD maxTime = (DWORD)connection->getTimeOut();

while (state != Connection::offline)
{
// Get the current state (thread safe).
state = connection->getState();

// Attempt to receive data.
int bytes_received = recv(connection->m_receiveSocket, buffer, max_buffer_size, 0);
if (bytes_received != SOCKET_ERROR)
{
// Update the response time.
lastResponseTime = GetTickCount();
// Process the Response.
connection->processResponse(buffer, bytes_received);

//If the state is connecting, then transition to the loading state.
if (state == Connection::connecting)
connection->setState(Connection::loading);

}
else
{
// Check how long it has been since we have received a response.
// If it has been to long, then transition to the offline state.
elapsedTime = GetTickCount() - lastResponseTime;

// Make sure the timer didn't roll over.
if (elapsedTime maxTime && (state > Connection::connecting && state setState(Connection::offline);
}
}
}

// Close the socket.
closesocket(connection->m_receiveSocket);

return 0;
}

void Connection::exitThreads()
{
...
}


}
GeneralRe: porting _beginthreadex from VS2005 to VS2017 Pin
leon de boer9-May-18 16:11
leon de boer9-May-18 16:11 
GeneralRe: porting _beginthreadex from VS2005 to VS2017 Pin
jimNLX11-May-18 6:23
jimNLX11-May-18 6:23 
QuestionOpenCL bit-matrix multiplication (implementing tiling in local memory) Pin
User 1370349219-Mar-18 19:19
User 1370349219-Mar-18 19:19 
AnswerRe: OpenCL bit-matrix multiplication (implementing tiling in local memory) Pin
leon de boer19-Mar-18 23:47
leon de boer19-Mar-18 23:47 
GeneralRe: OpenCL bit-matrix multiplication (implementing tiling in local memory) Pin
User 1370349220-Mar-18 1:02
User 1370349220-Mar-18 1:02 
GeneralRe: OpenCL bit-matrix multiplication (implementing tiling in local memory) Pin
leon de boer20-Mar-18 3:12
leon de boer20-Mar-18 3:12 
GeneralRe: OpenCL bit-matrix multiplication (implementing tiling in local memory) Pin
User 1370349220-Mar-18 10:09
User 1370349220-Mar-18 10:09 
GeneralRe: OpenCL bit-matrix multiplication (implementing tiling in local memory) Pin
leon de boer20-Mar-18 15:27
leon de boer20-Mar-18 15:27 
GeneralRe: OpenCL bit-matrix multiplication (implementing tiling in local memory) Pin
User 1370349221-Mar-18 3:50
User 1370349221-Mar-18 3:50 
GeneralRe: OpenCL bit-matrix multiplication (implementing tiling in local memory) Pin
leon de boer21-Mar-18 4:25
leon de boer21-Mar-18 4:25 
GeneralRe: OpenCL bit-matrix multiplication (implementing tiling in local memory) Pin
User 1370349221-Mar-18 7:00
User 1370349221-Mar-18 7:00 
GeneralRe: OpenCL bit-matrix multiplication (implementing tiling in local memory) Pin
leon de boer21-Mar-18 16:12
leon de boer21-Mar-18 16:12 
GeneralRe: OpenCL bit-matrix multiplication (implementing tiling in local memory) Pin
User 137034921-Apr-18 18:05
User 137034921-Apr-18 18:05 
GeneralRe: OpenCL bit-matrix multiplication (implementing tiling in local memory) Pin
leon de boer2-Apr-18 18:56
leon de boer2-Apr-18 18:56 
GeneralRe: OpenCL bit-matrix multiplication (implementing tiling in local memory) Pin
User 1370349220-Mar-18 9:07
User 1370349220-Mar-18 9:07 
GeneralRe: OpenCL bit-matrix multiplication (implementing tiling in local memory) Pin
Victor Nijegorodov20-Mar-18 9:18
Victor Nijegorodov20-Mar-18 9:18 
QuestionHow to read MS EXCEL workbook in Linux using C++ Pin
Member 179075719-Mar-18 5:55
Member 179075719-Mar-18 5:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.