Using c libraries: zlib.lib, libjpeg.lib

M

MuZZy

Hello,
I am pretty new to .NET programming and probably my question has an obvious
answer:

I am starting to port an existing c++ application to c#.NET
The first problem i am facing is that the app uses two open-source "c"
compression libraries:
zlib.lib and libjpeg.lib.

I would really want ot avoid rewriting those libraries, because it's a huge
amount of code, so is there any way to use the lib's or recompile the source
code some special way?

Any suggestions would be highly appreciated!

Thank you,
Andrey
 
R

Ralph

MuZZy said:
Hello,
I am pretty new to .NET programming and probably my question has an obvious
answer:

I am starting to port an existing c++ application to c#.NET
The first problem i am facing is that the app uses two open-source "c"
compression libraries:
zlib.lib and libjpeg.lib.

I would really want ot avoid rewriting those libraries, because it's a huge
amount of code, so is there any way to use the lib's or recompile the source
code some special way?

Any suggestions would be highly appreciated!

Thank you,
Andrey

The easiest way is to create a managed C++ assembly that provides class
wrappers for the C routines. You can then use this assembly(s) from C#.

[Warning aircode follows...]
extern "C" {
#include <stdio.h>
#include <zlib.h> // assume there is one
#include <jpep.h>
}
#using <mcorlib.dll>
using namespace System::Runtime::InteroptServices;
using namespace System;
namespace Zlib {
[DllImport("zlib")]
extern "C" void SomeZlibFunction();
...
public __gc class ZlibFunctions
{
void MyNewCall() {
SomeZlibFunction();
}
...
}
};

In your C# code just add
using ZLIB;
You can now use the c libs just like they were another assembly. You can
also inherit from the classes.

HTH
-ralph
 
T

Tony Wilton

Your best bet is to comple them to Win32 dlls and then use the
system.runtime.interop classes.

Look in the .NET Framework documentation (installs with the free .net 1.1
SDK download from Microsoft)
"Consuming Unmanaged DLL Functions"

I am not aware of any conversion utilities, sorry.
 

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