我正在创建一个C# DLL,将用作PLSQL Developer IDE的插件,该IDE是用C++设计的。
我的C# DLL需要接受一个C++指针,然后将该指针分配给一个函数或方法,在以后调用时使用。
这个IDE为构建这些插件提供了规范文档,但它只提供了C++和Delphi的示例。规范文档提供了更多信息,我在这个截图中包含了它。
提供的C++示例:
我的C# DLL需要接受一个C++指针,然后将该指针分配给一个函数或方法,在以后调用时使用。
这个IDE为构建这些插件提供了规范文档,但它只提供了C++和Delphi的示例。规范文档提供了更多信息,我在这个截图中包含了它。
提供的C++示例:
void (*IDE_MenuState)(int ID, int Index, BOOL Enabled);
BOOL (*IDE_Connected)();
void (*IDE_GetConnectionInfo)(char **Username, char **Password, char **Database);
void (*IDE_GetBrowserInfo)(char **ObjectType, char **ObjectOwner, char **ObjectName);
void RegisterCallback(int Index, void *Addr)
{
switch (Index)
{
case 10 :
(void *)IDE_MenuState = Addr;
break;
case 11 :
(void *)IDE_Connected = Addr;
break;
case 12 :
(void *)IDE_GetConnectionInfo = Addr;
break;
case 13 :
(void *)IDE_GetBrowserInfo = Addr;
break;
}
}
C# 我目前掌握的:
我应该注意到,我正在使用 Robert Giesecke 的Unmanaged Exports NuGet 包来导出函数。如果需要,我可以更改此设置。
public bool IDE_Connected()
{
return false;
}
public void IDE_MenuState(int ID, int Index, bool Enabled)
{
}
[DllExport("add", CallingConvention = CallingConvention.Cdecl, ExportName= "RegisterCallback")]
public static void RegisterCallback(int Index, IntPtr Addr)
{
if (Index == 10)
{
// Assign IntPtr Addr to IDE_MenuState()
// Please help :)
}
if (Index == 11)
{
// Assign IntPtr Addr to IDE_Connected()
// Please help :)
}
}
我该如何将C++指针参数赋值给我的C#方法?
void*
类型吗? - Mr AndersonMarshal.GetDelegateForFunctionPointer()
。 - Mr Anderson