By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,248 Members | 882 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,248 IT Pros & Developers. It's quick & easy.

Static libraries into C#

P: n/a
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
Share this Question
Share on Google+
6 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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.