14.4.4 C# and Visual C Sharp

 

C# and Visual C#.NET (C Sharp user programs).

 

We do not know if Bwdllobj (an Atl COM Dll) or viewdll.dll (a Win32 Dll) can be used with C# directly. If they can not be used with C# directly, users can always develop their own interface using our Bwdllobj or viewdll.dll. We think this is a C# developing issue not a WebAccess supporting issue. The following information may help users to decide how to use Bwdllobj or viewdll.dll with C#. Please note that we do not have any C# experience. The contents listed below are from http://blogs.msdn.com/deeptanshuv/archive/2005/06/26/432870.aspx.

 

 

Managed Exe calling Native Dll

(a) Create an Atl COM Dll from wizard say Atl Dll

(b) Add an ATL Simple Object AtlObj

(c) Add a method to AtlObj say factorial(), you will need to add it to the .idl file to expose it from the COM object

(d) Create a C# console app

(e) project->right click->Add Reference

(f) In the add reference dialog, select the COM tab, find your COM component and add the reference to it

(g) You can now create the AtlObj object as of any other class and call its methods.

You can also accomplish this without using COM by simply using exports/imports.

Managed Exe calling Native Dll using import

(a) Create a Win32 Dll that exports symbols, you can do this from the wizard, just make sure the "export symbols" checkbox is checked.

(b) You need to put extern "C" {} around the definition & declaration of the exported function say fnWin32Dll()

(b) Now create your C# Exe, add using

System.Runtime.InteropServices;

(c) add code

[[DllImport("Win32 Dll.dll")]

public static extern int fnWin32Dll(); ' this is the C++ function exposed by the dll

 

(d) Now you can just call the function in your code

int var = fnWin32Dll();

Note that your C# Exe needs to be able to find the Dll. You can copy the Dll next to the C# Exe and it will run just fine.  .