Click here to Skip to main content
11,925,292 members (58,704 online)
Rate this:
Please Sign up or sign in to vote.
See more: C#3.0 C#
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...
        // 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 28-Apr-11 8:18am
Edited 29-Apr-11 6:27am
Manfred R. 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 Lagria 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;
OleTest:= False;
ole1 := TOleContainer.CreateParented(0);
fstr := TFileStream.Create(p1,fmRead);
..... Test dll
Manfred R. 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

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Ok I came up with solution as:

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

C# side:

//Delegate for dll callbacks
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
             // tag and bag C# side of open item list
         case 2:
             // Datachanged - some debug stuff. Just ignore
         case 3:
             // Save
             // User pressed saved the open document.
             // handle created temporary file
         case 4:
             // Renamed - some debug stuff. Just ignore
         case 5:
             // View changed - some debug stuff. Just ignore
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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web03 | 2.8.151126.1 | Last Updated 8 May 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100