Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Delphi和Teamspeak SDK的使用_Delphi - Fatal编程技术网

Delphi和Teamspeak SDK的使用

Delphi和Teamspeak SDK的使用,delphi,Delphi,我正在尝试将TeamSpeak3 SDK与我的delphi一起使用。我遇到了一些问题,代码编译后似乎正常工作,大多数代码都是来自示例项目的示例代码,除了尝试读取返回的数据。 1.我释放的内存正确吗? 2.我从SDK读取返回的数据是正确的还是可以用更好的方法 我在另一个线程中询问了一个关于此SDK的问题,但我显然太快了,无法将该线程标记为已回答/ SDK文档: 要获取指定虚拟服务器上所有当前可见客户端的列表: 未签名的int-ts3client\u getClientList(serverConn

我正在尝试将TeamSpeak3 SDK与我的delphi一起使用。我遇到了一些问题,代码编译后似乎正常工作,大多数代码都是来自示例项目的示例代码,除了尝试读取返回的数据。
1.我释放的内存正确吗? 2.我从SDK读取返回的数据是正确的还是可以用更好的方法

我在另一个线程中询问了一个关于此SDK的问题,但我显然太快了,无法将该线程标记为已回答/

SDK文档:

要获取指定虚拟服务器上所有当前可见客户端的列表:
未签名的int-ts3client\u getClientList(serverConnectionHandlerID,result)
uint64服务器连接handlerid
anyID**结果
参数
•服务器连接HandlerID 请求客户端列表的服务器连接处理程序的ID。
•结果
接收客户端ID的空终端数组的变量的地址。
除非发生错误,否则必须使用ts3client_freeMemory释放阵列。
成功时返回ERROR_ok,否则返回public_errors.h中定义的错误代码。如果发生错误,则结果数组未初始化,不能释放

可以通过以下方式查询指定虚拟服务器上所有频道的列表:
无符号int-ts3client\u getChannelList(serverConnectionHandlerID,result)
uint64服务器连接handlerid
uint64**结果
参数
•服务器连接句柄ID
请求通道列表的服务器连接处理程序的ID。
•结果
接收通道ID的空终端数组的变量的地址。除非发生错误,否则必须使用ts3client_freeMemory释放阵列。
成功时返回ERROR_ok,否则返回public_errors.h中定义的错误代码。如果发生错误,则结果数组未初始化,不能释放

无符号int-ts3client_getCaptureDeviceList(modeID,result)const char*modeID;字符****结果

参数
•modeID
定义要使用的播放/捕获模式。对于不同的模式,可能会有不同的设备列表。有效模式返回ts3client\u getDefaultPlayBackMode/ts3client\u getDefaultCaptureMode和ts3client\u getPlaybackModeList/ts3client\u getCaptureModeList。
•结果
接收以NULL结尾的数组{{char*deviceName,char*deviceID},{char*deviceName,char*deviceID},…,NULL}的变量的地址。
除非函数返回错误,否则需要使用ts3client_freeMemory释放数组元素和数组本身

成功时返回ERROR_ok,否则返回public_errors.h中定义的错误代码。发生错误时,结果数组未初始化,不能释放

可以列出给定模式下可用的播放和捕获设备,以及当前的默认操作系统。返回的设备值可用于初始化设备。
要查询默认播放和捕获设备,请调用

要获取指定模式下所有可用播放和捕获设备的列表,请调用

unsigned int ts3client_getPlaybackDeviceList(modeID,result); 常量字符*modeID
字符****结果
未签名的int ts3client_getCaptureDeviceList(modeID,result); 常量字符*modeID
字符****结果

unsigned int error;
anyID myID;
error = ts3client_getClientID(scHandlerID, &myID); /* Calling some Client Lib function */
if(error != ERROR_ok) {
    char* errorMsg;
    if(ts3client_getErrorMessage(error, &errorMsg) == ERROR_ok) 
    { /* Query printable error */
        printf("Error querying client ID: %s\n", errorMsg);
        ts3client_freeMemory(errorMsg); /* Release memory */
    }
}


type
  PPanyID = ^PAnyID;
  PanyID = ^anyID;
  anyID  = word;

var
   error: longword;
   errormsg: PAnsiChar;


procedure TfrmMain.RequestOnlineClients;
var
  ids : PanyID;
  pids : PanyID;
  aid : anyID;
begin
  error := ts3client_getClientList(FTSServerHandlerID, @ids);
  if (error <> ERROR_ok) then
  begin
    if (ts3client_getErrorMessage(error, @errormsg) = ERROR_ok) then
    begin
      LogMsg(Format('Error requesting online clients: %s', [errormsg]));
      ts3client_freeMemory(errormsg);
    end;
  end else
      begin
         pids := ids;
         while (pids^ <> 0) do
         begin
           aid := pids^;
           LogMsg(format('userid %u',[aid, getUserNickNameById(aid)]));
           inc(pids);
         end;
         ts3client_freeMemory(@pids^);  // here's potiential problem
      end;
end;

procedure TfrmMain.RequestChannels;
var
  ids : PUint64;
  pids : PUint64;
  aid : uint64;
  channelname : PAnsiChar;

begin
  error := ts3client_getChannelList(FTSServerHandlerID, @ids);
  if (error <> ERROR_ok) then
  begin
    if (ts3client_getErrorMessage(error, @errormsg) = ERROR_ok) then
    begin
      LogMsg(Format('Error requesting channels: %s', [errormsg]));
      ts3client_freeMemory(errormsg);
    end;
  end else
    begin
       pids := ids;
       while (pids^ <> 0) do
       begin
         aid := pids^;
         LogMsg(format('channelid %u %s',[aid, getChannelNameById(aid)]));
         inc(pids);
       end;
       ts3client_freeMemory(@pids^);
    end;
end;

**// Added details 25-11-2014**
char* defaultMode;  

if(ts3client_getDefaultPlayBackMode(&defaultMode) == ERROR_ok) {
char*** array;  
    if(ts3client_getPlaybackDeviceList(defaultMode, &array) == ERROR_ok) {
       for(int i=0; array[i] != NULL; ++i) {
           printf("Playback device name: %s\n", array[i][0]); /* First element: Device name */  
           printf("Playback device ID: %s\n", array[i][1]); /* Second element: Device ID */  
           /* Free element */  
          ts3client_freeMemory(array[i][0]);  
          ts3client_freeMemory(array[i][1]);  
          ts3client_freeMemory(array[i]);  
       }  
   ts3client_freeMemory(array); /* Free complete array */  
   } else {  
     printf("Error getting playback device list\n");  
   }  
} else {  
printf("Error getting default playback mode\n");  
}  

Example to query all available playback devices:
char* defaultMode;  

if(ts3client_getDefaultPlayBackMode(&defaultMode) == ERROR_ok) {
char*** array;
if(ts3client_getPlaybackDeviceList(defaultMode, &array) == ERROR_ok) {
  for(int i=0; array[i] != NULL; ++i) {  
    printf("Playback device name: %s\n", array[i][0]); /* First element: Device name */  
    printf("Playback device ID: %s\n", array[i][1]); /* Second element: Device ID */  
    /* Free element */  
    ts3client_freeMemory(array[i][0]);  
    ts3client_freeMemory(array[i][1]);  
    ts3client_freeMemory(array[i]);  
}  
ts3client_freeMemory(array); /* Free complete array */  
} else {  
  printf("Error getting playback device list\n");  
}  
} else {  
printf("Error getting default playback mode\n");  
}  

procedure TfrmMain.ConnectServer2;
var
  version : PAnsiChar;
  DefaultChannelsArr : PPAnsiChar;
begin
  if Connected then Exit;

  if not ClientInitialized then
    InitializeClient;

  // Dbl Check if we can connect
  if ClientInitialized then
  try

    // Connect to server on localhost:9987 with nickname "client", no default channel, no default channel password and server password "secret"
    // error := ts3client_startConnection(FTSServerHandlerID, identity, '127.0.0.1', 9987, 'Delphi Client', nil, '', 'secret'); // example connection setup
    ts3check(ts3client_startConnection(FTSServerHandlerID, PAnsiChar(FSetup.ClientIdentity), PAnsiChar(FSetup.ServerAddress), FSetup.FServerPort, PAnsiChar(FSetup.NickName), nil, '', PAnsiChar(FSetup.ServerPassword)));
    { TODO -oMe -cImportant : Need to check how to convert ansistrings to UTF8 } // UnicodeToUtf8() // AnsiToUtf8()...


     // Query and print client lib version
    ts3check(ts3client_getClientLibVersion(@version));
    LogMsg(Format('Client lib version: %s', [version]));
    ts3client_freeMemory(version);  // Release dynamically allocated memory

     // Do not set connected here, wait for the callback connected state
  except
    on e: exception do
    begin
      UnInitializeClient; // clear the hole thing and start over
      LogMsg(Format('Error connecting: %s',[e.Message]));
    end;
  end;
end;
参数
•modeID
定义要使用的播放/捕获模式。对于不同的模式,可能会有不同的设备列表。有效模式由
ts3client_getDefaultPlayBackMode/s3client_getDefaultCaptureMode和ts3client_getPlaybackModeList/ts3client_getCaptureModeList

•结果
接收以NULL结尾的数组{{char*deviceName,char*deviceID},{char*deviceName,char*deviceID},…,NULL}的变量的地址。
除非函数返回错误,否则需要使用ts3client_freeMemory释放数组元素和数组本身。
成功时返回ERROR_ok,否则返回public_errors.h中定义的错误代码。发生错误时,结果数组未初始化,不能释放

未签名的int ts3client\u startConnection(serverConnectionHandlerID、标识、ip、端口、昵称、defaultChannelArray、defaultChannelPassword、serverPassword)

uint64服务器连接handlerid;常量字符*标识;常数 字符*ip;无符号整数端口;常量字符*昵称;常量字符** defaultChannelArray;//这就是我不懂的东西* 默认通道密码;const char*serverPassword

参数 •服务器连接句柄ID
此服务器连接的唯一标识符。使用ts3client\u spawnNewServerConnectionHandler创建
•身份
客户身份。必须通过调用ts3client_createIdentity来创建此字符串。
请注意,应用程序只应创建一次标识,将字符串存储在本地,并在将来的连接中重新使用它。
•ip
TeamSpeak 3服务器的主机名或IP。 如果传递的是主机名而不是IP,则客户端库将尝试将其解析为IP,但在解析过程中,函数可能会异常长的时间阻塞。如果您依赖函数快速返回,建议您自己解析主机名(例如异步解析),然后使用IP而不是主机名调用ts3client_startConnection。
•端口
TeamSpeak 3服务器的UDP端口,默认为9987。TeamSpeak 3使用UDP。将来可能会添加对TCP的支持。
•昵称 登录时,客户端尝试在连接的服务器上使用此昵称。注意,这不一定是实际分配的昵称,因为服务器可以修改昵称(“gandalf_1”而不是请求的“gandalf”)或拒绝阻止的名称。
•defaultChannelArray
斯特林
function ts3client_getClientList(serverConnectionHandlerID: UInt64; 
  out result: PAnyID): Cardinal; cdecl; external '...';
var
  ids: PAnyID;
  idarr: TArray<anyID>;
....
ts3check(ts3client_getClientList(serverConnectionHandlerID, ids));
try
  idarr := GetIDs(ids);
finally
  ts3check(ts3client_freeMemory(ids));
end;
function ts3client_getErrorMessage(error: Cardinal; 
  out errormsg: PAnsiChar): Cardinal; cdecl; external '...';

....

procedure ts3check(error: Cardinal);
var
  errormsg: PAnsiChar;
  errorstr: string;
begin
  if error = ERROR_ok then
    exit;

  if ts3client_getErrorMessage(error, @errormsg) <> ERROR_ok then
    raise Ets3Error.CreateFmt('Error code %d', [error]);

  errorstr := UTF8ToUnicodeString(errormsg);
  ts3client_freeMemory(errormsg);
  raise Ets3Error.CreateFmt('Error code %d (%s)', [error, errorstr]);
end;
function GetIDs(const ids: PAnyID): TArray<anyID>;
var
  Count: Integer;
  p: PAnyID;
begin
  Count := 0;
  p := ids;
  while p^ <> 0 do 
  begin
    inc(Count);
    inc(p);
  end;

  SetLength(Result, Count);
  Count := 0;
  p := ids;
  while p^ <> 0 do 
  begin
    Result[Count] := p^;
    inc(Count);
    inc(p);
  end;
end;