473,385 Members | 1,712 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,385 software developers and data experts.

calling a C dll or executable from vb.net

Hi I have a vb.net app and am trying to call a C program from it, perhaps a dll or executable. This is unmanaged code, just wondering if someone could provide a brief example? Thanks Paul.
Nov 20 '05 #1
5 4116
On 2004-01-26, Paul <an*******@discussions.microsoft.com> wrote:
Hi I have a vb.net app and am trying to call a C program from it, perhaps a dll or executable. This is unmanaged code, just wondering if someone could provide a brief example? Thanks Paul.


Paul,

An executable can be run from VB's shell statement or you can use the
System.Diagnostics.Process class if you need more control. If your
trying to call exported functions, then you'll want to look into using
P/Invoke... If you have the C definitions for the functions, we would
be happy to help you translate some of them and give you pointers...

--
Tom Shelton [MVP]
Nov 20 '05 #2
* "=?Utf-8?B?UGF1bA==?=" <an*******@discussions.microsoft.com> scripsit:
Hi I have a vb.net app and am trying to call a C program from it,
perhaps a dll or executable. This is unmanaged code, just wondering if
someone could provide a brief example? Thanks Paul.


\\\
Imports System.Diagnostics
..
..
..
Process.Start("C:\Foo.exe")
///

Or, in VB.NET:

\\\
Shell("C:\Foo.exe")
///

For calling exported functions of a native DLL, have a look at the
'Declare' statement and/or the 'DllImportAttribute' class.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #3
thanks for the information. How would I call this simple c function from vb.net passing params to it and also receiving the return param.
vb.net want to pass in 3,4 and get the integer results
results = sum_a_and_b(3,4)

c function
int sum_a_and_b (int a, int b)
{
int c;
c = a + b;
return (c);
}
Nov 20 '05 #4
thanks for the information. How would I call this simple c function from vb.net passing params to it and also receiving the return param.
vb.net want to pass in 3,4 and get the integer result
results = sum_a_and_b(3,4

c functio
int sum_a_and_b (int a, int b

int c
c = a + b
return (c)
Nov 20 '05 #5
* "=?Utf-8?B?UGF1bA==?=" <an*******@discussions.microsoft.com> scripsit:
thanks for the information. How would I call this simple c function from vb.net passing params to it and also receiving the return param.
vb.net want to pass in 3,4 and get the integer results
results = sum_a_and_b(3,4)

c function
int sum_a_and_b (int a, int b)
{
int c;
c = a + b;
return (c);
}


You will have to export the function as 'stdcall': '_declspec(dllexport)
<datatype> _stdcall'. You will get more info on this topic in the C++
group.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #6

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

Similar topics

1
by: Chandra Mohan | last post by:
Hi All, I have a requirement of calling a Executable from SQL Server. I know we can use - EXEC @result = Master..xp_cmdshell @<command_string> However I want to get the return value (int)...
5
by: Al the programmer | last post by:
I have a dll that consists of unmanaged C++ routines. I can call a function in the dll from a C++ executable, but not from a C# executable. I am calling an independent function, not a class. C#...
17
by: Bill Grigg | last post by:
I have been successfully calling DLL's using VC++ 6.0 and also using VC++7.1 (.NET). I only mention this because I have never felt comfortable with the process, but nonetheless it did work....
6
by: Marlene Arauz Martin | last post by:
Hello, How's everybody??? I have an aspx. page that is calling an executable,....like this... System.Diagnostics.ProcessStartInfo psi= new System.Diagnostics.ProcessStartInfo();...
2
by: Daniel Lidström | last post by:
I'm using a library called fyba. This library reads and writes files in a format called sosi. fyba uses the following code to determine if the calling process has own methods to handle errors,...
5
by: guxu | last post by:
Can anyone tell me the prons and cons having C# program calling an executable or DLL? I always do not like the idea of having one executable calling another executable since I can have more...
15
by: dspfun | last post by:
Hi, Is it possible to print the function name of the calling function? For example, f1() and f2() both calls f3(), in f3() I would like to print the name of the function calling f3() which...
1
by: muhamad.abbas | last post by:
Hello Folks, This is what i am required to do. Call an executable from my python script, and when the executable is finished running, i should continue with my python script. I have tried...
4
by: Darin | last post by:
I have a public class that I use to read columns out of a SQL database. In the try, catch, loop I want to display the error, and in the error I want to display the calling routine (and helpfully...
7
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post by:
I have a C# logging assembly with a static constructor and methods that is called from another C# Assembly that is used as a COM interface for a VB6 Application. Ideally I need to build a file...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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
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: 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
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,...

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.