473,387 Members | 1,864 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,387 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 1451
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...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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
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...

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.