希望这个示例可以让您从某个地方开始,它基于 SoftVelocity 新闻组中的示例(此处为缓存的纯文本版本)。
注意:我正在使用RGiesecke DllExport包和 Clarion LibMaker 的修改版本来创建兼容的 lib 文件。您提到您已经毫无问题地调用了 C# DLL,所以我假设您正在做类似的事情。如果你有兴趣,我会在我的博客上进一步讨论。
号角代码
PROGRAM
MAP
MODULE('ManagedCSharpDLL.dll')
CallbackProc PROCEDURE(BSTRING PassedValue, *BSTRING ReturnValue),TYPE,PASCAL,DLL(TRUE)
SetCallback PROCEDURE(*CallbackProc pCallback),NAME('SetCallback'),PASCAL,RAW,DLL(TRUE)
TestCallback PROCEDURE(*CString passedString),NAME('TestCallback'),PASCAL,RAW,DLL(TRUE)
END
Callback PROCEDURE(BSTRING PassedValue, *BSTRING ReturnValue),PASCAL
END
a CSTRING(20)
CODE
Message('Clarion: SetCallback(Callback)')
SetCallback(Callback)
a = 'Call Test Worked'
Message('Clarion: Send message: ' & a)
TestCallback(a)
Message('Clarion: Made call and got back safely')
Callback PROCEDURE(BSTRING PassedValue, *BSTRING ReturnValue)
CODE
MESSAGE('Clarion: Passed Value: ' & PassedValue)
ReturnValue = 'Done'
C# 代码
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using RGiesecke.DllExport;
namespace ManagedCSharpDLL
{
public static class UnmanagedExports
{
private static CallbackProc _callback;
[DllExport("SetCallback", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
public static void SetCallback(CallbackProc pCallback)
{
_callback = pCallback;
MessageBox.Show("C#: SetCallback Completed");
}
[DllExport("TestCallback", CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
public static void TestCallback(string passedString)
{
string displayValue = passedString;
string returnValue = String.Empty;
MessageBox.Show("C#: About to call the Callback. displayValue=" + displayValue + ", returnValue=" + returnValue);
_callback(displayValue, ref returnValue);
MessageBox.Show("C#: Back from the Callback. displayValue=" + displayValue + ", returnValue=" + returnValue);
}
public delegate void CallbackProc( [MarshalAs(UnmanagedType.BStr)] String PassedValue, [MarshalAs(UnmanagedType.BStr)] ref String ReturnValue);
}
}