我想使用C#创建一个DLL,然后可以通过以下方式从VBA调用它 -
Private Declare Function invokePath Lib "\\shared_computer\Projects\somedll\myDLL.dll" (ByVal strUName As String, ByVal strSFile As String) As String
Run Code Online (Sandbox Code Playgroud)
这个想法是,如果DLL的路径改变了,我只需要更新私有声明功能行中的路径....
我已经搜索了很多,也不确定这种安排是否可行 - 我们可以在没有引用或注册的情况下从网络路径调用DLL函数.
小智 12
其实你可以.查看unmanagedexports 这是一个完整的演练,你将能够创建这样的入口点:
[DllExport("GenerateSomehting", CallingConvention = CallingConvention.Cdecl)]
public static int GenerateSomehting(int somevalue, ref IntPtr pointer)
Run Code Online (Sandbox Code Playgroud)
并像任何其他非托管DLL一样调用它.
[DllImport("MyGenerator.dll", CallingConvention = CallingConvention.Cdecl)]
static extern int GenerateSomehting(int somevalue, ref IntPtr pointer);
Run Code Online (Sandbox Code Playgroud)
您无法使用 C# 创建非托管 DLL,因为 C# 是一种仅限 .NET 的语言。使用C++。
从非托管代码(例如 VBA)使用 .NET DLL 的唯一方法是使用 COM 互操作。
| 归档时间: |
|
| 查看次数: |
7367 次 |
| 最近记录: |