views:

1008

answers:

4

First off, I'm not a C++ programmer (but I am learning). I have finally managed to modify and compile some C++ source code using Visual C++ 2008 Express Edition. I've tried to get the same code compiled in the full version of Visual C++ 2003 without success (I get a wide variety of errors, but no luck).

The problem is that everything is working fine using RunDll32 to call the DLL on Windows Vista, but when I try the same rundll32 call on Windows 2000, I get the following error:

"Error loading mysampledll.dll" "The specified module could not be found."

Of course, I've tried setting the full path, moving the file around, etc...but no luck. I guarantee that the file exists and has the correct permissions.

I thought perhaps that there is something wrong with the manifest that is getting compiled along with the DLL in Vista. So I removed it using a resource editor, but then I get the same error in Vista and Win2k. Here's the manifest:

<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
    <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
    <security>
        <requestedPrivileges>
            <requestedExecutionLevel level="requireAdministrator" uiAccess="false"></requestedExecutionLevel>
        </requestedPrivileges>
    </security>
    </trustInfo>
    <dependency>
        <dependentAssembly>
            <assemblyIdentity type="win32" name="Microsoft.VC90.DebugCRT" version="9.0.21022.8" processorArchitecture="x86" publicKeyToken="1fc8b3b9a1e18e3b"></assemblyIdentity>
        </dependentAssembly>
    </dependency>
    <dependency>
        <dependentAssembly>
            <assemblyIdentity type="win32" name="Microsoft.VC90.CRT" version="9.0.21022.8" processorArchitecture="x86" publicKeyToken="1fc8b3b9a1e18e3b"></assemblyIdentity>
    </dependentAssembly>
    </dependency>
</assembly>

Now, I assume that the problem is with Win2k not having the Microsoft.VC90.CRT installed, but why does my DLL have this dependency? I've set the "Common Language Runtime Support" to "No Common Language Runtime Support" in the project properties, so why does it still require the CLR? Is there a way to change the manifest to use an older Visual C++ runtime that is available by default in Win2k? Sorry for my ignorance in these matters, and thanks in advance for any help.

A: 

Try installing the Visual Studio 2008 Redistributable package.

It contains the C++ runtime DLL that your program needs.

Don't get confused. That is not the CLR. The CLR is for managed code, not native Intel executables. Even native executables need the Microsoft runtime library dll if you dynamically link them to the runtime. This is the default in project properties, C++, Code Generation, Runtime Library = Multi-Threaded DLL. You can avoid this by choosing Multi-threaded, which would statically link in the library code.

Carlos A. Ibarra
Thanks a lot for all of your help everyone (thinkcube, jussij and Ants). I can't believe I confused CRT and CLR, but after hours of staring at code, I guess strange things can happen!
A: 

I would say that on the Windows 2000 box your DLL won't load because it is missing a dependency.

You find out what is missing by downloading the Depends utility found here: http://www.dependencywalker.com/

If it is a MSCRT DLL that is mising then you will need to reditribute these DLL's with your DLL.

jussij
A: 

The problem is that you are trying to run a DLL compiled with the debug C-Runtime (CRT) library linked in.

To fix the problem, link in the non debug CRT with your DLL:

Option 1: Build and distribute the release version. (This is what you should be doing anyway when it's time to release.) To do this:

  • List item
  • Build.Configuration Manager... and change your target flavor from Debug to Release; or
  • Build.Batch Build... and check of both Debug and Release; and
  • Use the binaries that come out of the Release directory.

Option 2: Build your debug binaries with the non-debug CRT. To do this:

  • List item
  • Project.Properties...
  • Navigate to C/C++, Code Generation
  • For Runtime Library, select Multithreaded DLL or Multithreaded.

I tend to go with option 2 for quick and dirty projects, where I want the speed of the retail CLR, but want all the debug info for my code.

(By the way, CLR != CRT, but that's a different discussion.)

Ants
A: 

Note that you can also redistribute the CRT DLLs with your application, if you'd rather not require your users to run the CRT installer. You'll find them in your VC installation directory under redist\x86 (C:\Program Files\Microsoft Visual Studio 9.0\VC\redist\x86\Microsoft.VC90.CRT is the full path on my machine). Note that you must copy all four files in that directory (three DLLs and a manifest) and place them next to your EXE for this to work properly.

If you're doing anything more complicated, like building a DLL that other applications will load this is insufficient, but this suffices for most cases.

Ted Mielczarek