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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:40:23+00:00 2026-05-17T23:40:23+00:00

I have a static library. This library have the following function defined int WriteData(LPTSTR

  • 0

I have a static library. This library have the following function defined

int WriteData(LPTSTR s)

The sample to call the function is

LPTSTR s = (LPTSTR) L"Test Data";   
int n = WriteData(s);

WriteData return 0 on success and -1 on failure.

I am writing a dynamic DLL to export this function.

int TestFun(LPTSTR lpData)
{
   return  WriteData(lpData);
}

A C++ test application result

LPTSTR s = (LPTSTR) L"Test Data";   
TestFun(s);  //OK  return 0

LPTSTR s = (LPTSTR) "Test Data";    
TestFun(s);  //Fail  return -1

I have to call it from a c# application. I assume my DLL-Import signature would be:

        [DllImport("Test.dll")]
        private static extern int TestFun(String s);

My question is very simple How can i call it from .Net?
As you can see i have control over

TestFun(LPTSTR lpData)

but no control over

WriteData(LPTSTR s)

Thanks everybody for their input. So far i am stuck on casting. I think my problem would be solved when i woul be able take input from user and write 2 line for casting in place of following line.

   LPTSTR s = (LPTSTR) L"Test Data"); //<= How can ii take input from user and 
    TestFun(s);  //OK  return 0
  • 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-17T23:40:23+00:00Added an answer on May 17, 2026 at 11:40 pm

    The L prefix makes the string a wchar_t string.
    You can use the Windows API function MultiByteToWideChar to convert an ANSI string to a wchar_t string.

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

Sidebar

Related Questions

I have got a C function in a static library, let's call it A,
I have the following static function: static inline HandVal StdDeck_StdRules_EVAL_N( StdDeck_CardMask cards, int n_cards
I have a C# library with the following Namespace/Class: namespace Helper { public static
I have a static library written in C++ and I have a structure describing
I have a static library *.lib created using MSVC on windows. The size of
I have a static linkable library of C and Fortran routines compiled and linked
Is it possible to have a C static library API, which uses C++ internally
I have a binary file - Windows static library (*.lib). Is there a simple
I have two projects, a Cocoa iPhone application and a static library which it
I have several static factory patterns in my PHP library. However, memory footprint is

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.