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

Using a C++ DLL in C#

HaLo2FrEeEk
404 256MB
I have a DLL written in C++, and it contains functionality that I need for a C# program I'm writing.

I know the names of the methods that I need, in fact I have all the method names in the DLL file, it's just using them that I'm having a problem with. Originally I thought I was out of luck because I couldn't add the DLL as a reference to my solution, but I found out how to use DllImport and tried that, but I couldn't get anywhere, so I searched Google and came up with something. This is my code for one of the functions in FATXLib.dll:

Expand|Select|Wrap|Line Numbers
  1. [DllImport("FATXLib.dll")]
  2. public static extern List<string> CheckDivices(FATX.DeviceType.Types DeviceToSearchFor);
Yeah, the word device is spelled wrong in the dll, so I kept it that way.

Anyway, I then have this method:

Expand|Select|Wrap|Line Numbers
  1. public static List<string> Main2()
  2. {
  3.     return CheckDivices(FATX.DeviceType.Types.FATX_DEVICE_360HDD);
  4. }
And finally I have a button on my form which, when clicked, does this:

Expand|Select|Wrap|Line Numbers
  1. private void button1_Click(object sender, EventArgs e)
  2. {
  3.     List<string> devices = Main2();
  4.     MessageBox.Show(devices.Count.ToString());
  5. }
At which point I get this error:

Cannot marshal 'return value': Generic types cannot be marshaled.

I'm stumped. How can I get around this?
May 16 '10 #1
2 3117
tlhintoq
3,525 Expert 2GB
Are you sure your C++ dll returns a List<> ?? Seems unlikely since List<> is a .NET type. Not impossible, just highly unlikely. I would sooner suspect it returns an array, or an address to an array.

It's a fairly pricey library. Surely the maker must supply some support and instructions for it's use.
May 16 '10 #2
HaLo2FrEeEk
404 256MB
Yah, it is expensive, but it came with a program I downloaded and I wanted to try using it. I found an alternative library that's not only free, it's open source, and it does exactly what I want.
May 16 '10 #3

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

Similar topics

17
by: beliavsky | last post by:
Many of my C++ programs have the line using namespace std; but the "Accelerated C++" book of Koenig and Moo has many examples where the library names are included one at a time, for example ...
5
by: Enos Meroka | last post by:
Hallo, I am a student doing my project in the university.. I have been trying to compile the program using HP -UX aCC compiler, however I keep on getting the following errors. ...
12
by: Calum Grant | last post by:
In older C++ computer books, you'll often see using namespace std; even in my 1996 copy of Stroustrup. Nowadays, it seems to be considered better to qualify names to make it clearer what...
0
by: canasdaq | last post by:
Can anyone please help me. I was looking at the article "http://www.eggheadcafe.com/articles/20030603.asp". I am new to .net and know nothing in c#. I want to write a menu in asp.net. Can anyone...
11
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on...
3
by: John Spiegel | last post by:
Hi All, I've been working on building a .dll in C# (framework 1.1) and using it in VFP8. As always, the example that runs so smoothly in the article fails at a rather basic point in practice. ...
8
by: acb | last post by:
Hi, I wrote a DLL Component (using Visual Studio 2005) and managed to include it into a C# Console application. I am now trying to include this component into a Web project. I copy the DLL...
0
by: Eugene Anthony | last post by:
The problem with my coding is that despite removing the records stored in the array list, the rptPages repeater control is still visible. The rptPages repeater control displayes the navigation...
3
by: JDeats | last post by:
I have some .NET 1.1 code that utilizes this technique for encrypting and decrypting a file. http://support.microsoft.com/kb/307010 In .NET 2.0 this approach is not fully supported (a .NET 2.0...
8
by: =?Utf-8?B?Q2hyaXMgSGFsY3Jvdw==?= | last post by:
Hi there I've successfully added some .NET validation controls to a page (using <asp:RequiredFieldValidator ...), however when I try to set the 'display' property to 'dynamic', my page then...
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: 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: 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,...
0
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...
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...

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.