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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T05:59:58+00:00 2026-05-25T05:59:58+00:00

I have written a C++ DLL with the following function exported extern C BOOL

  • 0

I have written a C++ DLL with the following function exported

extern "C" BOOL WINAPI SetUserPassword(const char* u, const char* p)

When calling this from C# I am using the following code

[DllImport("mydll.dll")]
private static extern int SetUserPassword(String user, String password);

Now when SetUserPassword is called I only get the first letter of each parameter. I did some googling and found that String was perhaps not the best to use so tried using IntPtr and Marshal.StringToBSTR() but this didn’t work either.

How should this be structured correctly? I am able to modify the C++ DLL if required.

  • 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-25T05:59:59+00:00Added an answer on May 25, 2026 at 5:59 am

    The only thing that makes sense is that your C# code is actually:

    [DllImport("mydll.dll", CharSet = Unicode)]
    private static extern int SetUserPassword(String user, String password);
    

    When you do this you pass a wide character based string to your C++ code and since it expects single byte characters it interprets the 0 byte in the second half of the first two byte character as a string terminator.

    You should write:

    [DllImport("mydll.dll", CharSet = Ansi)]
    private static extern int SetUserPassword(String user, String password);
    

    Or in fact you could write it exactly as in your question because Ansi is the default.


    And in fact it turns out that you are on CE which does not support Ansi character set and so the only reasonable solution is to make your C++ code accept wide character strings.

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

Sidebar

Related Questions

I have a third-party (Win32) DLL, written in C, that exposes the following interface:
I have a test suite DLL written in C# that uses Selenium.This is then
I have a very simple DLL written in unmanaged C++ that I access from
I have a code example from a SDK, the DLL is written in C
I have a DLL written in C#. In this DLL there is a class
I have written a DLL that uses MS Word to spell check the content
I have written a COM dll, and wish to register it using regsvr32 myComdll.dll
I have written a C# class library (DLL) and wondering the quickest way to
I have written some sample program and DLL to learn the concept of DLL
I have written a c# program that calls a c++ dll that echoes the

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.