Calling multiple dll imports with the same method name

I import several unmanaged DLLs into C ++, but the imported DLLs have the same method name, which causes problems with the compiler. For instance:

unsafe class Myclass { [DllImport("myfirstdll.dll")] public static extern bool ReturnValidate(long* bignum); [DllImport("myseconddll.dll")] public static extern bool ReturnValidate(long* bignum); public Myclass { int anum = 123; long passednum = &anum; ReturnValidate(passsednum); } } 

Now, what I would like to do is rename the method on import. Sort of:

 [DllImport("myseconddll.dll")] public static extern bool ReturnValidate(long bignum) AS bool ReturnValidate2(long bignum); 

Is it possible?

+6
source share
3 answers

You can specify any name for the imported function, you must specify only in DllImport name of the function in it using the EntryPoint property. So the code might look like this:

 [DllImport("myfirstdll.dll", EntryPoint="ReturnValidate")] public static extern bool ReturnValidate1(long bignum); [DllImport("myseconddll.dll", EntryPoint="ReturnValidate")] public static extern bool ReturnValidate2(long bignum); 
+7
source

Use the EntryPoint property of the DllImport attribute.

 [DllImport("myseconddll.dll", EntryPoint = "ReturnValidate")] public static extern bool ReturnValidate2(long bignum); 

Now that you call ReturnValidate2 in your C # code, you are effectively calling ReturnValidate on myseconddll.dll.

+12
source

Use the EntryPoint parameter:

 [DllImport("myfirstdll.dll", EntryPoint="ReturnValidate")] public static extern bool ReturnValidate1(long bignum); [DllImport("myseconddll.dll", EntryPoint="ReturnValidate")] public static extern bool ReturnValidate2(long bignum); 

Documentation:
http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.dllimportattribute.aspx
http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.dllimportattribute.entrypoint.aspx

+2
source

Source: https://habr.com/ru/post/898680/


All Articles