Howto: C# DCOM-Remote access from your own .NET App

This section contains user-submitted tutorials.
Post Reply
User avatar
Dravion
Senior user
Senior user
Posts: 1612
Joined: 2015-09-26 11:50
Location: Germany
Contact:

Howto: C# DCOM-Remote access from your own .NET App

Post by Dravion » 2017-07-24 01:09

This Tutorial will show you howto remote access hMailServer progammatically in your Windows Network.

Here you can see how it will look like:
dcom_app_access.png

Requirements:
1) Admin permissions on Client-DCOM and Remote DCOM Computer
2) You need a LAN Network with atleast Windows Vista (without Servicepacks installed)
3) You need to install a hMailServer Version 5.4.x or higher Version on your Remotecomputer
4) You needs a copy of the "hMailServer.tlb" file from your hMailServers\bin Install Directory.
5) You need Visual Studio 2017 for .NET Desktop Development installed (Express will work to)

a)
Install hMailServer on your Remotecomputer, you can get it here: https://www.hmailserver.com/download_fi ... loadid=256

b)
Copy the hMailServer\bin\hMailServer.tlb file to your Programming Computer

c)
Follow this Howto, to enable Remote Access and make sure you can access
your hMailServer remote Computer with hMailAdmin GUI-Program (double check all settings carefully)
viewtopic.php?f=21&t=30392

a1)
If you want to start a fresh C#.NET Project, follow the "add reference and import the
hMailServer.tlb file to get access to all DCOM API's declaration and Interfaces.

a2)
Select Browse and select "hMailServer.tlb" on the next screen and click OK
add_hms_typelib.png
a3)
Now you need the WindowsFormsApp1.7z Archive, unzipp or just goto release bin and execute
WindowsFormsApp1.exe. You can directly access you hMailServer remote computer with it,if you configured everything
the right way as described above.

C# Source snippet: This is basically all you need:

Code: Select all


private void button1_Click(object sender, EventArgs e) {
try {
    var tServerType = Type.GetTypeFromProgID("hMailServer.Application", ed_server.Text);
    var remoteServer = (hMailServer.Application) Activator.CreateInstance(tServerType);
                
    remoteServer.Authenticate(ed_username.Text, ed_password.Text);
    remoteServer.Connect();

    MessageBox.Show(remoteServer.Version, @"Info", MessageBoxButtons.OK);
}
catch (COMException comExc) {
                MessageBox.Show(@"Errordetails:"+comExc, @"Error",
                MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
Notice
VB.NET, C#.NET, C/C++ (native or not) accessing COM/DCOM diffrently then VBScript or Windows Powershell and doesnt
use Typelibrarys at all, so keep this in mind to avoid Problems.
Attachments
WindowsFormsApp1.7z
(54.4 KiB) Downloaded 296 times

Post Reply