EzDevInfo.com

dll interview questions

Top dll frequently asked interview questions

Visual Studio: how to set path to dll?

I developed an application that depends on a dll. When I debug my app, the app would complain that "This application has failed to start because xxx.dll was not found."

So what I have to do is to copy the dll into the same directory as my .vcproj.

Is there a way to set the project to look for the dll in (preferably) some relative path or (not preferred) some absolute path?

Similar concept to how we set include and lib path in the project settings.

EDIT: Sorry for all the confusion: I meant when I debug my app (hitting F5) the above error would pop up.


Source: (StackOverflow)

When to use dynamic vs. static libraries

When creating a class library in C++, you can choose between dynamic (.dll) and static (.lib) libraries. What is the difference between them and when is it appropriate to use which?


Source: (StackOverflow)

Advertisements

Embedding DLLs in a compiled executable

You know, I haven't seen a good answer for this anywhere. Is it possible to embed a pre-existing DLL into a compiled C# executable (so that you only have one file to distribute)? If it is possible, how would one go about doing it?

Normally, I'm cool with just leaving the DLLs outside and having the setup program handle everything, but there have been a couple of people at work who have asked me this and I honestly don't know.


Source: (StackOverflow)

How do I register a DLL file on Windows 7 64-bit?

I have tried to use the following code:

cd c:\windows\system32
regsvr32.exe dllname.ax

But this is not working for me. How can I register a DLL file on Windows 7 with a 64-bit processor?


Source: (StackOverflow)

java.lang.UnsatisfiedLinkError no *****.dll in java.library.path

How can I load a custom dll file in my web application? I tried following ways but its failing.

  • copied all required dlls in system32 folder and tried to load one of them in Servlet constructor System.loadLibrary
  • Copied required dlls in tomcat_home/shared/lib and tomcat_home/common/lib
  • all these dlls are in WEB-INF/lib of the web-application

Source: (StackOverflow)

Partial classes in separate dlls

Is it possible to have two parts (same namespace, same class name) to a partial class in separate DLLs?


Source: (StackOverflow)

How can I test a windows dll to determine if it is 32bit or 64bit? [duplicate]

This question already has an answer here:

I'd like to write a test script or program that asserts that all dlls in a given directory are of a particular build type.

I would use this as a sanity check at the end of a build process on an sdk to make sure that the 64bit version hasn't somehow got some 32bit dlls in it and vice versa.

Is there an easy way to look at a dll file and determine its type?

The solution should work on both xp32 and xp64.


Source: (StackOverflow)

Why do 64-bit DLLs go to System32 and 32-bit DLLs to SysWoW64 on 64-bit Windows?

I would like to know when do we need to place a file under

C:\Windows\System32 or C:\Windows\SysWOW64, on a 64-bits windows system.

I had two DLL's, one for 32-bit, one for 64-bit.

Logically, I thought I'd place the 32-bit DLL under C:\Windows\System32, and the 64-bit DLL under C:\Windows\SysWOW64.

To my surprise, it's the other way around! The 32-bit one goes into C:\Windows\SysWOW64, and the 64-bit DLL goes into C:\Windows\System32.

Very confusing stuff. What's the reason behind this? Thanks in Advance.


Source: (StackOverflow)

Win 7, 64 bit, dll problems

I have a problem with our executable. I'm running this C++ 32-bit executable on my Win-7 64-bit development box that also has all those MS applications (Visual Studio 2008 + 2010, TFS, SDK, MS Office)... And its still running just fine.

Now I got the client installation of the very same program and wwas asked to test it with a clean Win-7 installation. Thus i got I Win-7 64-bit VM Ware and updated it to Win-7 SP 1 (the very same version my developer box is tunning). But while on my developer box everything is fine the program does not work with the VW Ware (30 days trial) box.

The x86 dependency walker is telling me that the following DLLs are missing:

  • API-MS-WIN-CORE-COM-L1-1-0.DLL
  • API-MS-WIN-CORE-WINRT-ERROR-L1-1-0.DLL
  • API-MS-WIN-CORE-WINRT-L1-1-0.DLL
  • API-MS-WIN-CORE-WINRT-ROBUFFER-L1-1-0.DLL
  • API-MS-WIN-CORE-WINRT-STRING-L1-1-0.DLL
  • API-MS-WIN-SHCORE-SCALING-L1-1-0.DLL
  • DCOMP.DLL
  • GPSVC.DLL
  • IESHIMS.DLL

I googled for those API-MS-WIN-... dlls and found they should actually already be part of Win-7 (some sites claiming the belong to Win-8 and Win 2012 server though).

I already tried the suggested fixes I found, which are:

  • running 'sfc /scannow'
  • installing Visual Studio 2008 SP1 runtime executables

But that didn't solve anything. :-(

Side note: My development box does not have them either, and does not seem to need them. For example the user32.dll on my box does not link against one of those, while the installation on the VM ware does.

Any idea on how to fix this issue? I tried to find a suitable download / fix on the MS pages but failed.

Regards, Thomas


After solving my issue I wanted to report what I found out, and I can't post this as an answer because the question has been closed.

Actually all the DLLs reported missing by the dependency walker tool, nameley those

* API-MS-WIN-CORE-...  

type DLLs were not part of the actual problem.

In my case the registration of 3 OCX files was missing and after that everything was just fine, BUT dependency walker tool still listed all the very same DLLs as before even when the program was just running fine now.

The gist of it: As someone elsewhere stated, the tool is a bit dated by now and does not always work properly with newer OS. Thus keep an eye open and don't get mislead by missing 'API-MS-WIN-CORE-COM-L1-1-0.DLL', ... the problem probably lies entirely elsewhere.


Source: (StackOverflow)

How do I determine the dependencies of a .NET application?

How do I determine the dependencies of a .NET application? Does Dependency Walker work with managed apps? I've downloaded the latest and tried profiling the app, but it just exits without much of an explanation. If it doesn't work with .NET, then is there some other tool that would help me debug a run-time DLL loading issue?


Source: (StackOverflow)

What exactly are DLL files, and how do they work?

How exactly do DLL files work? There seems to be an awful lot of them, but I don't know what they are or how they work.

So, what's the deal with them?


Source: (StackOverflow)

.Net picking wrong referenced assembly version

I just copied an existing project to a brand new machine to start developing on it and have run into a problem with the version of one of my referenced assemblies (a telerik DLL as it happens).

The project originally referenced an older version of the assembly (lets call it v1.0.0.0). My new machine has the latest version of the assembly installed, so I thought I'd updated it (lets call the new version v2.0.0.0).

Now here's the problem: If I copy the old v1.0.0.0 dll to the project folder and add it as a reference, the web site launches without a problem. If I delete that reference (and also delete the old DLL from my system) and add the new version (v2.0.0.0), the page shows the following exception:

Could not load file or assembly 'XXXXXX, Version=1.0.0.0, Culture=neutral, PublicKeyToken=121fae78165ba3d4' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Clearly, the code is looking for the out of date version and can't find it. But why?

I greped the solution folder for that version number and couldn't find a single reference. I double checked the text of the .csproj file and found the version correctly shows the latest version and the HintPath correctly shows the path to the new DLL. Furthermore, because I didn't install the old DLL on the system it doesn't show up in my GAC (though v2.0.0.0 does, as expected).

I then enabled the fusion log viewer to try to figure out why it's looking for that old version, but no luck:

Assembly Load Trace: The following information can be helpful to determine why the assembly 'XXXXXX, Version=1.0.0.0, Culture=neutral, PublicKeyToken=121fae78165ba3d4' could not be loaded.


=== Pre-bind state information ===
LOG: User = MyComp\me
LOG: DisplayName = XXXXXX, Version=1.0.0.0, Culture=neutral, PublicKeyToken=121fae78165ba3d4
 (Fully-specified)
LOG: Appbase = file:///d:/My Documents/Visual Studio 2010/Projects/CoolProj/WebApp/
LOG: Initial PrivatePath = d:\My Documents\Visual Studio 2010\Projects\CoolProj\WebApp\bin
Calling assembly : WebApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: d:\My Documents\Visual Studio 2010\Projects\CoolProj\WebApp\web.config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: XXXXXX, Version=1.0.0.0, Culture=neutral, PublicKeyToken=121fae78165ba3d4
LOG: Attempting download of new URL file:///C:/WINDOWS/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/90233b18/10d54998/XXXXXX.DLL.
LOG: Attempting download of new URL file:///C:/WINDOWS/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/90233b18/10d54998/XXXXXX/XXXXXX.DLL.
LOG: Attempting download of new URL file:///d:/My Documents/Visual Studio 2010/Projects/CoolProj/WebApp/bin/XXXXXX.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Major Version
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

All it says it that it starts by looking for that old assembly. I have tried to find a solution online and saw this similar SO question, but it seems to be the exact opposite of my problem. That questioner's program was finding the wrong DLL instead of the referenced one. Whereas my problem is that the program is mysteriously looking for the wrong DLL and unable to find it when the right one can be found locally in the bin folder and in the GAC.

Why is mine looking for the old version? Where else can I search to find this bad reference?


Source: (StackOverflow)

What is in a DLL and how does it work?

I'm always referencing DLLs in my C# code, but they have remained somewhat of a mystery which I would like to clarify. This is a sort of brain dump of questions regarding DLLs.

I understand a DLL is a dynamically linked library which means that another program can access this library at run time to get "functionality". However, consider the following ASP.NET project with Web.dll and Business.dll (Web.dll is the front end functionality and it references Business.dll for types and methods).

  1. At what point does Web.dll dynamically link to Business.dll? You notice a lot in Windows HDD thrashing for seemingly small tasks when using Word (etc.) and I reckon that Word is going off and dynamically linking in functionality from other DLLs?

    1a. Additionally, what loads and links the DLL - the OS or some run time framework such as the .NET framework?

    1b. What is the process of "linking"? Are compatibility checks made? Loading into the same memory? What does linking actually mean?

  2. What actually executes the code in the DLL? Does it get executed by the processor or is there another stage of translation or compilation before the processor will understand the code inside the DLL?

    2a. In the case of a DLL built in C# .NET, what is running this: the .NET framework or the operating system directly?

  3. Does a DLL from Linux work on a Windows system (if such a thing exists), or are they operating system specific?

  4. Are DLLs specific to a particular framework? Can a DLL built using C# .NET be used by a DLL built with, for example, Borland C++?

    4a. If the answer to 4 is "no" then what is the point of a DLL? Why dont the various frameworks use their own formats for linked files? For example: an .exe built in .NET knows that a file type of .abc is something that it can link into its code.

  5. Going back to the Web.dll / Business.dll example - to get a class type of customer I need to reference Business.dll from Web.dll. This must mean that Business.dll contains some sort of a specification as to what a customer class actually is. If I had compiled my Business.dll file in, say, Delphi: would C# understand it and be able to create a customer class, or is there some sort of header info or something that says "hey sorry you can only use me from another Delphi DLL"?

    5a. Same applies for methods; can I write a CreateInvoice() method in a DLL, compile it in C++, and then access and run it from C#? What stops or allows me from doing this?

  6. On the subject of DLL hijacking, surely the replacement (bad) DLL must contain the exact method signatures and types as the one that is being hijacked. I suppose this wouldn't be hard to do if you could find out what methods were available in the original DLL.

    6a. What in my C# program is deciding if I can access another DLL? If my hijacked DLL contained exactly the same methods and types as the original but it was compiled in another language, would it work?

What is DLL importing and DLL registration?


Source: (StackOverflow)

Exporting functions from a DLL with dllexport

I'd like a simple example of exporting a function from a C++ windows DLL.

I'd like to see the header, the cpp file, and the def file (if absolutely required).

I'd like the exported name to be undecorated. I'd like to use the most standard calling convention (__stdcall?). I'd like the use __declspec(dllexport) and not have to use a DEF file.

For example:

  //header
  extern "C"
  {
   __declspec(dllexport) int __stdcall foo(long bar);
  }

  //cpp
  int __stdcall foo(long bar)
  {
    return 0;
  }

I'm trying to avoid the linker added underscores and/or numbers (byte counts?) to the name.

I'm OK with not supporting dllimport and dllexport using the same header. I don't want any information about exporting C++ class methods, just c-style global functions.

UPDATE

Not including the calling convention (and using extern "C") gives me the export names as I like, but what does that mean? Is whatever default calling convention I'm getting what pinvoke (.NET), declare (vb6), and GetProcAddress would expect? (I guess for GetProcAddress it would depend on the function pointer the caller created).

I want this DLL to be used without a header file, so I don't really need the a lot of the fancy #defines to make the header usable by a caller.

I'm OK with an answer being that I have to use a DEF file.


Source: (StackOverflow)

MS C++ 2010 and mspdb100.dll

Microsoft's C++ compiler and linker seem to have an odd relationship with mspdb100.dll. When run from the IDE, of course, the compiler and linker work fine. When running either one from the command line, I get an error.

No problem, I located the DLL and copied it to the directory. Now the compiler works fine, but the linker dies.

I could solve the problem by adding "%VS10%\Common7\IDE" to my PATH, but for various reasons (performance, system purity, OCD, etc), I don't want to do that. Why is this setup so touchy, and is there anything else I can do to solve it?


Source: (StackOverflow)