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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:33:34+00:00 2026-05-13T23:33:34+00:00

I have an existing app which P/Invokes to a DLL residing in the same

  • 0

I have an existing app which P/Invokes to a DLL residing in the same directory as the app itself.

Now (due to the fact that Canon produces one of the crappiest API’s around) I need to support two versions of this API and determine at run-time which one I should use (old or new). Since the DLLs have the same name (the first one loads other DLLs with same names so just renaming the first one won’t help me) I must keep them in different directories.

Hence my question: what options do I have to control what directory the DLL given in a DllImport declaration uses?

I guess I can start out by trying any of these two ideas:

1) Use “SetDllDirectory” to set my desired directory before doing the first P/Invoke and then reset it afterwards.

2) Load the desired DLL manually using “LoadLibraryEx” and hope that that will do the trick.

But are there any more “.NET:ish way” to try out first?

UPDATE: I realize that I can stuff all access to the DLLs in two separate .Net assemblies and then place each one of them in a separate directory with the corresponding API files. Then I can load the proper .Net assembly dynamically and the loading of the correct DLL whould happen automatically. Any reason that shouldn’t work?

I can think of one: how would I go about debugging this stuff? It is possible to tell Visual Studio that an assembly (contained in my solution) shall be placed in a subdirectory and debugged from there?

  • 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-13T23:33:34+00:00Added an answer on May 13, 2026 at 11:33 pm

    My condolences, I’ve seen one of the APIs and it was indeed shockingly bad. The bigger problem is that you’ll need to be able to convince Windows to find the DLL. They won’t be in your .exe directory so the default won’t work. Using SetDllDirectory() would work, using Environment.CurrentDirectory does too. LoadLibrary cannot work, the P/Invoke marshaller will use LoadLibrary itself.

    If it is at all an option, you can use different names for the two P/Invoke declarations, using different arguments for the DllImport() constructor and using the EntryPoint attribute. Doesn’t sound like that will fly.

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

Sidebar

Related Questions

We have an existing game app that is now defunct and is just sitting
I have an existing app in which I added the json-framework. Now it won't
I have an existing large(ish) PHP web app (using Apache and MySQL) which now
I have an existing web app that has a data layer and a bll
I have a legacy PHP/MySQL app that calls mysql_connect(). Tons of existing downstream code
I have an existing app in which I made the mistake of using String.GetHashCode
Ubuntu 11.10, Python 2.6. Background: I have an existing Python app that is using
I have an existing web app which uses Struts for the forward-action... I am
I have an existing Rails internal app, that handles inventory, invoicing, order taking, labeling,
We have an existing app which is mostly JSP based for front end and

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.