Jump to content
The simFlight Network Forums

Failed to connect in TeamSpeak3 SDK


Recommended Posts

Dear Pete,

 

I am now on a project that automantically switch channel in TeamSpeak3(TS3) according to the COM1 frequncy in FS2004.

 

TS3 offers a SDK that can easily build a plugin(DLL file) for it.

 

Based on the TS3 SDK demo, I added FSUIPC related files , but I failed to connect to the FSUIPC: FSUIPC_Open()  returned False.

 

I debuged it, and found that in FSUIPC_Open(),

m_hMap = CreateFileMapping(
					(HANDLE)0xFFFFFFFF, // use system paging file
					NULL,               // security
					PAGE_READWRITE,     // protection
					0, MAX_SIZE+256,       // size
					szName);     

m_hMap got 0. But in FSUIPC demo, it should be 96.

 

 

I am wondering what kind of  modificatiosn should be done to my code so it can connect to FSUIPC .

 

 

 

kind regards,

zea

Link to comment
Share on other sites

Dear Pete,

 

I am now on a project that automantically switch channel in TeamSpeak3(TS3) according to the COM1 frequncy in FS2004.

 

TS3 offers a SDK that can easily build a plugin(DLL file) for it.

 

Based on the TS3 SDK demo, I added FSUIPC related files , but I failed to connect to the FSUIPC: FSUIPC_Open()  returned False.

 

I debuged it, and found that in FSUIPC_Open(),

m_hMap = CreateFileMapping(
					(HANDLE)0xFFFFFFFF, // use system paging file
					NULL,               // security
					PAGE_READWRITE,     // protection
					0, MAX_SIZE+256,       // size
					szName);     

m_hMap got 0. But in FSUIPC demo, it should be 96.

 

 

I am wondering what kind of  modificatiosn should be done to my code so it can connect to FSUIPC

 

Sorry, you only show the one line, and I don't know what your szName parameter is. A return of 0 means a failure, so use GetLastError() to get the error number to see why it failed.

 

Pete

Link to comment
Share on other sites

Sorry, you only show the one line, and I don't know what your szName parameter is. A return of 0 means a failure, so use GetLastError() to get the error number to see why it failed.

 

Pete

 

Thank you for your reply.

 

I use printf() to display the value of szName and GetLastError().

szName is "FsasmLib:IPC:1AC0:1" . Note that "1AC0" changes every time I run the plugin.

GetLastError() returns 6.

 

 

I am not sure whether related code is helpful because it is just part of the FSUIPC demo. I put it below and I have added comment where my program failed.

BOOL FSUIPC_Open(DWORD dwFSReq, DWORD *pdwResult)
{  char szName[MAX_PATH];
	static int nTry = 0;
	BOOL fWideFS = FALSE;
	int i = 0;

	// abort if already started
	if (m_pView)
	{	*pdwResult = FSUIPC_ERR_OPEN;
		return FALSE;
	}

	// Clear version information, so know when connected
	FSUIPC_Version = FSUIPC_FS_Version = 0;
	
	// Connect via FSUIPC, which is known to be FSUIPC's own
	// and isn't subject to user modificiation
	m_hWnd = FindWindowEx(NULL, NULL, "UIPCMAIN", NULL);
	if (!m_hWnd)
	{	// If there's no UIPCMAIN, we may be using WideClient
		// which only simulates FS98
		m_hWnd = FindWindowEx(NULL, NULL, "FS98MAIN", NULL);
		fWideFS = TRUE;
		if (!m_hWnd)
		{	*pdwResult = FSUIPC_ERR_NOFS;
			return FALSE;
		}
	}
	
	// register the window message
	m_msg = RegisterWindowMessage(FS6IPC_MSGNAME1);
	if (m_msg == 0)
	{	*pdwResult = FSUIPC_ERR_REGMSG;
		return FALSE;
	}

	// create the name of our file-mapping object
	nTry++; // Ensures a unique string is used in case user closes and reopens
	wsprintf(szName, FS6IPC_MSGNAME1 ":%X:%X", GetCurrentProcessId(), nTry);


	// stuff the name into a global atom
	m_atom = GlobalAddAtom(szName);
	if (m_atom == 0)
   {	*pdwResult = FSUIPC_ERR_ATOM;
		FSUIPC_Close();
		return FALSE;
	}

	// create the file-mapping object
	m_hMap = CreateFileMapping(
					(HANDLE)0xFFFFFFFF, // use system paging file
					NULL,               // security
					PAGE_READWRITE,     // protection
					0, MAX_SIZE+256,       // size
					szName);            // name 

//=====================The function above returns 0, as a result the connection fail.===============


	if ((m_hMap == 0) || (GetLastError() == ERROR_ALREADY_EXISTS))
	{	*pdwResult = FSUIPC_ERR_MAP;
		FSUIPC_Close();
		return FALSE;    
	}


	...
}

Best regards,

zea

Link to comment
Share on other sites

Hmm. System Error 6 is "Invalid Handle". The only handle there is the special one, 0xFFFFFFFF, which is specifically needed for a system paging file. Here's what the CreateFileMapping documentation says:

 

"If hFile is INVALID_HANDLE_VALUE, the calling process must also specify a size for the file mapping object in the dwMaximumSizeHigh and dwMaximumSizeLow parameters. In this scenario,CreateFileMapping creates a file mapping object of a specified size that is backed by the system paging file instead of by a file in the file system."

 

INVALID_HANDLE_VALUE is actually defined as -1. Are you trying to compile in 64-bit mode? Try -1 instead. Maybe 0xFFFFFFFF is coming out as 0x00000000FFFFFFFF instead of 0xFFFFFFFFFFFFFFFF.

 

Pete

Link to comment
Share on other sites

Hmm. System Error 6 is "Invalid Handle". The only handle there is the special one, 0xFFFFFFFF, which is specifically needed for a system paging file. Here's what the CreateFileMapping documentation says:

 

"If hFile is INVALID_HANDLE_VALUE, the calling process must also specify a size for the file mapping object in the dwMaximumSizeHigh and dwMaximumSizeLow parameters. In this scenario,CreateFileMapping creates a file mapping object of a specified size that is backed by the system paging file instead of by a file in the file system."

 

INVALID_HANDLE_VALUE is actually defined as -1. Are you trying to compile in 64-bit mode? Try -1 instead. Maybe 0xFFFFFFFF is coming out as 0x00000000FFFFFFFF instead of 0xFFFFFFFFFFFFFFFF.

 

Pete

 

Thank you Pete.

I am sorry for my late reply, I've been away from my computer for several days.

 

Yes, I am trying to compile in 64-bit mode, and the same code runs pretty good in 32-bit mode.

I just tried 0xFFFFFFFFFFFFFFFF, and m_hMap gets 64, while in 32-bit mode it should be 96.

And after several lines, the program goes wrong again .

 

The error message is "Unhanled exception at 0x5168b3d9(msvcr100d.dll) in test.exe: 0xC0000005: Access violation writing location 0x0000000139800004."

 

 

here are part of the codes, and I have added comments.

        // create the file-mapping object
	m_hMap = CreateFileMapping(
					(HANDLE)0xFFFFFFFFFFFFFFFF, // use system paging file
					NULL,               // security
					PAGE_READWRITE,     // protection
					0, MAX_SIZE+256,       // size
					szName);            // name 



	//============m_hMap get 64, diffrent from 96 in 32-bit mode.============

	if ((m_hMap == 0) || (GetLastError() == ERROR_ALREADY_EXISTS))
	{	*pdwResult = FSUIPC_ERR_MAP;
		FSUIPC_Close();
		return FALSE;    
	}

	// get a view of the file-mapping object
	m_pView = (BYTE*)MapViewOfFile(m_hMap, FILE_MAP_WRITE, 0, 0, 0);

	// m_pView is different every time I run it. an example value is 1638400

	if (m_pView == NULL)
	{	*pdwResult = FSUIPC_ERR_VIEW;
		FSUIPC_Close();
		return FALSE;
	}


	// Okay, now determine FSUIPC version AND FS type
	m_pNext = m_pView;

	// Try up to 5 times with a 100mSec rest between each
	// Note that WideClient returns zeroes initially, whilst waiting
	// for the Server to get the data
	while ((i++ < 5) && ((FSUIPC_Version == 0) || (FSUIPC_FS_Version == 0)))
	{	// Read FSUIPC version
		if (!FSUIPC_Read(0x3304, 4, &FSUIPC_Version, pdwResult))
		{	FSUIPC_Close();
			return FALSE;
		}

		// and FS version and validity check pattern
		if (!FSUIPC_Read(0x3308, 4, &FSUIPC_FS_Version, pdwResult))
		{	FSUIPC_Close();
			return FALSE;
		}

		// Write our Library version number to a special read-only offset
		// This is to assist diagnosis from FSUIPC logging
		// But only do this on first try
		if ((i < 2) && !FSUIPC_Write(0x330a, 2, &FSUIPC_Lib_Version, pdwResult))
		{	FSUIPC_Close();
			return FALSE;
		}

		//========================= the code goes wrong below ======================

		// Actually send the requests and get the responses ("process")
		if (!FSUIPC_Process(pdwResult))
		{	FSUIPC_Close();
			return FALSE;
		}

		// Maybe running on WideClient, and need another try
		Sleep(100); // Give it a chance
	}

The error is in the function BOOL FSUIPC_Process(DWORD *pdwResult).

part of the code are below.

BOOL FSUIPC_Process(DWORD *pdwResult)
{	DWORD dwError;
	DWORD *pdw;
	FS6IPC_READSTATEDATA_HDR *pHdrR;
	FS6IPC_WRITESTATEDATA_HDR *pHdrW;
	int i = 0;
	
	if (!m_pView)
	{	*pdwResult = FSUIPC_ERR_NOTOPEN;
		return FALSE;
	}

	if (m_pView == m_pNext)
	{	*pdwResult = FSUIPC_ERR_NODATA;
		return FALSE;
	}

	ZeroMemory(m_pNext, 4); // Terminator
	m_pNext = m_pView;
	
	// send the request (allow up to 9 tries)
	while ((++i < 10) && !SendMessageTimeout(
			m_hWnd,       // FS6 window handle
			m_msg,        // our registered message id
			m_atom,       // wParam: name of file-mapping object
			0,            // lParam: offset of request into file-mapping obj
			SMTO_BLOCK,   // halt this thread until we get a response
			2000,			  // time out interval
			&dwError))    // return value
	{	Sleep(100); // Allow for things to happen
	}

	if (i >= 10) // Failed all tries?
	{	*pdwResult = GetLastError() == 0 ? FSUIPC_ERR_TIMEOUT : FSUIPC_ERR_SENDMSG;
		return FALSE;
	}

	if (dwError != FS6IPC_MESSAGE_SUCCESS)
	{	*pdwResult = FSUIPC_ERR_DATA; // FSUIPC didn't like something in the data!
		return FALSE;
	}

	// Decode and store results of Read requests
	pdw = (DWORD *) m_pView;

	while (*pdw)
	{	switch (*pdw)
		{	case FS6IPC_READSTATEDATA_ID:
				pHdrR = (FS6IPC_READSTATEDATA_HDR *) pdw;
				m_pNext += sizeof(FS6IPC_READSTATEDATA_HDR);
				if (pHdrR->pDest && pHdrR->nBytes)
					CopyMemory(pHdrR->pDest, m_pNext, pHdrR->nBytes);
				//===========  Visual Studio breaks in the next line.====================
				m_pNext += pHdrR->nBytes;
				break;

			case FS6IPC_WRITESTATEDATA_ID:
				// This is a write, so there's no returned data to store
				pHdrW = (FS6IPC_WRITESTATEDATA_HDR *) pdw;
				m_pNext += sizeof(FS6IPC_WRITESTATEDATA_HDR) + pHdrW->nBytes;
				break;

			default:
				// Error! So terminate the scan
				*pdw = 0;
				break;
		}
...

Thanks!

 

zea

Edited by zea
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.