473,404 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

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

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
1 2017
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Yoni Rabinovitch | last post by:
Hi, We have a large code base of "regular" C++ code (not MFC, COM or ATL). With VC6.0, we used to compile the "regular" C++ code as static libraries (.lib files), and then we would link the...
3
by: Mike | last post by:
I have been developing ASP applications for quite a while now. Most of the apps that I deploy are a typical n-tier setup. ASP GUI on a web server, Business and Data Components written in VB6...
5
by: Tim Nelson | last post by:
Hi, I've got a legacy application written in C. I'd like to evolve the product (as opposed to completely rewriting it) by adding new features using C#. Is this possible? I know I should be able...
47
by: Bonj | last post by:
I downloaded the gzlib library from zlib in order to do compression. (http://www.gzip.org/zlib) The prototype of the compression function seems to be int compress (Bytef *dest, uLongf *destLen,...
2
by: Brett Styles | last post by:
Hi Guys, I am trying to access a class in an unmanaged dll. I have created a wrapper managed class to access the functions I need but no matter what I try from the MSDN samples I can not get it to...
3
by: Tommy Svensson \(InfoGrafix\) | last post by:
I've been instructed to work againt a huge unmanaged C++ API from a C# application. Now, the only way, as I've understood it, is to go the Managed Extensions for C++ way. This means I have to...
5
by: Andy | last post by:
I'm having trouble accessing an unmanaged long from a managed class in VC++.NET When I do, the contents of the variable seem to be mangled. If I access the same variable byte-by-byte, I get the...
9
by: Amit Dedhia | last post by:
Hi All I have a VC++ 2005 MFC application with all classes defined as unmanaged classes. I want to write my application data in xml format. Since ADO.NET has buit in functions available for...
9
by: =?Utf-8?B?RWR3YXJkUw==?= | last post by:
I would greatly appreciate some help on passing managed object into unmanaged code. I need to pass a reference (address of) of a managed class into unmanaged code (written by a thrid party). The...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.