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

Import C++ DLL into C#

I have a DLL written in C++. A number of the functions both expect a string
(BSTR) and also return a string (BSTR)

How do I define this in C# ?

Sep 20 '07 #1
4 13891
Michael,

Is this a regular C++ dll, or is it a COM dll? If it is, then you can
use the dll through COM interop (just adding the reference in VS.NET will do
it for you).

If it is not a COM dll, but rather a regular DLL with exported
functions, then you can declare the functions in C# code and call it through
the P/Invoke layer.

If neither of these cases apply, then you will need to change the (or
create another) DLL which will expose the functionality in those ways, or
create a managed code wrapper using C++/CLI.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Michael Tissington" <mt*********@newsgroup.nospamwrote in message
news:%2******************@TK2MSFTNGP02.phx.gbl...
>I have a DLL written in C++. A number of the functions both expect a string
(BSTR) and also return a string (BSTR)

How do I define this in C# ?

Sep 20 '07 #2
Its a regular DLL with exported functions ...
Where do I find information about the P/Invoke layer ?
Sep 20 '07 #3
Michael,

Here's a quick view at how P/Invoke works in C#:

http://msdn2.microsoft.com/en-us/lib...81(vs.71).aspx

But also I suggest you get some hands-on experience with P/Invoke by running
a few samples (such as from the Windows API). Here are some sample tutorials
that call unmanaged functions:

http://www.geekpedia.com/tutorial219...rom-Files.html
http://www.geekpedia.com/tutorial218...ng-Csharp.html
http://www.geekpedia.com/tutorial174...y-in-.NET.html

Do a couple of these cause once you learn how to use P/Invoke in C# you'll
never forget.

Regards,
Mr. T.

"Michael Tissington" <mt*********@newsgroup.nospamwrote in message
news:el****************@TK2MSFTNGP04.phx.gbl...
Its a regular DLL with exported functions ...
Where do I find information about the P/Invoke layer ?
Sep 20 '07 #4
Thanks - it turns out that I just needed to marshall the return value.
Something like ... AS <MarshalAs(UnmanagedType.AnsiBStr)String
Sep 20 '07 #5

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

Similar topics

0
by: Stian Søiland | last post by:
all examples performed with: Python 2.3+ (#2, Aug 10 2003, 11:09:33) on linux2 (2, 3, 0, 'final', 1) This is a recursive import:
0
by: Vio | last post by:
Hi, I've been trying to embed (statically) wxPy alongside an embedded py interpreter on a linux/gtk box. At one point, for some reason misc.o linking reported "multiple definitions of...
0
by: John Roth | last post by:
I've found a case where it seems that Python is importing two copies of a module without any reason or indication. It took me a while to verify that this is what is occuring: I had to write a...
5
by: Steve Holden | last post by:
This is even stranger: it makes it if I import the module a second time: import dbimp as dbimp import sys if __name__ == "__main__": dbimp.install() #k = sys.modules.keys() #k.sort() #for...
1
by: mark | last post by:
In Access 2000 and 2002, I have created an import specification to import the fixed-width recordset below into an existing table. I am having strange problems with the import of the date and time...
4
by: Bruce W. Roeser | last post by:
All, I'm reading a book by Charles Petzold (Programming VS.Net). Pretty good content but am confused about the difference. From the text: ...
2
by: Jon | last post by:
It appears that (windows) python searches in the current working directory before looking in the local site-packages directory, or that '.' comes first in sys.path? The problem arises when I made...
7
by: Ron Adam | last post by:
from __future__ import absolute_import Is there a way to check if this is working? I get the same results with or without it. Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) on win 32 ...
5
by: W. Watson | last post by:
Is there a single source that explains these statements? ------------------------------ from Tkinter import * from Numeric import * import Image import ImageChops import ImageTk import time...
9
by: rsoh.woodhouse | last post by:
Hi, I'm trying to work out some strange (to me) behaviour that I see when running a python script in two different ways (I've inherited some code that needs to be maintained and integrated with...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.