473,789 Members | 2,833 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C++ managed wrapper for static C library

Hi,

I have a statically-linked C library (.lib) that I need to be able to
access from C#. I understand that the best way to do this is to code
a C++ managed wrapper.

How do I create this wrapper? One of the functions in this library is
as follows:

int *func2 (int *ary, int n, char *str)

How does this look in the wrapper?

Thanks,

Jon

Feb 5 '07 #1
3 2959
<jo********@gma il.comwrote in message
news:11******** **************@ v33g2000cwv.goo glegroups.com.. .
Hi,

I have a statically-linked C library (.lib) that I need to be able to
access from C#. I understand that the best way to do this is to code
a C++ managed wrapper.

How do I create this wrapper? One of the functions in this library is
as follows:

int *func2 (int *ary, int n, char *str)

How does this look in the wrapper?

Thanks,

Jon
You don't need a managed wrapper, you only have to build a native DLL that exports the
functions you need to be public from the static lib.

Willy.

Feb 5 '07 #2

Wouldn't this then require the use of pinvoke in the c# code though?
I was hoping to avoid that if possible.

Thanks.

Feb 5 '07 #3
<jo********@gma il.comwrote in message
news:11******** **************@ p10g2000cwp.goo glegroups.com.. .
>
Wouldn't this then require the use of pinvoke in the c# code though?
I was hoping to avoid that if possible.

Thanks.
Sure it does require PInvoke, no big deal, you have to transition from managed code to
unmanaged code anyway.
Normally, you should only use a managed wrapper if you need to wrap an native C++ class, or
when you have to deal with a lot of native function calls.

Willy.


Feb 6 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2289
by: Mark McEahern | last post by:
I just wrote a very simple wrapper for the PayFlow Pro SDK (see below). A friend of mine did this before, but I didn't have access to his source, so I took it as a learning opportunity for me to write a C wrapper. I did a little searching to see whether anyone had done anything like this for Python. I didn't find anything. I did find that PHP comes with an extension for PayFlow Pro that you can compile into the language:
0
2268
by: Yoni Rabinovitch | last post by:
Hi, I am new to C#, so I apologise if this is a stupid question. I have some 3rd party C++ code, which gets built as static libraries (not DLLs). I want to create a C# form, which will call the C++ code. So, I understand that I need to create a Managed C++ Wrapper, for any
1
2034
by: DBT | last post by:
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 )).
1
7162
by: Adam Clauss | last post by:
I have an unmanaged C++ library that I need to use through C#. I created a Managed C++ class library and through it wrote a wrapper class to call what I need. However, one of the methods (an Initialize function in the unmanaged library) crashes everytime I call it. Initialize calls another function 'GetInstance' (a static member function of a class) which looks something like: CLibConfig& CLibConfig::GetInstance()
10
3391
by: andrea catto' | last post by:
I have this giant library, it's static and it's all compiled in __fastcall fashion. I can not call any of those functions from winforms... even doing a wrapper off the main class, I still cant call it.... how do I overcome this issue ?
0
1944
by: Arnaud Debaene | last post by:
Hello all. I've got a bunch of existing, non managed, C++ DLLs that export types with, among other things, public events implemented using the boost::signals library. Now, I need to have these DLL interoperate with managed code. Among others things, the managed code need to be able to register for notification with the boost signals. I've tried different approaches (trying to register a pinned delegate with the boost::signal, etc...),
7
2430
by: Adam | last post by:
I have a managed cpp wrapper. Im using this in a native dll as a static variable. I need to free this library when the dll is done being used. The perfect place to do this is DllMain for DLL_PROCESS_DETACH, but I can't do this when touching managed code, even if its just calling "delete someObject;". Any recommendations on how to free this object (it needs to be freed when the dll is being unloaded from its caller). Since the CRT is...
9
3567
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...
1
1672
by: £ukasz Z±bik | last post by:
I have project that uses managed c++ where I use c - library, this library contains some variables named generic, during compilation I get error: Error 1 error C2146: syntax error : missing ';' before identifier 'generic', Problem is that in dotNet generic is a keyword, and I cannot change this name becouse I have only lib file and includes. How to solve this problem? -- pozdrawiam £ukasz
0
9511
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10200
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
10139
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
9984
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7529
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
6769
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();...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4093
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
2909
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.