"MuZZy" <le*******@yaho o.com> wrote in message
news:xTs_b.1101 79$uV3.597125@a ttbi_s51...
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 ::InteroptServi ces;
using namespace System;
namespace Zlib {
[DllImport("zlib ")]
extern "C" void SomeZlibFunctio n();
...
public __gc class ZlibFunctions
{
void MyNewCall() {
SomeZlibFunctio n();
}
...
}
};
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