Click here to Skip to main content
15,891,906 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
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
Posted
Updated 8-Dec-10 3:11am
v2

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
 
Share this answer
 
v4
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".
 
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