Yola
Yola

Reputation: 19041

Define for constants like in C++

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#?

Upvotes: 3

Views: 79

Answers (2)

Suresh Kumar Veluswamy
Suresh Kumar Veluswamy

Reputation: 4363

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

Upvotes: 1

Sean
Sean

Reputation: 62492

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.

Upvotes: 3

Related Questions