Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7613855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:15:19+00:00 2026-05-31T02:15:19+00:00

I have a DLL from which I need to P/Invoke the following C method:

  • 0

I have a DLL from which I need to P/Invoke the following C method:

int DAStart(
    HANDLE hOpen,
    char* IPAddress,
    int IPPort,
    int threadPriority,
    char* name,
    char* password,
    char* userName)

Using the P/Invoke Assistant and my own research, I’ve come up with the following C# signature:

[DllImportAttribute("<libName>", EntryPoint="DAStart")]  
static extern  int DAStart(  
    IntPtr hOpen,  
    [MarshalAs(Unmanaged.LPStr)] StringBuilder IPAddress,
    int IPPort,
    int threadPriority, 
    [MarshalAs(Unmanaged.LPStr)] StringBuilder name, 
    [MarshalAs(Unmanaged.LPStr)] StringBuilder password,   
    [MarshalAs(Unmanaged.LPStr)] StringBuilder userName);

Now, I’m doing the call in the following way:

int port = 3000;
int threadPriority = 20;

DAStart(
    this.nativeDllHandle, // an IntPtr class field  
    new StringBuilder("10.0.10.1"),
    int port,
    int threadPriority,
    new StringBuilder("admin"),
    new StringBuilder("admin"),
    new StringBuilder("admin"));

Now, sometimes this works just fine, but something I get a Win32 Error 1008 - An attempt was made to reference a token that does not exist on following calls to this library.

Could it be that my StringBuilder objects get garbage collected so that the reference no longer exist if the native code tries to use it? Should I keep a reference for each one of them?

Would an IntPtr be better solution for passing my strings in that case?

** UPDATE **

This is all the API documentation I have for DAStart:

Inputs
HANDLE hInfo The handle returned by the DAOpen
char *IPAdress_in IP Address of the TMEE Server
int IPPort Console Port of the TMEE Server (default is port 3000)
int threadPriority The thread priority for the send file thread.
char *name Not used in Hardware DLL
char *password Not used in Hardware DLL
char *username Not used in Hardware DLL

Returns
ERROR_SUCCESS 0
ERROR_BAD_HANDLE -1
ERROR_BIND_FAILED -10

Comments
The DAStart API connects the client dll to the active TMEE Server service. The client thread is started with a priority set to the threadPriority parameter. The IP address parameter must be set to the address of the TMEE Server. The port parameter must be set to the port the TMEE Server listens on for Console connections (the default port the Consoles use is 3010). The Console thread is started with a priority set to the threadPriority parameter.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T02:15:20+00:00Added an answer on May 31, 2026 at 2:15 am

    In the comments you indicate that the DLL takes a copy of the char* pointers (and not the contents of the strings) and then modifies the contents of the strings after DAStart returns.

    In the face of this very unconventional interface design your only option is to take charge of the marshaling of the string parameters. You cannot use StringBuilder since the char* passed to the native code is valid only during the pinvoke call. It cannot be relied upon to be valid after the pinvoke call returns.

    So your only solution is to pass the string parameters as IntPtr. Allocate the memory with Marshal.StringToHGlobalAnsi. Pass the resulting IntPtr to DAStart. When you are sure the DLL is done with the pointer, deallocate with Marshal.FreeHGlobal.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a DLL from which I need to P/Invoke the following C method:
I have a DLL from which I need to P/Invoke the following C method:
I have an unmanaged (C/C++) DLL which I need to call from a C#
I have a DLL file from which I need the memory address of a
I have a .NET dll which needs to read it's config settings from it's
I have a method I want to import from a DLL and it has
We have inherited VB6 dll which we need to make changes to. We have
I have a c++ dll which I need to debug. Due to the circumstances
I have an Asp.net application which require a third-part .dll from other department(In fact,it
I have dll which accepts Pointer to array of bytes from C++ and try

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.