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:
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
public delegate void ProcDelegate(int value,int callerID);
private static ProcDelegate procDelegate;
[DllImport("OleWrapper.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
public static extern void InitOle();
public void DelphiCallBack(int value, int callerID)
{
int index;
switch (value)
{
case 1:
OleClose(callerID);
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
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.