创建Win32 API [英] create win32 api

查看:89
本文介绍了创建Win32 API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在C#中创建WIN32 API.
我一直在寻找用C#为WIN32 API创建新项目的最佳选择.

我看到在Visual Studio中的C ++中,有一个创建MFC应用程序的选项.

但是我不确定哪个项目是创建WIN32 API的好选择.

我不想使用Windows函数.
我已经创建了一个类库.
我只想使用Win32 API在该类库周围创建包装器.
我可能需要使用指针.但仅此而已.

帮助将不胜感激.

谢谢

I want to create a WIN32 API in C#.
I was looking as to what would be the best option to create a new project for WIN32 API in C#.

I saw that in C++ in Visual Studio, there is one option to create MFC Application.

But i am not sure as to which would be good selection of a project to create WIN32 API.

I don''t want to use windows functions.
I have created a class library.
I just want to create a wrapper around that class library with win32 api.
I might need to use pointers. But nothing more than that.

Help would be appreciated.

Thanks

推荐答案

无法在c#.net中创建Win32 API,这两种操作在完全不同的模型上进行.

在Win32 API中,所有内存和资源都由程序员手动管理,并且所用的api也不受管理. Win32 Api已编译为可以运行的机器代码.

C#.NET内存由垃圾回收管理. .Net内容将转换为一种中间语言,直到运行时才进行编译.


尽管可以使用pascal和其他语言(不是我所知道的c#),但大多数win32 api都是使用C/C ++创建的.


在.net中,您可以创建将Win32类型的函数和托管的.Net混合在一起的C ++.NET程序集.


但是,如果您想在dev Studio c/C ++中创建Win32 API,那就是最好的选择.

如果您想要一个没有MFC依赖性的纯Win32 API,请转到File-> New-> Visual C ++ \ Win32 \ Win32 Project

***这就是你想要的***
对于您想要的内容,我建议使用C ++/.net clr项目,您可以混合使用win32 dll导出c函数并通过c ++.NET类调用.Managed代码.

文件->新项目->可视C ++-> CLR->类库

然后,您可以编写一些extern c函数,在函数导出时添加一个.def文件,并定义一个标头,生成一个lib文件.

添加对程序集的引用,然后从C函数中调用它.
Win32 API can''t be created in c#.NET the two things operated on completely different models.

In a Win32 API all memory and resources are managed manually by the programmer, and api used is also unmanaged. Win32 Api is compiled to machine code ready to run.

C#.NET memory is managed by garbage collection. .Net stuff is transform into an intermediate language which is not compiled until runtime.


Most win32 apis are created using C/C++ though pascal and other languages are available (not c# that I''m aware of).


In .net you can create a C++.NET assembly that mixes win32 type functions and managed .Net together.


But if you want to create a win32 API in dev studio c/C++ is your best bet.

If you want a pure Win32 API without MFC dependencies go to File->New->Visual C++\Win32\Win32 Project

*** This is what you want ***
For what you want I suggest C++/.net clr project you can mix a win32 dll exporting c functions and call .Managed code through c++.NET classes.

File->New Project->visual C++->CLR->Class Library

You can then write some extern c functions, add a .def file with your function exports and define a header, generate a lib file.

Add a reference to your assembly and call it from the C functions


Win32 API并不旨在包装"您的代码.您的代码应该包装API.

通过在.Net中创建一个程序集,并假设您已公开类,其他程序员可以使用您的"api".
The Win32 API isn''t meant to "wrap" your code. Your code is supposed to wrap the API.

By creating an assembly in .Net, and assuming you''ve made your classes public, other programmers can make use of YOUR "api".


这篇关于创建Win32 API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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