473,439 Members | 1,945 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,439 software developers and data experts.

Using C++ libs and headers through a DLL in C#?

3
I am trying to write a camera control software - I have some factory provided headers and SDK libraries for the camera (I'm assuming they're from the VS6 era) and the hardware, of course. I would like to call these library functions from C# because the interface and some graph- and image displaying seems to be much more easier to write in C#.

What I was thinking of, I would write a C++ code which basically includes the headers and other stuff and wraps these SDK/lib functions into C++ functions. Then I make a DLL from it and use it in C#.

For instance, the initialization in the C++ part:
Expand|Select|Wrap|Line Numbers
  1. int initCam(int param)
  2. {
  3.     return SET_INIT(param);
  4.     //returns with an error code or 0
  5. }
and I call the initCam(argument) function in C# to initialize the camera.

Would this work? I am not sure this is the proper way to call C/C++ libraries from C# and as I tried a couple of things it doesn't seem to be :)

edit:
I hope I posted to the right place, I wasn't sure where to post this question
Feb 17 '10 #1
2 1453
tlhintoq
3,525 Expert 2GB
Google with the terms "Call C++ DLL from C#" yielded several tutorials.
http://www.google.com/search?client=...UTF-8&oe=UTF-8
Feb 17 '10 #2
alag20
84
I agree with tlhintoq, that googling will give you lots of tutorials to explain in detail, but just as a reference for future, incase people come to this page via google, you can accomplish it in the way below.

Expand|Select|Wrap|Line Numbers
  1. [DllImport("user32.dll", SetLastError = true)]
  2.         [return: MarshalAs(UnmanagedType.Bool)]
  3.         static extern bool PostMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
  4.  
This goes to user32.dll which is a windows dll, and returns a boolean, but you will write something similar to tap into your C++ dll with exposed functions. Google for tutorials to explain in detail.
Feb 18 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Robin Becker | last post by:
Does anyone know if it is feasible to have static libraries for both 2.3 and 2.4 compatible extensions. I'm worrying about libjpeg etc in a win32 environment. -- Robin Becker
5
by: Lars Schouw | last post by:
I have downloaded the newest boos release. I am havng problems building boost using the intel C++ 8.0 compiler. It looks as if bjam can't fine the icl.exe compiler executable itself. This file is...
4
by: Anthony Gallagher | last post by:
I have a bunch of libraries compiled using VC++ 6.0, and I am trying to recompile one of our projects using VC++ .NET. I get all kind of linker errors (specially in STL calls). How do I get rid of...
11
by: Paul Tremblay | last post by:
Hi, I can't seem to locate the visual C++ (pre .NET) ng. This may be slight off topic here - please point me to the correct ng if it is. Without going into much detail (and repeating myself...
28
by: NewToCPP | last post by:
Hi, I am just trying to find out if there is any strong reason for not using Templates. When we use Templates it is going to replicate the code for different data types, thus increasing the...
7
by: christian.eickhoff | last post by:
Hi Everyone, I am currently implementing an XercesDOMParser to parse an XML file and to validate this file against its XSD Schema file which are both located on my local HD drive. For this...
2
by: iwl | last post by:
Hello I copied the code from the Extending Embedded Python section in the Python 2.5 but get an linker Error Unresolved external _Py_InitModule4TraceRefs. Who knows what's wrong?
2
by: mr_gees100_peas | last post by:
Hi, I've been trying for days to make either boost.python or swig to work for me. The one I have gotten the closest to is boost. Note that this is for windows XP. I'm not much of an unix person...
3
by: Pixel.to.life | last post by:
Hi, Gurus, I recently attempted to build a .Net forms application, that links with old style unmanaged C++ static libs. Of course I had to recompile the static lib projects to link properly...
9
by: Todd Whiteman | last post by:
I've put together a tutorial that shows off how to build a GUI application using XULRunner (same architectural components as Firefox uses) that can be used in conjunction with the Python...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
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
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...
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...
0
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

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.