Joel
3/24/2007 5:38:00 PM
Here's the working code:
using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices; // DllImport
using System.Diagnostics;
namespace ConsoleApplication5
{
public class orcaUtils
{
public static int PBORCA_MAXCOMMENT = 255;
public enum PBORCA_ENTRY_TYPE
{
PBORCA_APPLICATION,
PBORCA_DATAWINDOW,
PBORCA_FUNCTION,
PBORCA_MENU,
PBORCA_QUERY,
PBORCA_STRUCTURE,
PBORCA_USEROBJECT,
PBORCA_WINDOW,
PBORCA_PIPELINE,
PBORCA_PROJECT,
PBORCA_PROXYOBJECT,
PBORCA_BINARY
}
[DllImport("pborc100.dll", EntryPoint = "PBORCA_SessionOpen",
CharSet = CharSet.Unicode, SetLastError = true)]
public unsafe static extern int PBORCA_SessionOpen();
[DllImport("pborc100.dll", EntryPoint = "PBORCA_SessionClose",
CharSet = CharSet.Unicode, SetLastError = true)]
public unsafe static extern void PBORCA_SessionClose(int
hORCASession);
[DllImport("pborc100.dll", EntryPoint =
"PBORCA_LibraryCreate",
CharSet = CharSet.Unicode, SetLastError = true)]
public unsafe static extern int PBORCA_LibraryCreate(int
hORCASession,
[MarshalAs(UnmanagedType.LPTStr)] string lpszLibName,
[MarshalAs(UnmanagedType.LPTStr)] string lpszLibComment);
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
public struct PBORCA_DIRENTRY
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public string szComments;
public int lCreateTime; /* Time of entry create/
mod */
public int lEntrySize; /* Size of entry */
public string lpszEntryName; /* Pointer to entry
name */
public PBORCA_ENTRY_TYPE otEntryType; /* Entry
type */
}
public delegate void PBORCA_LIBDIRCALLBACK(
IntPtr pDirEntry,
IntPtr lpUserData);
[DllImport("pborc100.dll", EntryPoint =
"PBORCA_LibraryDirectory",
CharSet = CharSet.Unicode, SetLastError = true)]
public static extern int PBORCA_LibraryDirectory(int
hORCASession,
[MarshalAs(UnmanagedType.LPTStr)] string lpszLibName,
[MarshalAs(UnmanagedType.LPTStr)] string lpszLibComments,
int iCmntsBufflen,
PBORCA_LIBDIRCALLBACK pListProc,
IntPtr pUserData
);
}
class Program
{
public static void PBORCA_LibDirCallback(IntPtr pDirEntry,
IntPtr lpUserData)
{
orcaUtils.PBORCA_DIRENTRY myDirEntry =
(orcaUtils.PBORCA_DIRENTRY)Marshal.PtrToStructure(pDirEntry,
typeof(orcaUtils.PBORCA_DIRENTRY));
DateTime myDateTime = new DateTime(1970, 01, 01, 00, 00,
00).AddSeconds((double) myDirEntry.lCreateTime);
}
static void Main(string[] args)
{
int iORCASession = orcaUtils.PBORCA_SessionOpen();
Console.WriteLine("ORCA session opened");
int iRetVal;
orcaUtils.PBORCA_LIBDIRCALLBACK
PBORCA_LibraryDirectoryCallback = new
orcaUtils.PBORCA_LIBDIRCALLBACK(PBORCA_LibDirCallback);
string myName = "C:\\my.pbl";
string myComment = "";
IntPtr myDummy = new IntPtr();
iRetVal = orcaUtils.PBORCA_LibraryDirectory(iORCASession,
myName, myComment, 0, PBORCA_LibraryDirectoryCallback, myDummy);
if (iRetVal == 0)
{
Console.WriteLine("Library directory successful.");
}
else
{
Console.WriteLine("Error generating library directory:
" + iRetVal);
}
orcaUtils.PBORCA_SessionClose(iORCASession);
}
}
}