PDA

View Full Version : Accessing the SDK


NoLoComprendo
31-05-2004, 14:33
Hi there. I'm trying to access tsremote.dll from .NET, but keep being told that the .dll isn't a proper COM .dll. "resgsvr32" tells me the same thing. I'm prepared to use any .NET language (other than Delphi for .NET) and I'm wondering if anyone has done a C++ header for this file or any file that allows me to access TS2 calls!

I can't wait for TS3 (C++ port :D). Lovely product from some hard working devs :). Keep it up guys!

pbarrette
01-06-2004, 17:35
Hi NoLoCo,

I'm using C# to call the SDK functions. There is a (non .net) C++ header floating around. Take a look at my sticky post to find it.

Basically, you have to use P/Invoke to use the SDK dll with .NET. Here's an example ripped straight from my TsShow4DX8:


using System;
using System.Runtime.InteropServices;

namespace TsShow4DX8
{
/// <summary>
/// Summary description for TSControl.
/// </summary>


//This struct lays out the array that "tsrGetPlayerInfoByID" requires.
[StructLayout(LayoutKind.Sequential)]
public struct TPlayerInfo
{
public Int32 PlayerID;
public Int32 ChannelID;
[MarshalAs(System.Runtime.InteropServices.Unmanaged Type.ByValTStr,SizeConst=30)]
public string NickName;
public Int32 PlayerChannelPrivileges;
public Int32 PlayerPrivileges;
public Int32 PlayerFlags;
}

//Our P/Invoke code
class TSControlApi
{
[DllImport("TSRemote")]
public static extern int tsrGetSpeakers(Int32[] aIDs, ref int iRecords);

[DllImport("TSRemote")]
public static extern int tsrGetPlayerInfoByID(Int32 iID, ref TPlayerInfo tPInfo);
}

public class TSControl
{

public TSControl()
{
}

public string[,] GetSpeakers()
{
int iResult;
string sName;

//Make an array to hold the speaker ID's
Int32[] aIDs = new Int32[1024];
int iRecords = 1024;

//Get speaker ID#'s.
iResult = TSControlApi.tsrGetSpeakers(aIDs, ref iRecords);

//Setup array for names and ID's.
string[,] aNameList = new string[iRecords,2];

//If the call succeeded..
if(iResult == 0)
{
//If there were speakers..
if(iRecords > 0)
{
//Populate the speaker array with their names.
for(int i=0; i<iRecords; i++)
{
GetNames(aIDs[i], out sName);
aNameList[i,0] = aIDs[i].ToString();
aNameList[i,1] = sName;
}
}
//If there weren't speakers..
else
{
//If there were speakers last time around.
//(Basically, don't call the DLL to clear the display
// if the display is already clear.)
if (TsShow.bLastSpkrState)
{
//Clear the display.
UseGpComms m_GpComms = new UseGpComms();
m_GpComms.GPShowMLText(false);
}
}
}

//Send the name list array back.
return aNameList;
}

public void GetNames(Int32 iID, out string sName)
{
//Set some defaults for the name structure.
int iResult;
sName = "Error";

TPlayerInfo tPInfo;
tPInfo.ChannelID = 0;
tPInfo.PlayerID = 0;
tPInfo.NickName = "123456789012345678901234567890";
tPInfo.PlayerFlags = 0;
tPInfo.PlayerChannelPrivileges = 0;
tPInfo.PlayerPrivileges = 0;

//Get the player ID structure from the SDK.
iResult = TSControlApi.tsrGetPlayerInfoByID(iID, ref tPInfo);

//If succeeded, set the name found.
if(iResult == 0)
{
sName = tPInfo.NickName;
}
}


}
}


Some of this is specific to my program, but pay close attention to the "[StructLayout(LayoutKind.Sequential)]" and "[DllImport("TSRemote")]" code. The first creates a data structure formatted such that it can be passed to the SDK and be populated correctly. The second is the P/Invoke code that must be used to access the SDK.

So basically..
Pseudocode:

using InteropServices

namespace mynamespace

[StructLayout(LayoutKind.Sequential)]
public struct StructName
{data structure array here}

class MyPInvokeClass
{
[DllImport("TSRemote")]
public static extern TYPE tsrMyNeededCall(vars to send/recieve);
}

class MySDKUsageClass
{
public TYPE UsageName([vars])
{
MyPInvokeClass.tsrMyNeededCall(vars);
}
}


Create the struct (if needed), set up the P/Invoke caller class and calls, create an accessing class an accessing methods. Call the accessing methods when you want to access the SDK. Then read the vars that are returned by your accessing class (if applicable).

Hope this helps. I know it's not C++ .NET, but you should be able to translate from C#.

pb

NoLoComprendo
01-06-2004, 23:32
Beautiful :D!

Exactly what I needed! I'm using VB.NET at the mo, so this is great! Thanks mate :)

If I get time over the summer I'll try to do a full interop type thing in VB.NET because I'm sure other people will want to develop .NET programmes that interface with TS2.

Thanks again, and all the best with your proggy :).

Blue42
08-07-2004, 18:33
Where can I get the SDK for TS2? Searched the whole site but was not able to find any trace.
Blue42

Kabukiman
08-07-2004, 18:36
In your TS-Client-Installfolder, you'll find a folder named "client_sdk"

Guess what's in there... ;)

Blue42
08-07-2004, 22:10
Well ;) that was the first place I searched, strange but true there is no client_sdk
But never the less, thanx for the help. Think I got to reinstall.

pbarrette
11-07-2004, 19:40
Hi Blue42,

You don't really need to reinstall if you just want the TsRemote.dll file. Actually, unless they incorporated the newer (memory leak fixed) version into the installer, you probably need to download the fixed version anyway.

The fixed version is located here:
ftp://ftp.teamspeak.org/developer/client/TSRemote.dll

Also, the sticky post at the top of this forum topic is an unofficial list of the various software and programming topics that were spread out over this site before the existance of this forum category. Hopefully you can find something useful in that list as well.

pb

Blue42
12-07-2004, 11:49
THX 4 the information!