日期:2014-05-20  浏览次数:21740 次

找不到类型或命名空间名称“MarshalAs”(是否缺少 using 指令或程序集引用?)
//   logfont.cs
//   compile   with:   /target:module
using   System;
using   System.Runtime.InteropServices;
using   System.Text;


[StructLayout(LayoutKind.Sequential)]
public   class   LOGFONT  
{  
public   const   int   LF_FACESIZE   =   32;
public   int   lfHeight;  
public   int   lfWidth;  
public   int   lfEscapement;  
public   int   lfOrientation;  
public   int   lfWeight;  
public   byte   lfItalic;  
public   byte   lfUnderline;  
public   byte   lfStrikeOut;  
public   byte   lfCharSet;  
public   byte   lfOutPrecision;  
public   byte   lfClipPrecision;  
public   byte   lfQuality;  
public   byte   lfPitchAndFamily;
[MarshalAs(UnmanagedType.ByValTStr,   SizeConst=LF_FACESIZE)]
public   string   lfFaceName;  
}


------解决方案--------------------
命令行编译没有问题啊。
1.1和 2.0都可以编译通过
------解决方案--------------------
版本信息

.NET Framework
受以下版本支持:2.0、1.1、1.0

.NET Compact Framework
受以下版本支持:2.0、1.0

using System;
using System.Runtime.InteropServices;

namespace MyModule
{
// If you do not have a type library for an interface
// you can redeclare it using ComImportAttribute.

// This is how the interface would look in an idl file.

//[
//object,
//uuid( "73EB4AF8-BE9C-4b49-B3A4-24F4FF657B26 "),
//dual, helpstring( "IMyStorage Interface "),
//pointer_default(unique)
//]
//interface IMyStorage : IDispatch
//{
// [id(1)]
// HRESULT GetItem([in] BSTR bstrName, [out, retval] IDispatch ** ppItem);
// [id(2)]
// HRESULT GetItems([in] BSTR bstrLocation, [out] SAFEARRAY(VARIANT)* pItems);
// [id(3)]
// HRESULT GetItemDescriptions([in] BSTR bstrLocation, [out] SAFEARRAY(VARIANT) ** ppItems);
// [id(4), propget]
// HRESULT get_IsEmpty([out, retval] BOOL * pfEmpty);
//};

// This is the managed declaration.

[ComImport]
[Guid( "73EB4AF8-BE9C-4b49-B3A4-24F4FF657B26 ")]
public interface IMyStorage
{
[DispId(1)]
[return : MarshalAs( UnmanagedType.Interface )]
Object GetItem( [In, MarshalAs( UnmanagedType.BStr )] String bstrName );

[DispId(2)]
void GetItems( [In, MarshalAs( UnmanagedType.BStr )] String bstrLocation,
[Out, MarshalAs( UnmanagedType.SafeArray,
SafeArraySubType = VarEnum.VT_VARIANT )] out Object[] Items );


[DispId(3)]
void GetItemDescriptions( [In] String bstrLocation,
[In, Out, MarshalAs( UnmanagedType.SafeArray )] ref Object[] varDescriptions );

bool IsEmpty
{
[DispId(4)]
[return : MarshalAs( UnmanagedType.VariantBool )]
get;
}
}
}
------解决方案--------------------
Visual Studio .NET 2003用的是.net framework 1.0

用2005