calling a C dll or executable from vb.net

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.
 
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...
 
* "=?Utf-8?B?UGF1bA==?= said:
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.
 
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);
}
 
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)
 
* "=?Utf-8?B?UGF1bA==?= said:
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.
 
Back
Top