473,396 Members | 2,010 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,396 software developers and data experts.

Convert VBA code to C#

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

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

Expand|Select|Wrap|Line Numbers
  1. Private Declare Function getErrorCode Lib "c:\master.dll" (ByVal F1 As String, ByVal F2 As Long, ByVal F3 As Long) As Long
  2.  
with in my code I call the method getErrorCode like this
Expand|Select|Wrap|Line Numbers
  1. ErrCode = getErrorCode(fileName, 13, 1)
  2.  
thanks in advance
Daniel
Jul 12 '10 #1
2 3384
GaryTexmo
1,501 Expert 1GB
I think it might be...
Expand|Select|Wrap|Line Numbers
  1. [DllImport("<DLL NAME HERE>")]
  2. <method declaration here>
Give that a try... google DllImport if it doesn't, I'm pretty sure that's what you need.
Jul 12 '10 #2
@danmoran
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.


Expand|Select|Wrap|Line Numbers
  1.         [DllImport("c:\\Program Files\\DHI\\Calibration\\muEpanet2.dll")]
  2.         static extern long MUEpanet_RES_Load2Mem_InitHeader(ref string F1, ref long F2, ref long F3);
  3.  
  4.         [DllImport("c:\\Program Files\\DHI\\Calibration\\muEpanet2.dll")]
  5.         static extern long MUEpanet_RES_GetTSCount();
  6.  
  7.         public UI()
  8.         {
  9.             InitializeComponent();
  10.         }
  11.         public iCommand myParent;
  12.  
  13.  
  14.  
  15.         private void UI_Load(object sender, EventArgs e)
  16.         {
  17.             long errorCode;
  18.             string fileLocation = "c:\\MyFiles\\MU User Tool Turbidity\\base_zk-M1.res";
  19.             long secondParameter = 13;
  20.             long thirdParameter = 0;
  21.             long count;
  22.  
  23.             count = MUEpanet_RES_GetTSCount();
  24.  
  25.  
  26.             errorCode = MUEpanet_RES_Load2Mem_InitHeader(ref fileLocation, ref secondParameter, ref thirdParameter);
  27.         }
Jul 12 '10 #3

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

Similar topics

2
by: Graham Feeley | last post by:
Hi I have data resembling like this Clearing, The Italian Job, The Final Cut, The Manson Family, The I would like some code to convert the data to The Clearing The Italian Job The Final Cut
1
by: Diego | last post by:
Hi, Anyone can help to convert this code to C#? Public Class MonImageConverter Inherits System.Windows.Forms.AxHost Public Sub New() MyBase.New("59EE46BA-677D-4d20-BF10-8D8067CB8B33") 'note...
8
by: Mike | last post by:
is there a tool that will convert cold fusion code to C#? Or anything out there to help in this process? thx
15
by: Tanzim Saqib | last post by:
I've been trying to learn VB.NET. I know VB6. I can not convert the following VB6 code segment to VB.NET In VB 6: ' In a module starts here: Public Declare Function SetTimer Lib "user32"...
3
by: Dushyant | last post by:
Hello everyone, I am working on converting one code from VB to VB.NET. I am stuck at some point, please help me how to convert following code from VB to VB.NET : Dim xImage As...
2
by: shapper | last post by:
Hello, Could someone, please, convert the following code line to VB.NET? bool containsValue = myList.Any(item =item.NameParameter == nameParameterValue); (This is .NET 3.5. I couldn't find...
1
by: shapper | last post by:
Hello, I am having problems in converting the following code line to VB.NET: Control list = MyFun(myControl, delegate(Control ctl) { ctl.ID == "MyControl"; }); Could someone please help me...
4
by: Sam | last post by:
I am new in software development, and need some help. Please help me convert a class written in c# to vb.net. Thanks, Sam
3
mshmyob
by: mshmyob | last post by:
I am new to vb.net and would like to be able to convert the following code to it's own function - either inside the current module or better yet in a seperate class. This code currently runs in...
2
by: royhoja | last post by:
How do i convert the following code into a function? What parameters would be in the function? printingform(???,???) #include <stdio.h> #include <string.h> int main() { int i;
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
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
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
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,...

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.