c++ dll in C# project

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • danmoran
    New Member
    • May 2010
    • 14

    c++ dll in C# project

    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".


    Code:
    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            [DllImport("c:\\Program Files\\DHI\\Calibration\\muEpanet2.dll")]
            public static extern long myMethod (ref string F1, ref long F2, ref long F3);
    
    
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                long errorCode;
                string fileLocation = "c:\\base_zk-M1.res";
                long secondParameter = 13;
                long thirdParameter = 0;
    
    
                errorCode = myMethod (ref fileLocation, ref secondParameter, ref thirdParameter);
            }
    
        }
    thanks so much for your help.
    Last edited by tlhintoq; May 7 '10, 03:18 PM. Reason: [CODE] ...Your code goes between code tags [/CODE]
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    TIP: When you first created your question you were asked to wrap your code with [code] tags.
    [imgnothumb]http://files.me.com/tlhintoq/10jihf[/imgnothumb]
    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. [imgnothumb]http://clint.stlaurent .net/bytes/tags-code.jpg[/imgnothumb]More on tags. They're cool. Check'em out.

    Comment

    • danmoran
      New Member
      • May 2010
      • 14

      #3
      import a C++ dll into C#

      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.

      Code:
      namespace WindowsFormsApplication1
      {
          public partial class Form1 : Form
          {
              // here I call the external dll including its method MUEpanet_RES_Load2Mem_InitHeader
              [DllImport(@"c:\Program Files\DHI\Calibration\muEpanet2.dll")]
              private static extern long myDll(string F1, long F2, long F3);
      
              public Form1()
              {
                  InitializeComponent();
              }
      
              private void button1_Click(object sender, EventArgs e)
              {
                  long errorCode;
                  string fileLocation = @"c:\list.xml";
                  long secondParameter = 13;
                  long thirdParameter = 0;
      
                  errorCode = myDll(fileLocation, secondParameter, thirdParameter);
              }
          }
      }
      Thanks in advance.

      Comment

      • danmoran
        New Member
        • May 2010
        • 14

        #4
        Convert VBA to C#

        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.

        Code:
        Private Declare Function myMethod Lib "c:\myDLL.dll" (ByVal F1 As String, ByVal F2 As Long, ByVal F3 As Long) As Long

        Comment

        • GaryTexmo
          Recognized Expert Top Contributor
          • Jul 2009
          • 1501

          #5
          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.

          Comment

          • danmoran
            New Member
            • May 2010
            • 14

            #6
            Originally posted by GaryTexmo
            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.
            Yes, I google it and my code is OK... but I just can't see what it doesn't work.

            Comment

            • danmoran
              New Member
              • May 2010
              • 14

              #7
              Originally posted by danmoran
              Yes, I google it and my code is OK... but I just can't see what it doesn't work.
              @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

              Comment

              • tlhintoq
                Recognized Expert Specialist
                • Mar 2008
                • 3532

                #8
                Please don't TRIPLE-post your questions. It divides attempts to help you in an organized and cohesive manner. Your threads have been merged

                Comment

                Working...