473,395 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

URGENT: How to use C++ APIs in C# application?

Hi
I am writing and application using C# and i want to use some APIs from an
SDK. I want to know how can i incorperate the libs, .h etc to the C# file
and use the apis.

Thanks
Mustafa
Nov 15 '05 #1
7 2614
Mustafa Rabie <mr****@nospam.com> wrote:
I am writing and application using C# and i want to use some APIs from an
SDK. I want to know how can i incorperate the libs, .h etc to the C# file
and use the apis.


Look up "interoperation with unmanaged code" in the index of MSDN.
There's a *lot* of information there - exactly how you'll do it will
depend on the type of API etc.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Nov 15 '05 #2
thx for the info, the functions i have are in .h files and a .lib file
so do i treat this as a DLL or what exactly?

Thanks
Mustafa
"Jon Skeet" <sk***@pobox.com> wrote in message
news:MP************************@news.microsoft.com ...
Mustafa Rabie <mr****@nospam.com> wrote:
I am writing and application using C# and i want to use some APIs from an SDK. I want to know how can i incorperate the libs, .h etc to the C# file and use the apis.


Look up "interoperation with unmanaged code" in the index of MSDN.
There's a *lot* of information there - exactly how you'll do it will
depend on the type of API etc.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too

Nov 15 '05 #3
Mustafa Rabie <mr****@nospam.com> wrote:
thx for the info, the functions i have are in .h files and a .lib file
so do i treat this as a DLL or what exactly?


Hmm... not sure what you can do with a .lib file from .NET, to be
honest. Hopefully an interop expert will pop up and help you...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Nov 15 '05 #4
i too had a similar situation. I then converted my C++
apis into a COM DLL and referenced the same within C#
project..
Nov 15 '05 #5
Mustafa,

If the function is only in a lib file (and not exported through a dll),
then what you will have to do is create an unmanaged project where the
functions are exported from a DLL (you can reference the lib from the DLL
project and then just create wrapper functions for the functions in the
lib). Once you have that DLL, you can make calls to it from .NET through
the P/Invoke layer.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"Mustafa Rabie" <mr****@nospam.com> wrote in message
news:u$**************@TK2MSFTNGP12.phx.gbl...
ok thanks a lot for your help really appreciated...
HOPE SOMEONE POPS UP!! lets keep our fingers crossed
"Jon Skeet" <sk***@pobox.com> wrote in message
news:MP************************@news.microsoft.com ...
Mustafa Rabie <mr****@nospam.com> wrote:
thx for the info, the functions i have are in .h files and a .lib file
so do i treat this as a DLL or what exactly?


Hmm... not sure what you can do with a .lib file from .NET, to be
honest. Hopefully an interop expert will pop up and help you...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too


Nov 15 '05 #6
vuola.

You can't do a thing with .lib files in C#.
You should wrap the files with:
a) C++ into DLL
b) (MS) C++.NET to managed class
c) As irfan suggested into COM object.

HTH,
Miha

"Jon Skeet" <sk***@pobox.com> wrote in message
news:MP************************@news.microsoft.com ...
Mustafa Rabie <mr****@nospam.com> wrote:
thx for the info, the functions i have are in .h files and a .lib file
so do i treat this as a DLL or what exactly?


Hmm... not sure what you can do with a .lib file from .NET, to be
honest. Hopefully an interop expert will pop up and help you...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too

Nov 15 '05 #7
So what i should do is use normal C++ DLL add the functions and write
function wrappers and then use this DLL with C#... correct?

Thanks for your help
Mustafa

"Nicholas Paldino [.NET/C# MVP]" <ni**************@exisconsulting.com> wrote
in message news:#6**************@TK2MSFTNGP12.phx.gbl...
Mustafa,

If the function is only in a lib file (and not exported through a dll), then what you will have to do is create an unmanaged project where the
functions are exported from a DLL (you can reference the lib from the DLL
project and then just create wrapper functions for the functions in the
lib). Once you have that DLL, you can make calls to it from .NET through
the P/Invoke layer.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni**************@exisconsulting.com

"Mustafa Rabie" <mr****@nospam.com> wrote in message
news:u$**************@TK2MSFTNGP12.phx.gbl...
ok thanks a lot for your help really appreciated...
HOPE SOMEONE POPS UP!! lets keep our fingers crossed
"Jon Skeet" <sk***@pobox.com> wrote in message
news:MP************************@news.microsoft.com ...
Mustafa Rabie <mr****@nospam.com> wrote:
> thx for the info, the functions i have are in .h files and a .lib file > so do i treat this as a DLL or what exactly?

Hmm... not sure what you can do with a .lib file from .NET, to be
honest. Hopefully an interop expert will pop up and help you...

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too



Nov 15 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: serge calderara | last post by:
Dear all, How can I access in VB.NET to a registry key on a local and remote computer. Does the previous Profile string function can be safelly used on is there anything else ? thnaks for...
2
by: Tanuki | last post by:
Hi All: I am doing some development in VC++ using some llibraries downloaded from the web. The library comes in 3 files <mylib.dll>, <mylib.lib>, <mylib.exp> and I also have <mylib.h>. As...
8
by: Mike | last post by:
Hello, I have a few rather urgent questions that I hope someone can help with (I need to figure this out prior to a meeting tomorrow.) First, a bit of background: The company I work for is...
5
by: peteh | last post by:
We are running DB2 PE (AIX) 8.1.5 and have built a SQL stored proc that uses the SNAPSHOT_APPL_INFO udf to return to the caller info about current db2 connections. The SP was created by a user...
3
by: TC | last post by:
Hey Folks, I am using the following 4 Win32 APIs with a C# AddIn: FindWindow SetWindowLong SetForegroundWindow EnableWindow Within the AddIn, there are some winforms. I use these APIs to...
16
by: | last post by:
Hi all, I have a website running on beta 2.0 on server 2003 web sp1 and I keep getting the following error:- Error In:...
0
by: Tulasi | last post by:
Hello, any one help me the problem due to Shopping cart. I am developping a project in that project,I want to connect shopping Carts in Vb.net.The shopping carts...
6
by: ajit | last post by:
I am working on web service which in turn call com components. if # of users using the web service increases. Web service fails is there some why I can prevent max # of concurrent users using the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.