Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create unmanaged DLL using C#?

Tags:

c#

dll

I want to create a DLL using C#, which can be then called from VBA in the following manner -

Private Declare Function invokePath Lib "\\shared_computer\Projects\somedll\myDLL.dll" (ByVal strUName As String, ByVal strSFile As String) As String

The idea is, if the path of the DLL is changed I need to only update the path in the Private Declare function line....

I have searched a lot for it, and also not sure whether this arrangement is possible - where we can call a DLL function from a network path without referencing or registering.

like image 683
Amit Pandey Avatar asked Nov 21 '12 11:11

Amit Pandey


1 Answers

Actually you can. Check out unmanagedexports It is a complete walk-through and you'll be able to create entry points like this:

[DllExport("GenerateSomehting", CallingConvention = CallingConvention.Cdecl)]
public static int GenerateSomehting(int somevalue, ref IntPtr pointer)

and call it just like any other unmanaged dll.

[DllImport("MyGenerator.dll", CallingConvention = CallingConvention.Cdecl)]
static extern int GenerateSomehting(int somevalue, ref IntPtr pointer);
like image 166
Samball Avatar answered Sep 19 '22 11:09

Samball