如何处理数据库中的OLE对象 [英] How to handle OLE objects in database

查看:95
本文介绍了如何处理数据库中的OLE对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,
我确实有一个MSSQL表,其中的一列包含许多OLE对象.
内容是各种类型和版本的MS Office文档+ TIF图像(典型的办公用品).
案例:需要一个可以处理那些文档的应用程序(如果安装了必需的应用程序)和一些其他任务.
我的想法:
1-弹出对象-根据 Windows化合物的结构二进制文件格式规范 [ 公共 void ReadnDump(System.IO.Stream p_Stream,字符串 p_FileName) { System.IO.BinaryReader br = System.IO.BinaryReader(p_Stream); m_head = Header(); m_DirEntities = System.Collections.Generic.List< DirectoryEntry>(); m_FAT = System.Collections.Generic.List< UInt32>(); m_DiFAT = System.Collections.Generic.List< UInt32>(); m_MiniFAT = System.Collections.Generic.List< UInt32>(); m_MiniStream = System.IO.MemoryStream(); m_DirDictonary = System.Collections.Generic.Dictionary< string,DirectoryEntry>(); 字节 []缓冲区; // 下面在上面的链接中解释了二进制阅读的内容 readHeader( ref br); readFAT( ref br); readDirectoryEntities( ref br); readMiniFat( ref br); 字符串 fileName; 字符串 className = readCompObjClassName(); UInt32 分支; int fileSize; System.IO.FileStream fw; 开关(className) { // 某些情况... 大小写 " : { sect = m_DirDictonary [" ] ._ sectStart; // 将内容转储到名为"p_FileName"的文件+确定的扩展名... break ; } // 其他情况... } }


自动化...我希望这不会成为现实.

2-设法编写了一个Delphi dll并打开了ole,但是...事件接收器,回调等着我!如:

Delphi方面:创建了具有6个出口和一个小工厂的Dll.

Init
CleanUp
RegisterCallback
OleOpen
OleCreateFromFile
OleClose



C#端:

 // 代理dll回调
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
公共 委托  void  ProcDelegate( int   value  int  callerID);
私有 静态 ProcDelegate procDelegate;
// 出口声明
[DllImport(" ,CallingConvention = CallingConvention.StdCall,CharSet = CharSet.Ansi)]
公共 静态 外部 // 每个导出的函数还有5个

// 委派的函数
// 值是我决定标识操作的任意数字
//  callerID是由OleOpen或OleCreateFromFile返回的容器ID 
公共 无效 DelphiCallBack( int   int  callerID)
{
     int 索引;
    开关()
    {
         案例  1 :
             // 关闭
             // 这会创建一个临时文件,将其按原样插入到数据库中
             OleClose(callerID);
             // 未清项目列表的标签和袋子C#侧
              break ;
         案例  2 :
             // 已更改-一些调试内容.只是忽略
              break ;
         案例  3 :
             // 保存
             // 用户按下保存了打开的文档.
             // 处理已创建的临时文件
              break ;
         案例  4 :
             // 重命名-一些调试内容.只是忽略
              break ;
         案例  5 :
             // 视图已更改-一些调试内容.只是忽略
              break ;
     }
} 


在执行其他任何操作之前调用Init和RegisterCallback破坏工厂.
唯一的问题是我尝试避免与dll进行内存接触,以便我使用临时文件来回传递OLE对象.欢迎任何进一步的建议.


Hello,
I do have a MSSQL table in which a column contains numerous OLE objects.
Contents are various types and versions of MS Office documents + TIF Images (Typical office stuff).
Case: Need of an application that can handle those documents (if required applications are installed) and some other tasks.
My thoughts:
1- Pop objects - rip ole struct according to
Windows Compound Binary File Format Specification[^] - push back raw files - add a type field to the table - perform other tasks.
But automation hell arises.
2- Make a .dll in an older IDE which has OleConteiner - somehow pass OLE to dll - take it back if and when done - perform other tasks.
But... I don''t really know how many things can go wrong.

The question is, what should I do? Is there a feasible way to handle OLE objects?

Progress Update:
1- Rip ole:

public void ReadnDump(System.IO.Stream p_Stream,string p_FileName)
{
    System.IO.BinaryReader br = new System.IO.BinaryReader(p_Stream);
    m_head = new Header();
    m_DirEntities = new System.Collections.Generic.List<DirectoryEntry>();
    m_FAT = new System.Collections.Generic.List<UInt32>();
    m_DiFAT = new System.Collections.Generic.List<UInt32>();
    m_MiniFAT = new System.Collections.Generic.List<UInt32>();
    m_MiniStream = new System.IO.MemoryStream();
    m_DirDictonary = new System.Collections.Generic.Dictionary<string,DirectoryEntry>();
    byte[] buffer;
    // Binary reading stuff below explained in link above
    readHeader(ref br);
    readFAT(ref br);
    readDirectoryEntities(ref br);
    readMiniFat(ref br);
    string fileName;
    string className = readCompObjClassName();
    UInt32 sect;
    int fileSize;
    System.IO.FileStream fw;
    switch (className)
    {
        // Some cases...
        case "Word.Document.12":
        {
            sect = m_DirDictonary["\\Root Entry\\Package"]._sectStart;
            // Dump contents to file named "p_FileName" + decided extention...
            break;
        }
        // Some more cases...
    }
}


Automation... I hope it does not come to this.

2- Managed to write a Delphi dll and open ole but... Event sink, callbacks waiting for me yay!

解决方案

Ok I came up with solution as:

Delphi side: Created Dll with 6 exports and a little factory inside.

Init
CleanUp
RegisterCallback
OleOpen
OleCreateFromFile
OleClose



C# side:

//Delegate for dll callbacks
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
public delegate void ProcDelegate(int value,int callerID);
private static ProcDelegate procDelegate;
// Declarations for exports
[DllImport("OleWrapper.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
public static extern void InitOle();
// And 5 more for each exported functions

// Delegated function
// value is an arbitrary number I decided to identify operation
// callerID is the container ID which is returned by OleOpen or OleCreateFromFile
public void DelphiCallBack(int value, int callerID)
{
    int index;
    switch (value)
    {
         case 1:
             // Close
             // this creates a temporary file to be inserted to DB as it is
             OleClose(callerID);
             // tag and bag C# side of open item list
             break;
         case 2:
             // Datachanged - some debug stuff. Just ignore
             break;
         case 3:
             // Save
             // User pressed saved the open document.
             // handle created temporary file
             break;
         case 4:
             // Renamed - some debug stuff. Just ignore
             break;
         case 5:
             // View changed - some debug stuff. Just ignore
             break;
     }
}


Init and RegisterCallback called before doing anything else CleanUp destroys the factory.
Only problem is I tried to avoid memory contact with dll so that I used temporary files to pass OLE objects back and forth. Any further suggestion is welcome.


这篇关于如何处理数据库中的OLE对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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