我要做一个文件加密组件,主要实现以下方法:
EncryptFile(...)加密指定文件函数(算法已经确定)
IsFileEncrypted(....)检查指定文件是否已经加密
IsWorking(...)检查加密是否正在进行
Progress获取加密进度的属性组件主要用于网页,其次exe程序。由于加密需要时间长,所以不知道是不是应该在EncryptFile函数里新建线程。另外组件用什么线程模式?Apartment还是Single.为什么?请指教。
EncryptFile(...)加密指定文件函数(算法已经确定)
IsFileEncrypted(....)检查指定文件是否已经加密
IsWorking(...)检查加密是否正在进行
Progress获取加密进度的属性组件主要用于网页,其次exe程序。由于加密需要时间长,所以不知道是不是应该在EncryptFile函数里新建线程。另外组件用什么线程模式?Apartment还是Single.为什么?请指教。
解决方案 »
- 一个简单的文本编辑器,但不能输入!!求帮助!!!
- VS2005调用VC6编译的动态库的问题
- 如何把sql server 2000数据库表中的值取出来赋给vc中的变量呢?
- 我在用vc写程序的时候,char char_data〔3〕=“xyz”时出错,但是当char char_data〔6〕=“xyz”时编译正常,是否char_data〔i〕中只能
- 急!!!!!!!
- 关于MSDN光盘
- 为什么使用MAPI调用outlook express发信的时候,只能加入一个附件?
- 我如何才能获得IpConfig的输出信息?
- CString问题
- 用WINGATE 代理上网,如何用NETANETS下债???
- 调用CBitmap::FromHandle返回的CBitmap* 可以保存后反复使用吗?比如:
- 怎么我用vc++调用SOAP的时候怎么调用webservices的返回值为soap:server呀,是怎么回事!
After a careful examination of the implementation of the TipOfTheDay coclass, we confirmed our original suspicions: we were able to design the component such that it doesn't store global data, per-class data, or even per-instance data. The state of the component is entirely determined by the cookie parameter stored by the client application, so restricting object access to a single thread is unnecessary. Because the TipOfTheDay component doesn't use worker threads, there's no reason we wouldn't allow it to be created in an STA, so it makes sense to support both threading models. We'll change the Registry setting from ThreadingModel=Apartment to ThreadingModel=Both by editing the TIPOFTHEDAY.RGS file that the ATL Object Wizard created and added to the project.
InprocServer32 = s `%MODULE%'
{
val ThreadingModel = s `Both'
}
We'll also need to change some wizard-generated code to reflect the threading model. Replace
#define _ATL_APARTMENT_THREADED
Public CComObjectRootEx<CComSingleThreadModel>
with
#define _ATL_FREE_THREADED
Public CComObjectRootEx<CComMultiThreadModel> NOTE
--------------------------------------------------------------------------------
It wouldn't be accurate to say that the TipOfTheDay component is stateless, because the call history does indeed affect the data returned by the GetNextTip method. A client that calls GetNextTip three times will get a different result than a client that calls GetNextTip four times. More precisely, our component can be called "state estranged." A separate entity manages and stores its state.
The apartment model (or models) supported by an in-process component is determined by its ThreadingModel Registry setting. Although the wizard makes it easy for you to choose any one of these models, you shouldn't make this decision lightly. If you specify an STA—which, somewhat confusingly, maps to ThreadingModel=Apartment in the Registry—you're guaranteed that instances of your component will be accessed by only a single thread. That means you must protect access to global data but not to instance data. If you specify the MTA (ThreadingModel=Free), you must protect access to both global and instance data. Because we're not sure whether the TipOfTheDay component will maintain per-instance state, we'll initially it as ThreadingModel=Apartment to be on the safe side. After we've completed the implementation, we'll reexamine the issue to see whether individual instances of the TipOfTheDay component can handle concurrent access by multiple threads. If so, it might make sense to choose ThreadingModel=Both instead.