TeamSpeak3 客户端 SDK -- ts3client_startConnection() 的 defaultChannelArray 参数
TeamSpeak3 Client SDK -- defaultChannelArray argument for ts3client_startConnection()
我正在尝试使用与默认通道不同的通道连接到我的 TeamSpeak3 服务器。
文档说:
-defaultChannelArray
String array defining the path to a channel on the TeamSpeak 3 server. If the channel exists and the user has sufficient rights and supplies the correct password if required, the channel will be joined on login.
To define the path to a subchannel of arbitrary level, create an array of channel names detailing the position of the default channel (e.g. "grandparent", "parent", "mydefault", ""). The array is terminated with a empty string.
Pass NULL to join the servers default channel.
函数签名如下:
unsigned int ts3client_startConnection(uint64 serverConnectionHandlerID,
const char* identity,
const char* ip,
unsigned int port,
const char* nickname,
const char** defaultChannelArray,
const char* defaultChannelPassword,
const char* serverPassword);
TeamSpeak 的 C# 示例运行良好,使用的方法如下:
string defaultarray = "";
/* Connect to server on localhost:9987 with nickname "client", no default channel, no default channel password and server password "secret" */
error = ts3client.ts3client_startConnection(scHandlerID, identity, "localhost", 9987, "client", ref defaultarray, "", "secret");
if (error != public_errors.ERROR_ok) {
Console.WriteLine("Error connecting to server: 0x{0:X4}", error);
Console.ReadLine();
return;
}
在他们的代码中导入 DLL 时,他们使用:
[DllImport("ts3client_win32.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "ts3client_startConnection", CharSet = CharSet.Ansi)]
public static extern uint ts3client_startConnection(uint64 arg0, string identity, string ip, uint port, string nick, ref string defaultchannelarray, string defaultchannelpassword, string serverpassword);
现在回答我的问题:使用 C#,我试图将非默认通道数组传递给该方法,但效果不佳。
我尝试了以下方法但没有用:
string defaultarray = """name"", """"";
string defaultarray = "name,";
我在做除以下以外的任何事情时总是出错:
string defaultarray = "";
An unhandled exception of type 'System.AccessViolationException' occurred in ts3_client_minimal_sample.exe
Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
如何在不使用 String[] 的情况下将字符串数组从 C# 获取到 C++ DLL?
谢谢!
谢谢你,凤凰!
原来的答案没有帮助,但下面的答案有帮助:esskar's answer
更新代码:
[DllImport("ts3client_win32.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "ts3client_startConnection", CharSet = CharSet.Ansi)]
public static extern uint ts3client_startConnection(uint64 arg0, string identity, string ip, uint port, string nick, string[] defaultchannelarray, string defaultchannelpassword, string serverpassword);
...
string[] defaultarray = new string[] { "name", ""};
/* Connect to server on localhost:9987 with nickname "client", no default channel, no default channel password and server password "secret" */
error = ts3client.ts3client_startConnection(scHandlerID, identity, "localhost", 9987, "client", defaultarray, "password", "secret");
if (error != public_errors.ERROR_ok) {
Console.WriteLine("Error connecting to server: 0x{0:X4}", error);
Console.ReadLine();
return;
}
基本上,我将 DllImport 从 ref string defaultChannelArray
更改为 string[] defaultChannelArray
。正如该线程的另一位评论者所提到的,C# 数组作为引用传递。然后我传递了一个简单的 C# 字符串数组。工作完美!
我让它变得比需要的更复杂。
我正在尝试使用与默认通道不同的通道连接到我的 TeamSpeak3 服务器。
文档说:
-defaultChannelArray
String array defining the path to a channel on the TeamSpeak 3 server. If the channel exists and the user has sufficient rights and supplies the correct password if required, the channel will be joined on login.
To define the path to a subchannel of arbitrary level, create an array of channel names detailing the position of the default channel (e.g. "grandparent", "parent", "mydefault", ""). The array is terminated with a empty string.
Pass NULL to join the servers default channel.
函数签名如下:
unsigned int ts3client_startConnection(uint64 serverConnectionHandlerID,
const char* identity,
const char* ip,
unsigned int port,
const char* nickname,
const char** defaultChannelArray,
const char* defaultChannelPassword,
const char* serverPassword);
TeamSpeak 的 C# 示例运行良好,使用的方法如下:
string defaultarray = "";
/* Connect to server on localhost:9987 with nickname "client", no default channel, no default channel password and server password "secret" */
error = ts3client.ts3client_startConnection(scHandlerID, identity, "localhost", 9987, "client", ref defaultarray, "", "secret");
if (error != public_errors.ERROR_ok) {
Console.WriteLine("Error connecting to server: 0x{0:X4}", error);
Console.ReadLine();
return;
}
在他们的代码中导入 DLL 时,他们使用:
[DllImport("ts3client_win32.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "ts3client_startConnection", CharSet = CharSet.Ansi)]
public static extern uint ts3client_startConnection(uint64 arg0, string identity, string ip, uint port, string nick, ref string defaultchannelarray, string defaultchannelpassword, string serverpassword);
现在回答我的问题:使用 C#,我试图将非默认通道数组传递给该方法,但效果不佳。
我尝试了以下方法但没有用:
string defaultarray = """name"", """"";
string defaultarray = "name,";
我在做除以下以外的任何事情时总是出错:
string defaultarray = "";
An unhandled exception of type 'System.AccessViolationException' occurred in ts3_client_minimal_sample.exe
Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
如何在不使用 String[] 的情况下将字符串数组从 C# 获取到 C++ DLL?
谢谢!
谢谢你,凤凰!
原来的答案没有帮助,但下面的答案有帮助:esskar's answer
更新代码:
[DllImport("ts3client_win32.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "ts3client_startConnection", CharSet = CharSet.Ansi)]
public static extern uint ts3client_startConnection(uint64 arg0, string identity, string ip, uint port, string nick, string[] defaultchannelarray, string defaultchannelpassword, string serverpassword);
...
string[] defaultarray = new string[] { "name", ""};
/* Connect to server on localhost:9987 with nickname "client", no default channel, no default channel password and server password "secret" */
error = ts3client.ts3client_startConnection(scHandlerID, identity, "localhost", 9987, "client", defaultarray, "password", "secret");
if (error != public_errors.ERROR_ok) {
Console.WriteLine("Error connecting to server: 0x{0:X4}", error);
Console.ReadLine();
return;
}
基本上,我将 DllImport 从 ref string defaultChannelArray
更改为 string[] defaultChannelArray
。正如该线程的另一位评论者所提到的,C# 数组作为引用传递。然后我传递了一个简单的 C# 字符串数组。工作完美!
我让它变得比需要的更复杂。