Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it safe to rename extern method parameters in C#?

Tags:

c#

dll

unmanaged

I am currently cleaning up some of our legacy code base in which we make use of extern methods. The parameter names are all over the place in terms of naming conventions. I'd like to consolidate them.

Example

[DllImport("customdll", CallingConvention = CallingConvention.Cdecl)]
public static extern void SetStatus(int new_status);

Can I safely rename new_status to newStatus or will that break the contract?

ReSharper suggests it as a change, but I'd like to verify it. I was not able to find documentation on it (for or against it).

I am not asking if renaming the method name itself is possible, just the parameter definitions.

References

  • Alias for function
like image 852
Mario Tacke Avatar asked Aug 08 '17 21:08

Mario Tacke


1 Answers

Yes, it is safe to change the name of the parameters (but not the method itself) as long as you keep them in the same order with the proper data types. Parameters in traditional DLLs are populated by ordinal, not by name.

You can also change the name of the method itself if you use the EntryPoint parameter in the DllImport constructor.

like image 51
John Wu Avatar answered Oct 02 '22 01:10

John Wu