Вопрос

Suppose I have a file which imports a number of functions from dll, before every function I must put:

[DllImport(DLL_NAME, CallingConvention = CallingConvention.Cdecl)]

But it is boring and code becomes longer -> harder to understand, in C I can use define like this:

#define DLL_IMPORT [DllImport(...)]

What can I do in C#?

Это было полезно?

Решение

You're out of luck. The DllImport attribute is sealed, so you can't derive an instance and default the parameters, and C# has no macro processor to allow you to work around this.

Другие советы

You can use P/Invoke Interop Assistant to make your job a little easier. This tool automatically generates managed p/invoke declarations (in C# or VB) from native signatures. http://blogs.msdn.com/b/bclteam/archive/2008/06/23/p-invoke-interop-assistant-justin-van-patten.aspx

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top