1

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.

4

4 回答 4

0

请注意,如果您不想要求用户运行 CRT 安装程序,您也可以随应用程序重新分发 CRT DLL。您可以在 redist\x86 下的 VC 安装目录中找到它们(C:\Program Files\Microsoft Visual Studio 9.0\VC\redist\x86\Microsoft.VC90.CRT 是我机器上的完整路径)。请注意,您必须复制该目录中的所有四个文件(三个 DLL 和一个清单)并将它们放在您的 EXE 旁边才能正常工作。

如果您正在做更复杂的事情,比如构建一个其他应用程序将加载的 DLL,这是不够的,但这对于大多数情况来说已经足够了。

于 2009-06-08T12:20:11.017 回答
0

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.

于 2009-02-18T03:35:04.720 回答
0

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.

于 2009-02-18T03:38:33.227 回答
0

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.)

于 2009-02-18T03:42:21.020 回答