473,803 Members | 4,192 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2034
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.Class 1.Managed_afunc 1(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
2769
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 .lib files with an MFC GUI "front end". The "regular" C++ can also run as a standalone .EXE (with no GUI).
3
1522
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 running in COM+ on a separate server with the SQL database residing on its own server. I don't really use COM+ for the transactions but more for the DCOM capabilities and as a way to control the running program. If I need to compile out a new...
5
1291
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 to call a managed-code DLL from C, but I am unsure of the best way to do it, and also how I might marshal the data between the two parts between the managed and unmanaged parts of the application. Can anyone point me in a direction? Thanks.
47
3544
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, const Bytef *source, uLong sourceLen); It is meant to be called by C, but I would rather use it from C#. So I wrote the following C# program to test it, but it failed to work. The call to compress doesn't return or throw an exception, it simply...
2
2412
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 work with my code. I have a VB Net front end which need the access the unmanaged functions. The wrapper I wrote can be accessed but the wrapper will not compile when I refer to the unmanaged class. I have tried using header file for definitions...
3
1958
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 write a wrapper between unmanaged API and my managed app. Now on to the question: If there's an unmanaged API class called X with a defined method
5
2404
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 correct value. Regardless what I set the variable to, the value that is returned for a long is always the same value. What's going on...can anyone help me? A short version of the code follows:
9
3123
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 this, I want to use it. Is it possible to call Managed class functions from Unmanaged class? How to do it? I did something like this. I declared a managed class (in C++ CLI) called as MyManagedClass whose
9
3568
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 3rd party unmanaged DLL will pass this reference into standard Win32 unmanaged static callback function in my code. Inside this unmanaged callback function I need to cast this unmnaged pointer that I have received from 3rd party back into the...
0
9703
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10548
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10316
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10295
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9125
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7604
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6842
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4275
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2970
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.