Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi. Does anybody know how to use NativeMethods in c sharp? Does it have special namespace?
Posted

You probably talking about WinApi methods in meaning of word NativeMethods.
If it's true, you must look forward to use P/Invoke in .NET enviroment.

For example calling of method GetDC from User32.dll could be declared in next format:

C#
[DllImport("user32.dll")]
private static extern IntPtr GetDC(IntPtr hWnd);


Take a closer look to P\Invoke
Good luck.
 
Share this answer
 
v2
Comments
Zoltán Zörgő 1-Jun-12 17:40pm    
Good mind-reading :) My vote +5.
By the way, NativeMethods is a concept not a language entity. (http://msdn.microsoft.com/en-us/library/ms182161.aspx)
Oleksandr Kulchytskyi 1-Jun-12 17:48pm    
Yep ) it's an interesting article. Thanks for share link)
aliprogrammer 1-Jun-12 17:46pm    
These codes will set the windows calculator into a windows form application. But the question is how to use the NativeMethods.SetParent in the third line. Does it have special namespace?

System.Diagnostics.Process p = System.Diagnostics.Process.Start("calc.exe");
p.WaitForInputIdle();
NativeMethods.SetParent(p.MainWindowHandle, this.Handle);

Please help me to use NativeMethods in the third line.
Oleksandr Kulchytskyi 1-Jun-12 17:51pm    
=) Now issue became more clearly)
NativeMethods is a third-party class , which is not related to .NET environment.
aliprogrammer 1-Jun-12 17:52pm    
What should I do?
In addition to Oleksandr's answer, wrapping P\Invoke methods in a class called "NativeMethods" is a convention, so if you're looking for a specific class with that name I suggest looking into any external libraries used with code where you may have seen it referenced (making a guess from how you typed it that this may be the case).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900