473,499 Members | 1,593 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

c++ dll in C# project

14 New Member
Im trying to use an external DLL and extract data from the dll. my code is as follows:

myMethod should return a Zero "0". but when I run it I get an error message "vshost.exe has stopped working".


Expand|Select|Wrap|Line Numbers
  1. namespace WindowsFormsApplication1
  2. {
  3.     public partial class Form1 : Form
  4.     {
  5.         [DllImport("c:\\Program Files\\DHI\\Calibration\\muEpanet2.dll")]
  6.         public static extern long myMethod (ref string F1, ref long F2, ref long F3);
  7.  
  8.  
  9.         public Form1()
  10.         {
  11.             InitializeComponent();
  12.         }
  13.  
  14.         private void button1_Click(object sender, EventArgs e)
  15.         {
  16.             long errorCode;
  17.             string fileLocation = "c:\\base_zk-M1.res";
  18.             long secondParameter = 13;
  19.             long thirdParameter = 0;
  20.  
  21.  
  22.             errorCode = myMethod (ref fileLocation, ref secondParameter, ref thirdParameter);
  23.         }
  24.  
  25.     }
thanks so much for your help.
May 7 '10 #1
7 2461
tlhintoq
3,525 Recognized Expert Specialist
TIP: When you first created your question you were asked to wrap your code with [code] tags.

It really does help a bunch. Look how much easier it is to read now that someone has done it for you. Its the button with a '#' on it.

More on tags. They're cool. Check'em out.
May 7 '10 #2
danmoran
14 New Member
I am trying to get a method out of a C++ dll in C#. Can anybody help me I can't extract the method myDll which takes 3 parameters (string, long, long). I get an error message "vshost.exe stopped working " Can anybody tell me what's wrong with the code below.

Expand|Select|Wrap|Line Numbers
  1. namespace WindowsFormsApplication1
  2. {
  3.     public partial class Form1 : Form
  4.     {
  5.         // here I call the external dll including its method MUEpanet_RES_Load2Mem_InitHeader
  6.         [DllImport(@"c:\Program Files\DHI\Calibration\muEpanet2.dll")]
  7.         private static extern long myDll(string F1, long F2, long F3);
  8.  
  9.         public Form1()
  10.         {
  11.             InitializeComponent();
  12.         }
  13.  
  14.         private void button1_Click(object sender, EventArgs e)
  15.         {
  16.             long errorCode;
  17.             string fileLocation = @"c:\list.xml";
  18.             long secondParameter = 13;
  19.             long thirdParameter = 0;
  20.  
  21.             errorCode = myDll(fileLocation, secondParameter, thirdParameter);
  22.         }
  23.     }
  24. }
Thanks in advance.
May 10 '10 #3
danmoran
14 New Member
I have the following code in VBA I would like to convert the same code to C#. the VBA codes calls a c++ dll which includes method myMethod. Thanks so much for your help.

Expand|Select|Wrap|Line Numbers
  1. Private Declare Function myMethod Lib "c:\myDLL.dll" (ByVal F1 As String, ByVal F2 As Long, ByVal F3 As Long) As Long
May 10 '10 #4
GaryTexmo
1,501 Recognized Expert Top Contributor
I think this might be the same as [DllImport] in C#. Try googling that :)

Actually, your other thread uses it... so while I'm not 100% sure, that VB code looks to be the equivalent.
May 10 '10 #5
danmoran
14 New Member
@GaryTexmo
Yes, I google it and my code is OK... but I just can't see what it doesn't work.
May 10 '10 #6
danmoran
14 New Member
@danmoran
@GaryTexmo Yes, I google it and my code is OK... but I just can't see why my code doesn't give me the results I expect from the DLL
May 10 '10 #7
tlhintoq
3,525 Recognized Expert Specialist
Please don't TRIPLE-post your questions. It divides attempts to help you in an organized and cohesive manner. Your threads have been merged
May 10 '10 #8

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

Similar topics

0
1529
by: public heath vb developer | last post by:
We have a solution with 29 projects including a main menu and 28 dlls. One of the projects (Project B) was created by copying an existing project (Project A), making changes including the assembly...
2
4762
by: Rudy Ray Moore | last post by:
How can I modify the project build order of a multi-project workspace under "Visual Studio .net 2003 7.1 c++"? I tried to modify the .sln by hand to influence the build order, but it didn't seem...
1
1782
by: Jerad Rose | last post by:
Hello, I have searched all over for the answer to this, to no avail. I have a web project already set up and running on a remote server, that I created from my home computer. I am now trying...
11
7717
by: Dave | last post by:
I copied the project files from an ASP.NET project on one computer and want to create the project on another computer, There is no connection between the two computers so I simply copied the...
4
2878
by: Brad | last post by:
I'm not one to rant or flame....so please excuse me while I do so for this once. I've now spent a bit of time working with VS2005 beta 2 to see how it functions for web development, especially how...
7
1613
by: Mantorok | last post by:
Hi all We have an ASP.Net project (and the Solution) under source-control. Here is the example - I create the Solution, I create an ASP.Net project and then check it all in to source control,...
6
2800
by: liu | last post by:
Hi all, in my vb.net solution, i have 3 project: 1. Main-this is the startup or the base of my window application. 2. Sales-this is the project that contains all the sales info 3. Product-this...
9
5419
by: Anubhav Jain | last post by:
Hi, I am having few .net source files(.cs or .vb) and I want to dynamically generate the corresponding .net project file(.csproj or .vbproj) for them without using visual studio.So that I could...
3
2175
by: Jerad Rose | last post by:
This is regarding Visual Studio 2003 (framework 1.1). We have several projects/libraries. Of course, many of these reference each other. If we only had one solution, we would simply add all of...
29
2780
by: Tony Girgenti | last post by:
Hello. I'm developing and testing a web application using VS.NET 2003, VB, .NET Framework 1.1.4322, ASP.NET 1.1.4322 and IIS5.1 on a WIN XP Pro, SP2 computer. I'm using a web form. How do I...
0
7132
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
7009
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
7390
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...
0
5475
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4602
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3103
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3094
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
302
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.