Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change function name inside managed code while using DllImpot attribute?

Tags:

c#

.net

vb.net

I want to call an external function like this.

[DllImport("user32.dll")]
static extern IntPtr WindowFromPoint(POINT Point);

However I want to change function name from WindowFromPoint to MyFunc. So in my managed code I would be able to do :

MyFunc(new POINT());

Because this is not the only function and there is over 100 functions I'm looking for a easy one line solution.

like image 440
Mohsen Sarkar Avatar asked Apr 23 '26 10:04

Mohsen Sarkar


1 Answers

[DllImport("user32.dll", CharSet = CharSet.Unicode, EntryPoint = "WindowFromPoint")]
static extern IntPtr MyFunc(POINT Point);

I believe this will work.

Or, if, for whatever reason, you need to keep the name you can try this:

[MethodImplAttribute(MethodImplOptions.AggressiveInlining)] 
public static IntPtr MyFunc(POINT Point)
{
    return WindowFromPoint(Point);
}
like image 71
Vercas Avatar answered Apr 25 '26 00:04

Vercas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!