TeamSpeak3 Client SDK - ts3client_startConnection()的defaultChannelArray参数

时间:2016-08-25 12:35:17

标签: c# teamspeak

我正在尝试使用默认的其他频道连接到我的TeamSpeak3服务器。

文档说:

  

-defaultChannelArray

     

定义TeamSpeak 3服务器上通道路径的字符串数组。如果频道存在且用户拥有足够的权限并在需要时提供正确的密码,则该频道将在登录时加入。

     

要定义任意级别子通道的路径,请创建一个详细说明默认通道位置的通道名称数组(例如“祖父母”,“父级”,“mydefault”,“”)。该数组以空字符串终止。

     

传递NULL以加入服务器默认频道。

这是函数签名:

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 = "";
  

ts3_client_minimal_sample.exe中发生未处理的“System.AccessViolationException”类型异常

     

附加信息:尝试读取或写入受保护的内存。这通常表明其他内存已损坏。

如何从C#到C ++ DLL获取字符串数组,而不使用String []?

谢谢!

1 个答案:

答案 0 :(得分:0)

谢谢你,凤凰!

原始答案没有帮助,但进一步回答了问题:Link

更新的代码:

string[] defaultChannelArray

基本上,我将DllImport从ref string defaultChannelArray更改为@WebServlet(urlPatterns = {"/blah"}, loadOnStartup = -1000) public class MyServlet implements ServletContextListener { @Override public void contextInitialized(ServletContextEvent sce) { AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(MyConfiguration.class); Application.logitContextInitializer = context.getBean(LogitContextInitializer.class); Application.configWsClientInitializer = context.getBean(ConfigWsClientInitializer.class); } @Override public void contextDestroyed(ServletContextEvent sce) { } } 。作为该线程上提到的另一位评论者,C#数组作为引用传递。然后我传递了一个简单的C#字符串数组。工作完美!

我让它变得比它需要的更复杂。