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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:09:33+00:00 2026-06-14T11:09:33+00:00

I’m calling a C++ DLL from C# via P/Invoke using DllImport. The DLL is

  • 0

I’m calling a C++ DLL from C# via P/Invoke using DllImport. The DLL is produced by a third party and is x86 only (so our C# code is built as x86 as well).

If I call a certain function on the DLL from a console application, I always get one result which is correct. The function takes a file path and extracts some information from the file.

The signature of the function is:

private static extern int Function(
    string str1,
    int bool1,
    ref uint outUint1,
    ref uint outUint2,
    ref uint outUint3,
    ref double outDouble1,
    ref double outDouble2,
    StringBuilder outStr1);

And the unexpected result is in one of the ref uint parameters.

If I create a unit test and call the exact same code (with all parameters and such hardcoded), I get an entirely different result, which is incorrect. The incorrect result is always the same. I’ve tried both MSTest and NUnit tests using various different runners with the same result.

Cases producing correct results:

  • Console app
  • Winforms app
  • Console app running the code but launched from a Unit Test (NUnit)

Cases producing incorrect results:

  • Test run from Resharper Test Runner (NUnit)
  • Test run from Visual Studio Test Runner (MSTest)
  • Test run from NUnit GUI Test Runner
  • Test run from NUnit Console Test Runner

My test environment is Windows 8 and the C# is built for x86 targeting .NET framework 4.

Do any of you have any ideas about what’s causing this issue or what I can do to debug it further?

I will definitely be attempting to contact the third party that created the DLL, but having a good idea about exactly what’s causing this issue would substantially increase the chance of it getting resolved.

  • 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-14T11:09:35+00:00Added an answer on June 14, 2026 at 11:09 am

    It sounds like the “filepath” it is expecting may be relative to the working directory, or the working directory or even the application directory is important to the dll.

    That dll may also try to reference other dll’s in its directory, but can’t find them because it was loaded from its own folder instead of the exe running in its directory.

    About half way down this page it describes the search order for dll resolution:

    1. The directory from which the application loaded.

    2. The current directory.

    3. The system directory. Use the GetSystemDirectory function to get the
      path of this directory.

    4. The 16-bit system directory. There is no function that obtains the
      path of this directory, but it is searched.

    5. The Windows directory. Use the GetWindowsDirectory function to get
      the path of this directory.

    6. The directories that are listed in the PATH environment variable.
      Note that this does not include the per-application path specified
      by the App Paths registry key. The App Paths key is not used when
      computing the DLL search path.

    Hope that helps.

    EDIT: Another idea… You could go and write a wrapper for that DLL so that it returns the correct values, and make an interface that works with your unit tester built into your wrapper.

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

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
Let's say I'm outputting a post title and in our database, it's Hello Y’all
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.