Board index » Visual Studio » calling a C dll or executable from vb.net

calling a C dll or executable from vb.net

Visual Studio186
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.


-
 

Re:calling a C dll or executable from vb.net

On 2004-01-26, Paul <anonymous@discussions.microsoft.com>wrote:

Quote
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]

-

Re:calling a C dll or executable from vb.net

* "=?Utf-8?B?UGF1bA==?=" <anonymous@discussions.microsoft.com>scripsit:

Quote
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]

<www.mvps.org/dotnet>">www.mvps.org/dotnet>

-

Re:calling a C dll or executable from vb.net

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);

}

-

Re:calling a C dll or executable from vb.net

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)





-

Re:calling a C dll or executable from vb.net

* "=?Utf-8?B?UGF1bA==?=" <anonymous@discussions.microsoft.com>scripsit:

Quote
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]

<www.mvps.org/dotnet>">www.mvps.org/dotnet>

-