首页 新闻 会员 周边 捐助

关于Luence 调用Parser.parse("Pdf文件")出现“尝试读取或写入受保护的内存。”

0
[已关闭问题]

如题在Webservice中调用该方法时候出现”尝试读取或写入受保护的内存。这通常指示其他内存已损坏。“
1.该代码在本地服务器和本地机子上均无出现上述情况,只在发布的服务器上出现win2003
2.PDF IFilter 6.0插件已经安装,除了pdf其他格式如office格式均可正确读取文件内容
3.利用编写window forms简易程序测试Parser.parse("Pdf文件")时候能正确读取内容,但是在关闭应用程序后出现font capture 应用程序错误 0x03cf61b3 0x047223e8 内存不能读
上述异常只在读取pdf文件时候出现,其他格式均正常

Parse类如下

代码
1 public class Parser
2 {
3 public Parser()
4 {
5 }
6
7 [DllImport("query.dll", CharSet = CharSet.Unicode)]
8 private extern static int LoadIFilter(string pwcsPath, ref IUnknown pUnkOuter, ref IFilter ppIUnk);
9
10 [ComImport, Guid("00000000-0000-0000-C000-000000000046")]
11 [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
12 private interface IUnknown
13 {
14 [PreserveSig]
15 IntPtr QueryInterface(ref Guid riid, out IntPtr pVoid);
16
17 [PreserveSig]
18 IntPtr AddRef();
19
20 [PreserveSig]
21 IntPtr Release();
22 }
23
24
25 private static IFilter loadIFilter(string filename)
26 {
27 IUnknown iunk = null;
28 IFilter filter = null;
29
30 // Try to load the corresponding IFilter
31 int resultLoad = LoadIFilter(filename, ref iunk, ref filter);
32 if (resultLoad != (int)IFilterReturnCodes.S_OK)
33 {
34 return null;
35 }
36 return filter;
37 }
38
39 /*
40 private static IFilter loadIFilterOffice(string filename)
41 {
42 IFilter filter = (IFilter)(new CFilter());
43 System.Runtime.InteropServices.UCOMIPersistFile ipf = (System.Runtime.InteropServices.UCOMIPersistFile)(filter);
44 ipf.Load(filename, 0);
45
46 return filter;
47 }
48 */
49
50 public static bool IsParseable(string filename)
51 {
52 return loadIFilter(filename) != null;
53 }
54
55 public static string Parse(string filename)
56 {
57 IFilter filter = null;
58
59 try
60 {
61 StringBuilder plainTextResult = new StringBuilder();
62 filter = loadIFilter(filename);
63
64 STAT_CHUNK ps = new STAT_CHUNK();
65 IFILTER_INIT mFlags = 0;
66
67 uint i = 0;
68 filter.Init(mFlags, 0, null, ref i);
69
70 int resultChunk = 0;
71
72 resultChunk = filter.GetChunk(out ps);
73 while (resultChunk == 0)
74 {
75 if (ps.flags == CHUNKSTATE.CHUNK_TEXT)
76 {
77 uint sizeBuffer = 60000;
78 int resultText = 0;
79 while (resultText == Constants.FILTER_S_LAST_TEXT || resultText == 0)
80 {
81 sizeBuffer = 60000;
82 System.Text.StringBuilder sbBuffer = new System.Text.StringBuilder((int)sizeBuffer);
83 resultText = filter.GetText(ref sizeBuffer, sbBuffer);
84
85 if (sizeBuffer > 0 && sbBuffer.Length > 0)
86 {
87 string chunk = sbBuffer.ToString(0, (int)sizeBuffer);
88 plainTextResult.Append(chunk);
89 }
90 }
91 }
92 resultChunk = filter.GetChunk(out ps);
93 }
94 return plainTextResult.ToString();
95 }
96 catch (Exception ex)
97 {
98 return ex.Message;
99 }
100 finally
101 {
102 if (filter != null)
103 Marshal.ReleaseComObject(filter);
104 }
105 }
106 }

各位达人看见的话多提提意见

问题补充: PDF IFilter 5.0用旧版本就可以了 谢谢
LuckyMN的主页 LuckyMN | 初学一级 | 园豆:10
提问于:2010-03-12 10:03
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册