How to work with Header files(.h) and lib files in C

W

weird0

Hi!all. As part of the course project in the university, students
have been given task to develop a front-end for SMILE( an API written
in C++ for network modelling). Upon extracting the setup, it gives a
collection of " Header files and Lib files" written in c++.

Now, how do i add them in c# to use the existing api to create a
front-end. I do know that we can include the reference for any .dll
file and use it. But don't know how to use existing header files and
lib files in c#.

Can somebody guide me and help me on this issue, if somebody has
worked with C++ header files or done any sort of work on SMILE.

Would be really thankful personally, and it will be great help for
the students of this course project.
 
N

Nicholas Paldino [.NET/C# MVP]

weird0,

See inline:

weird0 said:
Hi!all. As part of the course project in the university, students
have been given task to develop a front-end for SMILE( an API written
in C++ for network modelling). Upon extracting the setup, it gives a
collection of " Header files and Lib files" written in c++.

Now, how do i add them in c# to use the existing api to create a
front-end. I do know that we can include the reference for any .dll
file and use it. But don't know how to use existing header files and
lib files in c#.

You can't create a reference to ANY .dll file and use it. The only way
you can add a reference to a .dll file is if it is a .NET assembly, or if it
is a COM assembly (in which case, you really reference the assembly
generated by TLBIMP, the COM wrapper generator).
Can somebody guide me and help me on this issue, if somebody has
worked with C++ header files or done any sort of work on SMILE.

What you need to do is declare the types and functions that you are
going to call. In general, you are using the P/Invoke layer. Here is a
reference to get your started:

http://msdn2.microsoft.com/en-us/library/fzhhdwae.aspx

Specifically, the section on consuming unmanaged DLL functions would be
helpful as well:

http://msdn2.microsoft.com/en-us/library/26thfadc.aspx
 
N

Nicholas Paldino [.NET/C# MVP]

Oh, and one other thing, if you have a .lib file, you are going to have
to create a DLL file which exposes the functions you want to call. You
can't access lib files directly from .NET.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Nicholas Paldino said:
weird0,

See inline:

weird0 said:
Hi!all. As part of the course project in the university, students
have been given task to develop a front-end for SMILE( an API written
in C++ for network modelling). Upon extracting the setup, it gives a
collection of " Header files and Lib files" written in c++.

Now, how do i add them in c# to use the existing api to create a
front-end. I do know that we can include the reference for any .dll
file and use it. But don't know how to use existing header files and
lib files in c#.

You can't create a reference to ANY .dll file and use it. The only way
you can add a reference to a .dll file is if it is a .NET assembly, or if
it is a COM assembly (in which case, you really reference the assembly
generated by TLBIMP, the COM wrapper generator).
Can somebody guide me and help me on this issue, if somebody has
worked with C++ header files or done any sort of work on SMILE.

What you need to do is declare the types and functions that you are
going to call. In general, you are using the P/Invoke layer. Here is a
reference to get your started:

http://msdn2.microsoft.com/en-us/library/fzhhdwae.aspx

Specifically, the section on consuming unmanaged DLL functions would be
helpful as well:

http://msdn2.microsoft.com/en-us/library/26thfadc.aspx


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Would be really thankful personally, and it will be great help for
the students of this course project.
 
S

Sheng Jiang[MVP]

You can write managed wrapper classes in a mixed assembly using C++/CLI.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top