Static libraries into C#

G

Guest

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
 
E

e-lores

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)
 
G

Guest

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 said:
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 said:
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
 
G

Guest

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 said:
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 said:
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 said:
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
 
G

Guest

Thanks! I didnt think it would be, but I thought I would check before I
ruled it completely out.

Andrew

JoeWood said:
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 said:
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 said:
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" <[email protected]> escribió en el
mensaje 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
 
B

Bern

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 said:
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 said:
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 said:
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" <[email protected]> escribió en el
mensaje 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
 
J

Joel Martinez

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
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.

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

:

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

:


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" <[email protected]> escribió en
el
mensaje
Is it possible to bring in a static library (developed in C++) into

a C#
 

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