473,387 Members | 1,903 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.

Importing C++ dll into C#

I have tried everything to import a C++ dll into a C# program without
success. I can import the dll into another C++ program but not a C# program.
I always get the message that it can't find the function in the specified
dll. So it is finding the dll program but it can't find the entry
statements. I know that in C++ environment a lib file is used for addressing
the entry statements at link time. Obviously, it does not work in a C#
environment since there are no linker variables. Does anyhow have an example
of importing a C++ dll into a C# program using the DLLexport function?
Dave
Jan 23 '08 #1
2 7114
On Tue, 22 Jan 2008 18:26:00 -0800, Parrot
<Pa****@discussions.microsoft.comwrote:
[...] Does anyhow have an example
of importing a C++ dll into a C# program using the DLLexport function?
You need to look at the DllImport directive and "p/invoke" generally.
Searching for those terms in this newsgroup will turn up lots of existing
examples.

You may also want to look at this page:
http://msdn2.microsoft.com/en-us/library/aa288468.aspx (Platform Invoke
Tutorial)

Pete
Jan 23 '08 #2
"Parrot" <Pa****@discussions.microsoft.comwrote in message
news:38**********************************@microsof t.com...
>I have tried everything to import a C++ dll into a C# program without
success. I can import the dll into another C++ program but not a C#
program.
I always get the message that it can't find the function in the specified
dll. So it is finding the dll program but it can't find the entry
statements. I know that in C++ environment a lib file is used for
addressing
the entry statements at link time. Obviously, it does not work in a C#
environment since there are no linker variables. Does anyhow have an
example
of importing a C++ dll into a C# program using the DLLexport function?
Dave
Here's an example. You just put this code somewhere in you C# project. This
is all you need, you don't add an import like you do for C++.
[DllImport("gdi32")]
private static extern int AbortDoc(int hdc);

You need to make sure your C++ dll doesn't mangle the function names it
exports and generally you should make then stdcall. To stop the mangling you
need to add a text file called Exports.DEF and add something like this

Exports
FirstFunctionNameNotToMangle
SecondFunctionNameNotToMangle
etc


Jan 23 '08 #3

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

Similar topics

12
by: qwweeeit | last post by:
The pythonic way of programming requires, as far as I know, to spread a big application in plenty of more manageable scripts, using import or from ... import to connect the various modules. In...
4
by: jean-marc | last post by:
As an application programmer, I'm not well versed in the material aspects of computing (memory, cpu, bus and all). My understanding of imports in Python is such: the __main__ program is the center...
2
by: steve | last post by:
Hi, I have researched but have not found a good solution to this problem. I am importing large amounts of data (over 50 Meg) into a new mysql db that I set up. I use >mysql dbname <...
11
by: Grim Reaper | last post by:
I am importing a .csv file into Access that has 37 fields. My problem is that sometimes the last field only has data at the end of the column (it looks like when you import a file into Access, for...
7
by: Darren | last post by:
I have been attempting to create a reservation planning form in excel that imports Data from an Access database and inserts that information automaticly into the correct spreed sheet and the...
5
by: dixie | last post by:
If I sent a user an empty database container - dB with no tables and I needed them to import their tables into it and one of their tables was a hidden table with the prefix Usys, is there any way...
2
by: nutthatch | last post by:
I want to be able to import an Excel spreadsheet into Access 2K using the macro command Transferspreadsheet. However, the file I am importing (over which I have no control) contains some records...
7
by: Timothy Shih | last post by:
Hi, I am trying to figure out how to use unmanaged code using P/Invoke. I wrote a simple function which takes in 2 buffers (one a byte buffer, one a char buffer) and copies the contents of the byte...
0
by: Mike Collins | last post by:
I am importing a XML file and have not been having the best of luck in doing this, but I do have the following solution below. I will not be importing more than 2000 records at a time, but will be...
3
by: rs387 | last post by:
Hi, I've found the following behaviour on importing a variable from a module somewhat odd. The behaviour is identical in Python 2.5 and 3.0b2. In summary, here's what happens. I have a...
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...
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: 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
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,...

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.