IDE_OpenFile does not open file, but returns true using C#
Using PL/SQL Developer 13 Version: 13.0.3.1902 (64 bit)
Steps to reproduce:
create a menubutton which calls function a. Function a has a hardcoded filepath as string. Function a calls IDE_OpenFile with windowtype = 0 and filepath as parameters. IDE_OpenFile does not open a new file or any file at all. Maybe i'm just doing something wrong?
openFile is registered and its return type is then casted to an Unmanaged bool.
The filepath was just a test. I've used escaped backslashes before.
Hi, @Mikefox2k,
Will try to check that in the next days. Did you escape backslashes? Have you tried @? For example
// this one with escaped backslashes
string filepath = "O:\\NCT\\db\\jobs\\rcutil_job_check.prc"
// or this one
string filepath = @"O:\NCT\db\jobs\rcutil_job_check.prc"
I did escape backslashes. I've tried either way, but nothing works as expected. The problem still exists. My thought is that the function is not working properly, but i don't know.
@Mikefox2k , I've tried out and could not reproduce an error. Everything works for me - returns true and opens a window with file contents. I even tried non-existing file - opened empty window and showed an error. What I've tried:
//Existing file, PL/SQL determines window type automatically
bool result = openFileCallback(0, @"c:\users\vm\procedure.prc");
//Existing file, SQL window
bool result = openFileCallback(1, @"c:\users\vm\procedure.prc");
//Existing file, but file extension is unknown to PL/SQL Developer
bool result = openFileCallback(0, @"c:\users\vm\procedure.rpc");
// C:\ root directory usually needs admin permission to read file.
//Existing file, auto-determine window type
bool result = openFileCallback(0, @"c:\users\vm\procedure.prc");
//Non-existing file
bool result = openFileCallback(0, @"c:\users\vm\nonexisting.txt");
My callback:
[return: MarshalAs(UnmanagedType.Bool)]
delegate bool IdeOpenFile(int windowType, string fileName);
PL/SQL Developer:
Version 13.0.6.1911 (64 bit)
Windows 10 Build 17763
@Mikefox2k , You can try my plug-in. It creates menu "Open file" in the "Plug-Ins" tab. Here's the full code.
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using RGiesecke.DllExport;
namespace Aniskop.Tryout.OpenFile
{
[return: MarshalAs(UnmanagedType.Bool)]
delegate bool IdeOpenFile(int windowType, string fileName);
public class OpenFilePlugin
{
private const string PLUGIN_NAME = "OpenFile try-out";
private const int PLUGIN_MENU_INDEX = 1;
private static OpenFilePlugin me;
private int pluginId;
private static IdeOpenFile openFileCallback;
private OpenFilePlugin(int id)
{
pluginId = id;
}
#region DLL exported API
[DllExport("IdentifyPlugIn", CallingConvention = CallingConvention.Cdecl)]
public static string IdentifyPlugIn(int id)
{
if (me == null)
{
me = new OpenFilePlugin(id);
}
return PLUGIN_NAME;
}
[DllExport("RegisterCallback", CallingConvention = CallingConvention.Cdecl)]
public static void RegisterCallback(int index, IntPtr function)
{
if (index == 21)
{
openFileCallback = (IdeOpenFile)Marshal.GetDelegateForFunctionPointer(function, typeof(IdeOpenFile));
}
}
[DllExport("OnMenuClick", CallingConvention = CallingConvention.Cdecl)]
public static void OnMenuClick(int index)
{
if (index == PLUGIN_MENU_INDEX)
{
bool result = openFileCallback(0, @"c:\users\vm\procedure.prc");
if (result)
{
MessageBox.Show("OpenFile result = true");
} else
{
MessageBox.Show("OpenFile result = false");
}
}
}
[DllExport("CreateMenuItem", CallingConvention = CallingConvention.Cdecl)]
public static string CreateMenuItem(int index)
{
if (index == PLUGIN_MENU_INDEX)
{
return "ITEM=Open file";
}
else
{
return "";
}
}
[DllExport("About", CallingConvention = CallingConvention.Cdecl)]
public static string About()
{
//TODO: create about dialog
return "This is try out plug-in for IDE_OpenFile.";
}
#endregion
}
}