472,126 Members | 1,554 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Static libraries into C#

Is it possible to bring in a static library (developed in C++) into a C#
project/solution?

Thanks in advance for any information.

Andrew S. GIles
Nov 16 '05 #1
6 2489
Maybe Marshaling can helps you. Look at this:

using System;
using System.Runtime.InteropServices;

class CSClass
{
[DllImport("mycpp.dll")]
public static extern int myfunction(string c);

public static void Main()
{
...
int n = myfunction("One String");
...
}
}

Ernesto Lores
(Barcelona)


"Andrew S. Giles" <An**********@discussions.microsoft.com> escribió en el
mensaje news:CD**********************************@microsof t.com...
Is it possible to bring in a static library (developed in C++) into a C#
project/solution?

Thanks in advance for any information.

Andrew S. GIles

Nov 16 '05 #2
Thanks. But it is not a Dynamic Library that I have access to. All I have
is a static
libraby (lib) not a dynamic library (DLL).

Andrew

"e-lores" wrote:
Maybe Marshaling can helps you. Look at this:

using System;
using System.Runtime.InteropServices;

class CSClass
{
[DllImport("mycpp.dll")]
public static extern int myfunction(string c);

public static void Main()
{
...
int n = myfunction("One String");
...
}
}

Ernesto Lores
(Barcelona)


"Andrew S. Giles" <An**********@discussions.microsoft.com> escribió en el
mensaje news:CD**********************************@microsof t.com...
Is it possible to bring in a static library (developed in C++) into a C#
project/solution?

Thanks in advance for any information.

Andrew S. GIles


Nov 16 '05 #3
No, this is not possible. The best solution would be to compile your LIB
file into a DLL and export out the functions that you want to use.

JoeW

"Andrew S. Giles" wrote:
Thanks. But it is not a Dynamic Library that I have access to. All I have
is a static
libraby (lib) not a dynamic library (DLL).

Andrew

"e-lores" wrote:
Maybe Marshaling can helps you. Look at this:

using System;
using System.Runtime.InteropServices;

class CSClass
{
[DllImport("mycpp.dll")]
public static extern int myfunction(string c);

public static void Main()
{
...
int n = myfunction("One String");
...
}
}

Ernesto Lores
(Barcelona)


"Andrew S. Giles" <An**********@discussions.microsoft.com> escribió en el
mensaje news:CD**********************************@microsof t.com...
Is it possible to bring in a static library (developed in C++) into a C#
project/solution?

Thanks in advance for any information.

Andrew S. GIles


Nov 16 '05 #4
Thanks! I didnt think it would be, but I thought I would check before I
ruled it completely out.

Andrew

"JoeWood" wrote:
No, this is not possible. The best solution would be to compile your LIB
file into a DLL and export out the functions that you want to use.

JoeW

"Andrew S. Giles" wrote:
Thanks. But it is not a Dynamic Library that I have access to. All I have
is a static
libraby (lib) not a dynamic library (DLL).

Andrew

"e-lores" wrote:
Maybe Marshaling can helps you. Look at this:

using System;
using System.Runtime.InteropServices;

class CSClass
{
[DllImport("mycpp.dll")]
public static extern int myfunction(string c);

public static void Main()
{
...
int n = myfunction("One String");
...
}
}

Ernesto Lores
(Barcelona)


"Andrew S. Giles" <An**********@discussions.microsoft.com> escribió en el
mensaje news:CD**********************************@microsof t.com...
> Is it possible to bring in a static library (developed in C++) into a C#
> project/solution?
>
> Thanks in advance for any information.
>
> Andrew S. GIles

Nov 16 '05 #5
how is that not possible?

u build a dll that calls the functions in the static lib and the compiler
will insert the code from the static lib into the dll and then u can use the
dll.

"JoeWood" <Jo*****@discussions.microsoft.com> wrote in message
news:97**********************************@microsof t.com...
No, this is not possible. The best solution would be to compile your LIB
file into a DLL and export out the functions that you want to use.

JoeW

"Andrew S. Giles" wrote:
Thanks. But it is not a Dynamic Library that I have access to. All I have is a static
libraby (lib) not a dynamic library (DLL).

Andrew

"e-lores" wrote:
Maybe Marshaling can helps you. Look at this:

using System;
using System.Runtime.InteropServices;

class CSClass
{
[DllImport("mycpp.dll")]
public static extern int myfunction(string c);

public static void Main()
{
...
int n = myfunction("One String");
...
}
}

Ernesto Lores
(Barcelona)


"Andrew S. Giles" <An**********@discussions.microsoft.com> escribió en el mensaje news:CD**********************************@microsof t.com...
> Is it possible to bring in a static library (developed in C++) into a C# > project/solution?
>
> Thanks in advance for any information.
>
> Andrew S. GIles

Nov 16 '05 #6
It's not possible because the code in the static lib is not managed ...
thus it cannot be compiled into a managed assembly. Also, the .NET
framework doesn't have those kinds of linking utilities (without third
party tools), and those are only for linking other managed code
--
Joel Martinez
http://www.onetug.org - Orlando .NET User Group
http://www.codecube.net - blog

Bern wrote:
how is that not possible?

u build a dll that calls the functions in the static lib and the compiler
will insert the code from the static lib into the dll and then u can use the
dll.

"JoeWood" <Jo*****@discussions.microsoft.com> wrote in message
news:97**********************************@microsof t.com...
No, this is not possible. The best solution would be to compile your LIB
file into a DLL and export out the functions that you want to use.

JoeW

"Andrew S. Giles" wrote:

Thanks. But it is not a Dynamic Library that I have access to. All I
have
is a static
libraby (lib) not a dynamic library (DLL).

Andrew

"e-lores" wrote:
Maybe Marshaling can helps you. Look at this:

using System;
using System.Runtime.InteropServices;

class CSClass
{
[DllImport("mycpp.dll")]
public static extern int myfunction(string c);

public static void Main()
{
...
int n = myfunction("One String");
...
}
}

Ernesto Lores
(Barcelona)


"Andrew S. Giles" <An**********@discussions.microsoft.com> escribió en
el
mensaje news:CD**********************************@microsof t.com...

>Is it possible to bring in a static library (developed in C++) into
a C#
project/solution?
>
>Thanks in advance for any information.
>
>Andrew S. GIles


Nov 16 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by mudd | last post: by
3 posts views Thread by Rickard Lind | last post: by
3 posts views Thread by iceColdFire | last post: by
1 post views Thread by rajesh_krec | last post: by
2 posts views Thread by Cliff Cooley | last post: by
5 posts views Thread by meendar | last post: by
15 posts views Thread by Notre Poubelle | last post: by
reply views Thread by abarun22 | last post: by

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.