// gets Channel Info and Players by Name public static TtsrChannelInfo GetChannelInfo(string channel_name, ref TtsrPlayerInfo [] arr_pi) { const int MAX_PLAYERS = 200; int nRetVal = 0; int records = MAX_PLAYERS; bool bGetPlayers = false; TtsrChannelInfo ci = new TtsrChannelInfo(); TtsrPlayerInfo [] pi = new TtsrPlayerInfo[MAX_PLAYERS]; int ci_size = Marshal.SizeOf(typeof(TtsrChannelInfo)); int pi_size = Marshal.SizeOf(typeof(TtsrPlayerInfo)) * MAX_PLAYERS; System.IntPtr p_channel = Marshal.AllocHGlobal(ci_size); System.IntPtr p_player = Marshal.AllocHGlobal(pi_size); System.IntPtr p_current = (IntPtr)0; nRetVal = tsrGetChannelInfoByName(channel_name, p_channel, p_player, out records); // figure out if we are to get the player list too. if (arr_pi != null) { bGetPlayers = true; } arr_pi = null; // now process the items if (nRetVal == 0) { nRetVal = ci.ReadHeapValues(p_channel); Marshal.DestroyStructure(p_channel, typeof(TtsrChannelInfo)); if (nRetVal == 0 && bGetPlayers == true) { // build the new player array... arr_pi = new TtsrPlayerInfo [records]; // keep track of our player pointer p_current = p_player; for (int i = 0; i < records; i++) { arr_pi[i] = new TtsrPlayerInfo(); Marshal.PtrToStructure(p_current, arr_pi[i]); Marshal.DestroyStructure(p_current, typeof(TtsrPlayerInfo)); p_current = (IntPtr)((int)p_current + Marshal.SizeOf(typeof(TtsrPlayerInfo)) - 2); } } } // Free the memory that was allocated on the heap, otherwise // you will create a memory leak. Marshal.FreeHGlobal(p_channel); Marshal.FreeHGlobal(p_player); return(ci); }
// gets Player Info by Name public static TtsrPlayerInfo GetPlayerInfo(string player_name) { int nRetVal = 0; TtsrPlayerInfo pi = new TtsrPlayerInfo(); int size = Marshal.SizeOf(typeof(TtsrPlayerInfo)); System.IntPtr p_player = Marshal.AllocHGlobal(size); nRetVal = tsrGetPlayerInfoByName(player_name, p_player); if (nRetVal == 0) { nRetVal = pi.ReadHeapValues(p_player); } Marshal.DestroyStructure(p_player, typeof(TtsrPlayerInfo)); // Free the memory that was allocated on the heap, otherwise // you will create a memory leak. Marshal.FreeHGlobal(p_player); return(pi); }
// gets Player Info by Name public static TtsrPlayerInfo GetPlayerInfo( string player_name ) { int nRetVal = 0; TtsrPlayerInfo pi = new TtsrPlayerInfo(); int size = Marshal.SizeOf( typeof( TtsrPlayerInfo ) ); System.IntPtr p_player = Marshal.AllocHGlobal(size); nRetVal = tsrGetPlayerInfoByName( player_name, p_player ); if ( nRetVal == 0 ) { nRetVal = pi.ReadHeapValues( p_player ); } Marshal.DestroyStructure( p_player, typeof( TtsrPlayerInfo ) ); // Free the memory that was allocated on the heap, otherwise // you will create a memory leak. Marshal.FreeHGlobal(p_player); return pi; }
// gets Channel Info and Players by Name public static TtsrChannelInfo GetChannelInfo( string channel_name, ref TtsrPlayerInfo [] arr_pi ) { const int MAX_PLAYERS = 200; int nRetVal = 0; int records = MAX_PLAYERS; bool bGetPlayers = false; TtsrChannelInfo ci = new TtsrChannelInfo(); TtsrPlayerInfo [] pi = new TtsrPlayerInfo[MAX_PLAYERS]; int ci_size = Marshal.SizeOf( typeof( TtsrChannelInfo ) ); int pi_size = Marshal.SizeOf( typeof( TtsrPlayerInfo ) ) * MAX_PLAYERS; System.IntPtr p_channel = Marshal.AllocHGlobal( ci_size ); System.IntPtr p_player = Marshal.AllocHGlobal( pi_size ); System.IntPtr p_current = (IntPtr)0; nRetVal = tsrGetChannelInfoByName( channel_name, p_channel, p_player, out records ); // figure out if we are to get the player list too. if ( arr_pi != null ) { bGetPlayers = true; } arr_pi = null; // now process the items if ( nRetVal == 0 ) { nRetVal = ci.ReadHeapValues( p_channel ); Marshal.DestroyStructure( p_channel, typeof( TtsrChannelInfo ) ); if ( nRetVal == 0 && bGetPlayers == true ) { // build the new player array... arr_pi = new TtsrPlayerInfo [ records ]; // keep track of our player pointer p_current = p_player; for( int i = 0; i < records; i++ ) { arr_pi[ i ] = new TtsrPlayerInfo(); Marshal.PtrToStructure ( p_current, arr_pi[ i ]); Marshal.DestroyStructure( p_current, typeof(TtsrPlayerInfo) ); p_current = (IntPtr)((int)p_current + Marshal.SizeOf( typeof( TtsrPlayerInfo ) ) - 2 ); } } } // Free the memory that was allocated on the heap, otherwise // you will create a memory leak. Marshal.FreeHGlobal(p_channel); Marshal.FreeHGlobal(p_player); return ci; }
public TtsrUserInfo() { Player = new TtsrPlayerInfo(); Channel = new TtsrChannelInfo(); ParentChannel = new TtsrChannelInfo(); }