Click here to Skip to main content
15,891,375 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
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:
C#
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!
Posted
Updated 29-Apr-11 5:27am
v3
Comments
Manfred Rudolf Bihy 28-Apr-11 14:02pm    
Sounds like an interesting question to me. Let's see what the seasoned OLE specialists aboard CP have to say to this.
Rajesh Lagaria 28-Apr-11 20:22pm    
send your code ! what you do
yesotaso 28-Apr-11 22:10pm    
Function OleTest(p1:PChar): Boolean; StdCall;
var ole1:TOleContainer;
fstr:TFileStream;
Begin
OleTest:= False;
ole1 := TOleContainer.CreateParented(0);
fstr := TFileStream.Create(p1,fmRead);
ole1.LoadFromStream(fstr);
ole1.DoVerb(ovPrimary);
..... Test dll
Manfred Rudolf Bihy 29-Apr-11 8:38am    
How come you replied to my comment? I do hope this was done by mistake ;)
yesotaso 29-Apr-11 11:04am    
:) Mistake indeed.

1 solution

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:

C#
//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.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900