473,383 Members | 1,792 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.

Trouble adding a reference to C++ DLL in C#

A third party vendor has provided me with a DLL authored in C++ .Net. The
vendor's package includes the DLL, .lib and all necessary .h files and sample
code to develop a C++ .NET app. For the C++ sample project to run, the .lib
file needs to be added to the additional dependencies, the Stack Reserve Size
needs to be 2meg, the WIN32 directive must be included, and the runtime
library must be Multi-threaded Debug DLL. The sample app includes a few
"extern template class DLLIMPORT std::vector<namespace::someclass*>"
statements to access the objects in the external library. I can get the C++
sample app to work just fine.

I am not a C++ developeer and would much rather develop an app using C# or
VB.Net, but when I try to add a reference to the DLL, I receive a "This is
not a valid assembly or COM component" error message.

How can I go about accessing the objects and methods in this external
library in a VB.Net or C# app?
Nov 17 '05 #1
1 1739
You would need to create a managed wrapper for it.
Something like:
Create a mixed dll that has a class to expose to C#, and that links to the
..lib file and includes the .h file that they provide, like
//thedll.cpp
#include "3rdparty.h" //contains, say, extern void the3rdpartyfunc();
#using <mscorlib.dll>
using namespace System;
public __gc class ThirdParty
{
public:
static void Call3rdPartyFunc()
{
the3rdpartyfunc();
}
};
You should be able to then call this from C#.

"Lee Greco" <Lee Gr***@discussions.microsoft.com> wrote in message
news:98**********************************@microsof t.com...
A third party vendor has provided me with a DLL authored in C++ .Net. The
vendor's package includes the DLL, .lib and all necessary .h files and
sample
code to develop a C++ .NET app. For the C++ sample project to run, the
.lib
file needs to be added to the additional dependencies, the Stack Reserve
Size
needs to be 2meg, the WIN32 directive must be included, and the runtime
library must be Multi-threaded Debug DLL. The sample app includes a few
"extern template class DLLIMPORT std::vector<namespace::someclass*>"
statements to access the objects in the external library. I can get the
C++
sample app to work just fine.

I am not a C++ developeer and would much rather develop an app using C# or
VB.Net, but when I try to add a reference to the DLL, I receive a "This is
not a valid assembly or COM component" error message.

How can I go about accessing the objects and methods in this external
library in a VB.Net or C# app?

Nov 17 '05 #2

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

Similar topics

9
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my...
1
by: Greg | last post by:
I have the following code (a one line function) I'm trying to calculate a value for text field matPerPiece# where # is a row number I provide. The value is calculated from text fields...
20
by: Peter E. Granger | last post by:
I'm having a strange problem (or at least it seems strange to me) trying to display a MessageBox in a VC++ .NET forms application. If I put the call to MessageBox::Show in the form's .h file, it...
1
by: brad langhorst | last post by:
I'm going over a result set and adding results as levels on the tree control. when stepping through the code i see execution switch to the calling subroutine as soon as the parentnode.nodes.add...
3
by: Olivier BESSON | last post by:
Hello, I have a web service of my own on a server (vb.net). I must declare it with SoapRpcMethod to be used with JAVA. This is a simple exemple method of my vb source : ...
10
by: Hendri Adriaens | last post by:
Hi, I'm trying to automate the creation of an excel file via COM. I copied my code below. I read many articles about how to release the COM objects that I create. The code below runs just fine...
9
by: Nathan Sokalski | last post by:
I am trying to use the System.Array.ForEach method in VB.NET. The action that I want to perform on each of the Array values is: Private Function AddQuotes(ByVal value As String) As String Return...
8
by: Jason | last post by:
Hello, I am trying to utilitze the AJAX Control toolkit in my asp.net project. I have added a reference to AjaxControlToolkit.dll, and in my page, added these lines of code: ...
1
by: =?Utf-8?B?Sm9zaFA=?= | last post by:
I am new to C# and windows programming. I am trying do create something fairly simple (at least I think). I have 1 form (Form1). On Form1 I have a listbox. I also have a Class (Class1). Class1...
3
by: kkao77 | last post by:
can you show me in more detail? I have same problem where on the page it's https://service.premilance.com/Company.svc, but the svcutil tells me to get it from https://pserver1/Company.svc?wsdl...
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
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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: 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:
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
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.