gpt4 book ai didi

c# - 编译器找不到命名空间 'System.Windows.Interop'

转载 作者:行者123 更新时间:2023-11-30 16:59:50 25 4
gpt4 key购买 nike

求助!!**编译器找不到命名空间**'System.Windows.Interop'****

最近建了一个winform项目,想用另一个c++项目生成的dll(做一些d3d渲染工作);

OS: win7 x64
IDE: vs2013
Language:C#
current framework used in the winform project is ".net framework 4.5"

然后在 winform 项目中,我创建了一个名为 MCDllOpt.cs 的类文件代码如下。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Interop; // Error occured here!

namespace WorldEditor
{
class MCDllOpt
{

}
}

这是编译器告诉的部分内容。

1>CoreCompile:
1> C:\Program Files (x86)\MSBuild\12.0\bin\Csc.exe /noconfig /nowarn:1701,1702,2008 /nostdlib+ /platform:anycpu32bitpreferred /errorreport:prompt /warn:4 /define:TRACE /errorendlocation /preferreduilang:en-US /highentropyva+ /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\Microsoft.CSharp.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\mscorlib.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\System.Core.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\System.Data.DataSetExtensions.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\System.Data.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\System.Deployment.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\System.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\System.Drawing.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\System.Windows.Forms.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\System.Xml.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\System.Xml.Linq.dll" /debug:pdbonly /filealign:512 /optimize+ /out:obj\Release\WorldEditor.exe /subsystemversion:6.00 /resource:obj\Release\WorldEditor.Form1.resources /resource:obj\Release\WorldEditor.Properties.Resources.resources /target:winexe /utf8output Form1.cs Form1.Designer.cs MCDllOpt.cs Program.cs Properties\AssemblyInfo.cs Properties\Resources.Designer.cs Properties\Settings.Designer.cs "C:\Users\Think\AppData\Local\Temp\.NETFramework,Version=v4.5.1.AssemblyAttributes.cs" obj\Release\\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs obj\Release\\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs obj\Release\\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
1>F:\WorldEditor\WorldEditor\WorldEditor\MCDllOpt.cs(6,22,6,29): error CS0234: The type or namespace name 'Interop' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?)
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:00.78
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

经过几分钟的搜索,我发现我需要添加指定的引用。但是在我添加所有前缀为'System.Windows'的引用之后,问题仍然没有解决! enter image description here

有没有人遇到过这个问题?请帮助我。

最佳答案

这是一个WPF命名空间。您可以引用的一个程序集(它为该命名空间提供类)是 PresentationCore.dll。但是,由于您拥有 using 指令,您实际上需要 System.Windows.Interop 中的哪些类?您需要引用的是这些类所在的程序集。

也许解决方案是删除 using

如果您制作 WinForm 应用程序,可能不需要任何 WPF namespace ?

关于c# - 编译器找不到命名空间 'System.Windows.Interop',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23148360/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com