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 9178351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:31:52+00:00 2026-06-17T17:31:52+00:00

I have a C# gui calling an unmanaged C++ dll. callbacks are used for

  • 0

I have a C# gui calling an unmanaged C++ dll. callbacks are used for dll -> gui messaging.

in the dll a LPTSTR is created that may contain ‘\0’ characters. that string needs to be passed back via a callback parameter to the gui, in full, via the callback.

unfortunately i can only get the string passed to the gui up until the null character. seems the marshaling cuts the string.

// C# callback declarations
public delegate bool callbackDelegate(int iEvent, [MarshalAs(UnmanagedType.LPWStr)] string SomeString);
private callbackDelegate callbackDelegateInstance;

// instantiating and calling the callback in C#
callbackDelegateInstance = new callbackDelegate(CallbackHandler);
DLLCallbackFunction(callbackDelegateInstance);

// C# callback handler
private bool CallbackHandler(int iEvent, [MarshalAs(UnmanagedType.LPWStr)] string SomeString)
{
    // SomeString only contains characters up until the null char
}

Is there a way to return the entire string, including null chars from the dll?

I do have access to dll and gui code.

  • 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-06-17T17:31:53+00:00Added an answer on June 17, 2026 at 5:31 pm

    You could marshal it as a raw byte array instead of an LPTSTR. If your data is not a constant size, you will have to add an additional length parameter.

    The delegate would be declared something like this:

     public delegate bool callbackDelegate(int iEvent, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] byte[] data, int dataCount);
    

    And on the unmanaged side:

    typedef void (__stdcall *callbackDelegate)(int iEvent, const char* data, int size);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So basically I have a plugin dll that is loaded by a GUI-Application. In
I have a GUI app that is getting to be quite slow. I want
I have a GUI that is going to do a lot of disparate tasks.
I have a GUI C++ application (Visual Studio 2008) that needs to be converted
I have a GUI tool that manages state sequences. One component is a class
I have a PyGTK GUI that has a gtk.Table. Pressing one button will generate
I have a class that draws a GUI, using gtk. Clicking a button will
I have a bunch of auto-generated code (coming from Ranorex GUI testing tool) that
I have a c# windows form application that has a similar GUI functionality as
I have made a java GUI program and have added a jList on that

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.