是否可以在C#中使用Microsoft的Offline Files API? [英] Is it possible to use Microsoft's Offline Files API in C#?

查看:268
本文介绍了是否可以在C#中使用Microsoft的Offline Files API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想弄清楚如何使用 Offline Files API 从C#(如果可能)。我相信如果API是一个COM API,那么我理论上应该能够从C#使用方法此处

I'm trying to figure out how to use the Offline Files API from C# (if possible). I believe that if the API is a COM API, then I should theoretically be able to call it from C# using the methods here.

不幸的是,我不知道它是不是COM API,如何告诉。 (作为一个更通用的注释,任何人都可以告诉我如何判断API是否与COM兼容?)

Unfortunately, I have no idea if it's a COM API or not, or how to tell. (As a more general side note, can anyone tell me how to tell whether an API is COM compatible?)

我已成功调用 OfflineFilesQueryStatus 函数声明如下:

I've successfully called the OfflineFilesQueryStatus function from the API by declaring it like:

[DllImport("cscapi.dll")]
public static extern int OfflineFilesQueryStatus(out bool pbActive, out bool pbEnabled);

但我不知道如何使用接口(即,我不知道如何创建 IOfflineFilesCache 对象。)

But I'm not sure how to use the interfaces (i.e., I don't know how to create an IOfflineFilesCache object.)

任何人都可以帮我解释这个问题吗?

Can anyone help explain this to me?

推荐答案

好吧,它说


使用类ID CLSID_OfflineFilesCache

code code <这将是对 CoCreateObject 的调用。只需使用 CoCreateObject 的.NET替换。我认为运行时可调用的包装器/主互操作程序集合应该发出元数据,让你使用正常的C# new 语法创建对象。

From C or C++, that'd be a call to CoCreateObject. Just use the .NET replacement for CoCreateObject. I thought the runtime callable wrapper / primary interop assembly was supposed to emit metadata that would let you do that using the normal C# new syntax for creating objects.

使用.NET中的Offline Files API比COM对象更难,MSDN解释了为什么:

Using the Offline Files API from .NET is more difficult than usual for COM objects, MSDN explains why:


不幸的是,您无法通过在Visual Studio解决方案资源管理器中添加对此COM组件的引用来创建MobSync.dll互操作程序集。尝试这样做会产生错误。这是因为MobSync.dll与许多COM组件DLL不同,没有类型库(TLB)信息来支持嵌入其中的COM互操作。

Unfortunately, you cannot create a MobSync.dll interop assembly by adding a reference to this COM component in the Visual Studio Solution Explorer. Attempting to do so produces an error. This occurs because MobSync.dll, unlike many COM component DLLs, doesn't have type library (TLB) information to support COM interop embedded inside it.

.NET依赖于interop的类型库,但是Microsoft仅为这些接口提供了C / C ++头文件。有了一些IDL黑客,您可以使用它,请参阅创建自定义同步管理器处理程序MSDN上的示例,其中包含修复 mobsync.dll 的食谱。你需要执行相同的步骤,但使用cscapi / cscobj IDL。

.NET relies on the type library for interop, but Microsoft only provided the C/C++ header for these interfaces. With some IDL hacking, you can get it to work, see Creating a Custom Synchronization Manager Handler sample on MSDN, which has a recipe for "fixing" mobsync.dll. You'd need to perform the same steps, but with the cscapi/cscobj IDL.

但是目前为止,最简单和最支持的方法是使用C ++ / CLI 。在那里你可以直接 #include SDK头文件,你也可以定义从C#轻松使用的托管类型。

But by far the easiest and best-supported approach would be to use C++/CLI. There you can directly #include the SDK headers, and you can also define managed types easily used from C#.

这篇关于是否可以在C#中使用Microsoft的Offline Files API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆