Community Forums Today's Posts     Member List     Archive    
Results 1 to 10 of 10
  1. #1
    Join Date
    Feb 2010
    Location
    Germany
    Posts
    11

    Solved PInvokeimbalance (C#, SDK 3)

    Hello

    using the SDK simple client sample with C# and .net 4 on my Win7 64bit, but compiling it to x86 due to compatibility issues results me with a PInvokeImbalance error with this line:

    Code:
    uint error = ts3client.ts3client_initClientLib(ref cbs, ref cbs_rare, LogTypes.LogType_CONSOLE, null, "");
    which is defined here:
    Code:
    [DllImport("ts3client_win32.dll", EntryPoint = "ts3client_initClientLib")]
    			public static extern uint ts3client_initClientLib(ref client_callback_struct arg0, ref client_callbackrare_struct arg1, LogTypes arg2, string arg4, string arg5);
    Compiling it as x64 is working correctly. I would so far prefer the x86 way since not everyone is owning an x64 system yet ...

    Thank you for any hints

  2. #2
    Join Date
    Jul 2002
    Location
    Germany
    Posts
    2,836
    Hi,

    first off, I must confess I have zero knowledge of C#, but from searching "PInvokeImbalance" I found http://social.msdn.microsoft.com/For...-02b2324bfcd7/ which makes references about the calling convention being important. As the SDK docs say, the TS3 SDK uses cdecl calling convention (and not stdcall). I hope this helps.

  3. #3
    Join Date
    Dec 2009
    Location
    Frankfurt/Main
    Posts
    15
    There should be an ohter mistake in the Example. Also the callbacks in the csharp example are the old ones. Will it beeing updated?

  4. #4
    Join Date
    Feb 2010
    Location
    Germany
    Posts
    11
    That hint about the CallingConvention was fine. Thank you!

    Now it stops with an "System.AccessViolationException - Trying to read/write protected memory." with this line:
    ts3client.ts3client_startConnection(scHandlerID, identity, "127.0.0.1", 9987, "client", ref defaultarray, "", "secret");
    I'd be happy if we can solve this too

  5. #5
    Join Date
    Mar 2010
    Location
    Germany
    Posts
    181
    Quote Originally Posted by soccy View Post
    That hint about the CallingConvention was fine. Thank you!

    Now it stops with an "System.AccessViolationException - Trying to read/write protected memory." with this line:


    I'd be happy if we can solve this too
    This might help

  6. #6
    Join Date
    Feb 2010
    Location
    Germany
    Posts
    11
    Thank you for trying to help.
    For bad luck the site about the AccessViolation is not really pointing to what might cause that read/write error with x86 compilation. It works for x64 using the exactly same syntax.
    The line

    ts3client.ts3client_startConnection(scHandlerID, identity, "127.0.0.1", 9987, "client", ref defaultarray, "", "secret");
    refers to this definition:

    [DllImport("ts3client_win64.dll", 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);
    and the identity and defaultarray are defined like this:

    string identity = Marshal.PtrToStringAnsi(identityPtr);
    string defaultarray = "";
    One of these seem to cause the accessviolation, but how to define them in another way ...?

    I wonder, if the x86 version of the .DLL is working for anyone? I tested it also on a native 32bit Vista system with exactly the same error (Accessviolation) in the same line.

  7. #7
    Join Date
    Feb 2010
    Location
    Germany
    Posts
    11
    Thank you for trying to help.
    For bad luck the site about the AccessViolation is not really pointing to what might cause that read/write error with x86 compilation in this case. It works for x64 using the exactly same syntax.
    The line

    ts3client.ts3client_startConnection(scHandlerID, identity, "127.0.0.1", 9987, "client", ref defaultarray, "", "secret");
    refers to this definition:

    [DllImport("ts3client_win32.dll", EntryPoint = "ts3client_startConnection", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
    public static extern uint ts3client_startConnection(uint64 arg0, string identity, string ip, uint port, string nick, ref string defaultchannelarray, string defaultchannelpassword, string serverpassword);
    and the identity and defaultarray are defined like this:

    string identity = Marshal.PtrToStringAnsi(identityPtr);
    string defaultarray = "";
    One of these seem to cause the accessviolation, but how to define them in another way ...?

    I wonder, if the x86 version of the .DLL is working for anyone? I tested it also on a native 32bit Vista system with exactly the same error (Accessviolation) in the same line.

  8. #8
    Join Date
    Aug 2011
    Posts
    1
    Hello everyone,

    I have tested it on a Windows 7, 32bit System, using Visual C# 2010 Express, and I get the exact same error on the same line.

    I've also tried to alter the two lines you mentioned, but with no success.

    As we are stuck at the same point I can't really helo you, but I'm really interested in hearing any other ideas on what to do...

    Valandur


    EDIT:
    Interesting is the fact that if you open the example solution for C# made by TeamSpeak then the default compile configuration is x64. This could mean that the TeamSpeak developers did not test the SDK on a 32bit System.

  9. #9
    Join Date
    Feb 2010
    Location
    Germany
    Posts
    11
    Hello again

    so this is meaning, that the 32bit version of the dll is not working with managed code, right?
    That's sad since this means you cannot code for a wider audience

    Could any TeamSpeak official put some light into this matter (i.ex. confirming it is not working or bringing a fixed version or give us a hint on how to do it right or some other sign of life hehehe)?

    Thank you

  10. #10
    Join Date
    Jun 2008
    Location
    Krün, Germany
    Posts
    464
    For reference, the solution should be here: http://forum.teamspeak.com/showthrea...334#post295334

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •