c++ windows 创建进程 和 传参

main.cpp

#include <iostream>
#include <vector>
#include <string>

std::vector account_list;
void ThreadTcp(LPVOID lpParam)
{
	cout << "TCP线程开始" << endl;

	vector *account_list = (vector *)lpParam;

	WSADATA wsaData;
	SOCKET hSocket;
	SOCKADDR_IN servAddr;

	int strLen = 0;
	int idx = 0, readLen = 0;
	if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
	{
		std::cout << "WSAStartup() error" << std::endl;
	}

	hSocket = socket(PF_INET, SOCK_STREAM, 0);
	if (hSocket == INVALID_SOCKET)
	{
		std::cout << "hSocket() error" << std::endl;
	}

	memset(&servAddr, 0, sizeof(servAddr));
	servAddr.sin_addr.S_un.S_addr = inet_addr("139.224.118.131");
	servAddr.sin_family = AF_INET;
	servAddr.sin_port = htons(9035);
	int conn_ret = -111;
	if (conn_ret = connect(hSocket, (SOCKADDR*)& servAddr, sizeof(SOCKADDR)))
	{
		std::cout << "连接失败!" << std::endl;
		std::cin.get();
	}

	int n = 0;
	char recvBuf[2000];
	char sendBuf[2000];

	while (true)
	{
		ZeroMemory(recvBuf, 2000);
		recv(hSocket, recvBuf, sizeof(recvBuf), 0);
		if (strlen(recvBuf) == 0)
		{
			std::cout << "断开连接" << std::endl;
			break;
		}
		printf("recv:%s", recvBuf);
		
		for (int i = 0; i < 1000; i++)
		{
			sprintf_s(sendBuf, "Hello, This is client %d\r\n", i);
			//send(hSocket, sendBuf, strlen(sendBuf), 0);
		}

		if (std::count(account_list->begin(), account_list->end(), "100444024"))
		{
			cout << "已有账号" << endl;
		}
		else
		{
			cout << "添加登录账号" << endl;
			account_list->push_back("100444024");

			TThostFtdcBrokerIDType brokerID = "9999";
			TThostFtdcInvestorIDType investerID = "100444024";
			TThostFtdcPasswordType investerPassword = "123456";
			char tradeFrontAddr[] = "tcp://139.129.39.75:1234";
			addAccount(brokerID, investerID, investerPassword, tradeFrontAddr);
		}
	}

	closesocket(hSocket);
	WSACleanup();
}

int main()
{
    HANDLE Thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ThreadTcp, &account_list, 0, NULL);
}