Using static Library from application written with managed code

C

chandra.somesh

Hi

I have bunch of static libs which were written in C++ and i want to
link to those libraries using managed code(c#) . For c++ VS had the
option of including additional libraries .....what is the equivalent of
that for c# ?

Also will such a scenario work where a managed app access a static lib
written in native code?

Thanks in advance

Somesh
 
N

Norman Rericha

You can include your C++ library as a resource. Then using P/Invoke you
can access those functions.

This is a sample of P/Invoke, I am using it here to load a function
from CoreDLL.

[DllImport("coredll.dll", EntryPoint="CreateEvent", SetLastError=true)]
internal static extern IntPtr CreateEvent(IntPtr
SecurityAttributes, //Must be null
bool ManualReset,
bool InitializeState,
string Name);


--
I hope this helps

--
Norman Rericha
Senior Software Engineer
Applied Data Systems
www.applieddata.net
An ISO 9001:2000 Registered Company
Microsoft WEP Gold-level Member
 
C

chandra.somesh

Thanks for replying .

Could you tell me how much of a performance degradation(if any )it
would be invoking a c++ function from managed code. .... as in i have
an application where only the ui is in managed code while rest of the
functionality is implemented in c++ ( ie rpc etc ..) The managed code
is there to trap user events and fwd it to the lower umanaged layer and
correspondingly update its state upon receiving reponse from the
unmanaged layer .

thanks

Somesh
 
I

Ilya Tumanov [MS]

No, you can not use static libraries (.lib) with C#.



You have to link static libraries to the wrapper C/C++ code which would
expose functions in static library as DLLs entry points.

As soon as you compile that wrapper code and link it to the static
libraries, you would get DLL(s) which you can P/Invoke into.



That assumes these libraries have some code in them and they are not just
wrappers to some DLL.

If that's the case you can P/Invoke DLL directly, .lib are not needed.


--
Best regards,


Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.

*** Want to find answers instantly? Here's how... ***

1. Go to
http://groups-beta.google.com/group/microsoft.public.dotnet.framework.compactframework?hl=en
2. Type your question in the text box near "Search this group" button.
3. Hit "Search this group" button.
4. Read answer(s).
 

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