我引用启动如下一个COM结构代表一个领域:的PInvoke - 如何从一个COM接口
[scriptable, uuid(ae9e84b5-3e2d-457e-8fcd-5bbd2a8b832e)]
interface nsICacheSession : nsISupports
{
/**
* Expired entries will be doomed or evicted if this attribute is set to
* true. If false, expired entries will be returned (useful for offline-
* mode and clients, such as HTTP, that can update the valid lifetime of
* cached content). This attribute defaults to true.
*/
attribute PRBool doomEntriesIfExpired;
...
我发现代码导入该接口到我的C#应用程序。该代码必须是错的,因为set
方法似乎并不有用,当我尝试调用它只是为了看看会发生什么还抛出一个错误:
[Guid("ae9e84b5-3e2d-457e-8fcd-5bbd2a8b832e"), ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface nsICacheSession
{
[return: MarshalAs(UnmanagedType.Bool)]
void set_doomEntriesIfExpired();
[return: MarshalAs(UnmanagedType.Bool)]
bool get_doomEntriesIfExpired();
...
什么是设置正确的方法doomEntriesIfExpired
的值,以及如何从我的代码中引用此值?
编辑
我改变了我的代码以下,取得了“System.AccessViolationException:尝试读取或写入受保护的内存内容十分重要...”:
[Guid("ae9e84b5-3e2d-457e-8fcd-5bbd2a8b832e"), ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface nsICacheSession
{
void set_doomEntriesIfExpired(bool enabled);
bool get_doomEntriesIfExpired();
...
不错,我没有意识到在使用互操作时你可以保留属性。 – 2009-10-27 07:22:55