如何使用WinAPI索引中的.dll文件? [英] How to use .dll files from WinAPI Index?

查看:124
本文介绍了如何使用WinAPI索引中的.dll文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是导入任何.dll文件以使用任何Windows API。



有Windows API索引,我选择任何.dll来包装使用。



http ://msdn.microsoft.com/en-us/library/ff818516(v = vs.85).aspx [ ^ ]



我选择了下一个.dll,我怎么包装才能使用?我不能,因为没有关于这样一个目标的信息,换句话说,Windows API参考不是为了这样的目标。



http://msdn.microsoft.com/en-us/library/ms535564(v = vs.85 ).aspx [ ^ ]



有.NET Framework类库,它显示了我在C#程序中使用它们时需要知道的一切。我需要关于WinAPI的相同内容。

http ://msdn.microsoft.com/en-us/library/gg145045(v = vs.100).aspx [ ^ ]



下一个是我需要什么,但它是某些类的例外。

http://msdn.microsoft.com/en-us/library/ms534039%28VS.85%29.aspx [ ^ ]



我有大纲的工作代码,但我从最后一个只有600个函数的链接中得到它,但我想对从Windows API索引中选择的任何.dll做同样的事情。



我认为Windows API索引引用是专门用于C ++的,而不是C#。

My goal is to import any .dll file to use any Windows API.

There is Windows API Index where i choose any .dll to wrap to use.

http://msdn.microsoft.com/en-us/library/ff818516(v=vs.85).aspx[^]

I chose the next .dll, how can i wrap it to use? I can't because there is no information for such a goal, in other words Windows API reference is not made for such a goal.

http://msdn.microsoft.com/en-us/library/ms535564(v=vs.85).aspx[^]

There is .NET Framework Class Library, it shows everything i need to know to use them in my C# program. I need the same thing about WinAPI.
http://msdn.microsoft.com/en-us/library/gg145045(v=vs.100).aspx[^]

The next one is what i need for, but it an exception for certain classes.
http://msdn.microsoft.com/en-us/library/ms534039%28VS.85%29.aspx[^]

I have the working code for Outline, but i got it from the last link where are just 600 functions, but i wanna do the same thing with any .dll i choose from Windows API Index.

I think Windows API Index reference is specialized for C++, not for C#.

推荐答案

确定所以你需要做的第一件事就是使用windows api函数(这是针对DLLUser32.dll)是添加对System.Runtime.InteropServices的引用

通过这样做:

ok so the first thing you need to do in order to use a windows api function(this is for the DLL "User32.dll") is to add a reference to the System.Runtime.InteropServices
by doing this:
using System.Runtime.InteropServices;





然后你像这样导入DLL(注意你在winform app的构造函数之前的空格中这样做):



then you import the DLL like this(note you do this in the space right before the constructor for a winform app):

[DllImport("user32.dll")]





这里是一个如何从新导入的User32.dll导入LockWorkStation方法的示例(注意:你应该添加进程DLL导入语句下的代码行):



here is an example of how to import the LockWorkStation method from the newly imported "User32.dll" (Note: you should add the proceeding line of code right under the DLL import statement):

public static extern void LockWorkStation();



现在这个方法不接受任何参数,所以你这样称呼:


now this method doesn't take any arguments so you call it like this:

LockWorkStation();



这会锁定你的电脑所以我会把它放在一个按钮事件方法或什么东西



这个是一个非常简单的使用windows api和一个非常容易操作的操作。

C#可以访问windows api它比C ++稍微难一点。

i希望这个得到你开始并帮助,

MasterCodeon


this will lock your computer so i would put this in a button event method or something

this is a very simple use of the windows api and a very easy to do operation.
C# can access the windows api its just a little harder than C++.
i hope this gets you started and helps,
MasterCodeon


这是你已经发布过两次的完全相同的问题,答案仍然是一样的。您使用P / Invoke从.NET应用程序访问Windows API函数;没有其他文件。选择您要使用的功能,并在P / Invoke网站上查找。如果没有引用它,那么你需要自己计算出调用顺序。
This is exactly the same question that you have already posted twice, and the answer is still the same. You use P/Invoke to access Windows API functions from .NET applications; there is no other documentation. Choose the function you wish to use and look it up on the P/Invoke website. If there is no reference to it then you will need to work out the calling sequence for yourself.


解决了!



问题:如何使用.dll文件?

1.转到WinAPI索引。

http://msdn.microsoft.com/en-us/library/ff818516(v = vs.85).aspx [ ^ ]

2.选择任何.dll文件。

http://msdn.microsoft.com/en-us/library/ms646294(v = vs.85).aspx [ ^ ]

3.使用平台调用(C#,Windows Forms,.Net Framework 4.0,Visual Studio 2010)。

Solved!

Question: How to use .dll files?
1. Go to WinAPI Index.
http://msdn.microsoft.com/en-us/library/ff818516(v=vs.85).aspx[^]
2. Choose any .dll file.
http://msdn.microsoft.com/en-us/library/ms646294(v=vs.85).aspx[^]
3. Use Platform Invoke (C#, Windows Forms, .Net Framework 4.0, Visual Studio 2010).
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.Runtime.InteropServices;
using System.Reflection;

namespace _123
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            Method();
        }

        [DllImportAttribute(@"User32.dll")]
        static extern void GetFocus();

        private void Method()
        {
            GetFocus();
        }
    }
}





问题:如何以相同的方式使用GDI + Flat API ?

答:不可能以同样的方式使用任何GDI + Flat API。

1.例如,选择一个简单的GDI + API:

http://msdn.microsoft.com/en-us/ library / ms535564(v = vs.85).aspx [ ^ ]

2.你不能使用它!

问题:为什么?

答案:因为:



Question: How to use GDI+ Flat API in the same way?
Answer: It is impossible to use any of GDI+ Flat APIs in the same way.
1. For example, choose a simple GDI+ API:
http://msdn.microsoft.com/en-us/library/ms535564(v=vs.85).aspx[^]
2. You can not use it!
Question: Why?
Answer: Because of:

Quote:

Microsoft产品支持服务不会为调用的代码提供支持平面API直接

Microsoft Product Support Services will not provide support for code that calls the flat API directly



http: //msdn.microsoft.com/en-us/library/ms534039%28VS.85%29.aspx [ ^ ]



问题:可以使用任何Windows API索引的Windows API直接API?

答:不可能直接使用所有这些API,你只能直接使用.dll文件。因此,您应该使用C ++为这些API生成.dll文件,以便通过使用Platform Invoke在C#中使用它们。


http://msdn.microsoft.com/en-us/library/ms534039%28VS.85%29.aspx[^]

Question: Is it possible to use any API of Windows API from Windows API Index directly?
Answer: It is impossible to use all of them directly, you only can use .dll files directly. As a result, you should use C++ to make .dll files for those APIs to use them in C# by using Platform Invoke.


这篇关于如何使用WinAPI索引中的.dll文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆