Convert VBA code to C#

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

    Convert VBA code to C#

    I have VBA code calling an external dll file, within the dll exist method "getErrorCo de".

    I would like to know how I should call the dll file from C#.

    Code:
    Private Declare Function getErrorCode Lib "c:\master.dll" (ByVal F1 As String, ByVal F2 As Long, ByVal F3 As Long) As Long
    with in my code I call the method getErrorCode like this
    Code:
    ErrCode = getErrorCode(fileName, 13, 1)
    thanks in advance
    Daniel
  • GaryTexmo
    Recognized Expert Top Contributor
    • Jul 2009
    • 1501

    #2
    I think it might be...
    Code:
    [DllImport("<DLL NAME HERE>")]
    <method declaration here>
    Give that a try... google DllImport if it doesn't, I'm pretty sure that's what you need.

    Comment

    • danmoran
      New Member
      • May 2010
      • 14

      #3
      Originally posted by danmoran
      I have VBA code calling an external dll file, within the dll exist method "getErrorCo de".

      I would like to know how I should call the dll file from C#.

      Code:
      Private Declare Function getErrorCode Lib "c:\master.dll" (ByVal F1 As String, ByVal F2 As Long, ByVal F3 As Long) As Long
      with in my code I call the method getErrorCode like this
      Code:
      ErrCode = getErrorCode(fileName, 13, 1)
      thanks in advance
      Daniel
      Thanks for your prompt response. I tried the DLLImport but for some reason I can get it to work. I came with the following code.

      However; I can't get the method to return an errorCode number.


      Code:
              [DllImport("c:\\Program Files\\DHI\\Calibration\\muEpanet2.dll")]
              static extern long MUEpanet_RES_Load2Mem_InitHeader(ref string F1, ref long F2, ref long F3);
      
              [DllImport("c:\\Program Files\\DHI\\Calibration\\muEpanet2.dll")]
              static extern long MUEpanet_RES_GetTSCount();
              
              public UI()
              {
                  InitializeComponent();
              }
              public iCommand myParent;
      
              
      
              private void UI_Load(object sender, EventArgs e)
              {
                  long errorCode;
                  string fileLocation = "c:\\MyFiles\\MU User Tool Turbidity\\base_zk-M1.res";
                  long secondParameter = 13;
                  long thirdParameter = 0;
                  long count;
      
                  count = MUEpanet_RES_GetTSCount();
      
      
                  errorCode = MUEpanet_RES_Load2Mem_InitHeader(ref fileLocation, ref secondParameter, ref thirdParameter);
              }

      Comment

      Working...