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

  • Home
  • SEARCH
  • 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 6250673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:28:14+00:00 2026-05-24T13:28:14+00:00

I have a C++ MFC regular DLL I am calling with the following: public

  • 0

I have a C++ MFC regular DLL I am calling with the following:

public static class Access3rdPartyDLL
{
  public static string FilePath;
  [DllImport("3rdparty.dll")]  
  // I have also tried LPWStr
  public static extern long Download([MarshalAs(UnmanagedType.LPStr)]string sDownloadFile,
                                   int iDeviceNum
                                   ...);

  public static long DownloadToDevice()
  {
    long result;
    string FilePath = "C:\\myfile.txt"
    result = Download(FilePath, 1, ...);
    // check if success or error
    if(result > 0)
    ...
  }
}

I get an error back from the DLL saying “File: ‘C:\myfile.txt’ not found. But its there…
I have also tried using StringBuilder but this also fails.

Could this be a problem with the DLL or am I doing something wrong?
I found this current code here: SO: equivalent char* in C#

EDIT: I have done this in C++ before and this code works:

extern "C" __declspec(dllimport) HRESULT __stdcall Download(char* sDownloadFile, int ...  

which I call with:

HRESULT result = Download(file_for_download, 1, .. // where file_for_download is a char*
  • 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-24T13:28:14+00:00Added an answer on May 24, 2026 at 1:28 pm

    The only thing wrong with the P/invoke is that you are using C# long which is 64 bits, but an HRESULT is only 32 bits.

    You have matching calling conventions, default marshalling for managed string is char* on the unmanaged side.

    Mismatching return value size would not explain why your C# code receives a string message File: 'C:\myfile.txt' not found so your main problem most likely lies in the code that you haven’t shown us.

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

Sidebar

Related Questions

I have an MFC extension DLL that I've written. It contains derived classes of
I have an unmanaged C++ MFC dll that was developed in VS 6.0. I
I have a MFC extension DLL which I want to use in a C#
I have an MFC DLL that is loaded by a 3rd party application. How
I have an mfc resource only dll's with strings and menus, but i want
I have an MFC project that imports a C type DLL for use. This
I have an installation program (just a regular C++ MFC program, not Windows Installer
I have a MFC application compiled with MBCS. We are also using the CMFCMenuBar
I have created a regular dll where I have one method GetRecord to allocate
I have this MFC app with the following piece of code to check for

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.