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

from .lib and .h files, how to get a managed wrapper

P: n/a
DBT
I'm sure this is simple if you know how.

I've got .h files and .lib files for a C language API that I need to access
from a C# assembly.

For the sake of this question, assume there are two .h files (ctap.h and
rtap.h) and three .lib files (a.lib, b.lib, c.lib). There are six functions
to be accessed (void afunc1(int), char afunc2(char []), void bfunc1(float),
double bfunc2(int *), void cfunc1(char), char[] cfunc2(char [])).

Can you provide a quick example, or the code, or a clear walkthrough on how
to wrap these in a C++ managed wrapper that will allow a C# assembly to
access the 6 named functions?
Nov 15 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
DBT wrote:
I'm sure this is simple if you know how.

I've got .h files and .lib files for a C language API that I need to
access from a C# assembly.

For the sake of this question, assume there are two .h files (ctap.h
and rtap.h) and three .lib files (a.lib, b.lib, c.lib). There are six
functions to be accessed (void afunc1(int), char afunc2(char []), void
bfunc1(float), double bfunc2(int *), void cfunc1(char), char[]
cfunc2(char [])).

Can you provide a quick example, or the code, or a clear walkthrough
on how to wrap these in a C++ managed wrapper that will allow a C#
assembly to access the 6 named functions?

Create a managed C++ assembly:
- "File | New | Project | Visual C++ Projects | Class Library (.NET)"
#include "ctap.h"
#include "rtap.h"

#pragma comment(lib, "a.lib)
#pragma comment(lib, "b.lib)
#pragma comment(lib, "c.lib)

namespace MyWrapper {
public __gc class Class1 {
public:

static void Managed_afunc1(int value)
{
afunc1(value);
}

// The following is a little bit complicated...
// what is "char" ? (string or byte array)
static char Managed_afunc2(char [])
{
return 0;
}

static void Managed_bfunc1(float value)
{
bfunc1(value);
}

// The following is also complicated...
// what is "int *" ? (menaing of in/out, or array ?)
static double Managed_bfunc2(int *)

// What is char !? (String-Char !? or 1 byte?)
static void Managed_cfunc1(char value)
{
cfunc1(value);
}

// What is char !? (String char or byte array?)
static char[] Managed_cfunc2(char []));

};
}
In C# you can simply make a reference to this DLL and use it:

Example:
MyWrapper.Class1.Managed_afunc1(12);
--
Greetings
Jochen

Do you need a memory-leak finder ?
http://www.codeproject.com/tools/leakfinder.asp
Nov 15 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.