Ecng.Interop.Windows 1.0.390

dotnet add package Ecng.Interop.Windows --version 1.0.390
                    
NuGet\Install-Package Ecng.Interop.Windows -Version 1.0.390
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Ecng.Interop.Windows" Version="1.0.390" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Ecng.Interop.Windows" Version="1.0.390" />
                    
Directory.Packages.props
<PackageReference Include="Ecng.Interop.Windows" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Ecng.Interop.Windows --version 1.0.390
                    
#r "nuget: Ecng.Interop.Windows, 1.0.390"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Ecng.Interop.Windows@1.0.390
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Ecng.Interop.Windows&version=1.0.390
                    
Install as a Cake Addin
#tool nuget:?package=Ecng.Interop.Windows&version=1.0.390
                    
Install as a Cake Tool

Interop.Windows

A .NET library providing Windows-specific interoperability utilities for working with Windows APIs, DDE (Dynamic Data Exchange), and threading operations.

Overview

Interop.Windows provides essential Windows platform utilities including:

  • Windows API helper methods
  • DDE (Dynamic Data Exchange) client and server for Excel integration
  • Threading helpers for STA/MTA apartment state management
  • Windows security and access control management

Installation

This library is part of the Ecng framework and targets .NET 6.0+ with Windows-specific features.

Components

WinApi

Static utility class providing Windows API helper methods.

Get Screen Parameters

Retrieves screen boundaries for a specific window:

using Ecng.Interop;

IntPtr windowHandle = // ... your window handle
WinApi.GetScreenParams(windowHandle, out int left, out int top, out int width, out int height);

Console.WriteLine($"Screen: Left={left}, Top={top}, Width={width}, Height={height}");
Manage Application Auto-Run

Control whether your application starts automatically with Windows:

using Ecng.Interop;

// Enable auto-run
string appName = "MyApplication";
string exePath = @"C:\Program Files\MyApp\MyApp.exe";
WinApi.UpdateAutoRun(appName, exePath, enabled: true);

// Disable auto-run
WinApi.UpdateAutoRun(appName, exePath, enabled: false);

WindowsThreadingHelper

Extension methods for managing thread apartment states and executing code in specific threading contexts.

Execute Code in STA Thread

Run code that requires Single-Threaded Apartment (e.g., clipboard operations, COM interop):

using Ecng.Interop;

// Execute action in STA thread
Action clipboardOperation = () => {
    Clipboard.SetText("Hello from STA thread");
};
clipboardOperation.InvokeAsSTA();

// Execute function in STA thread and get result
Func<string> getClipboardText = () => {
    return Clipboard.GetText();
};
string text = getClipboardText.InvokeAsSTA();
Console.WriteLine($"Clipboard content: {text}");
Set Thread Apartment State
using System.Threading;
using Ecng.Interop;

var thread = new Thread(() => {
    // Your code here
});

// Set to STA
thread.STA().Start();

// Or set to MTA
var mtaThread = new Thread(() => {
    // Your code here
}).MTA();
mtaThread.Start();

WindowsGrandAccess

Manages Windows security permissions for window stations and desktops.

Grant Access to Window Station and Desktop

Temporarily grant a user access to the current window station and desktop (useful for service scenarios):

using Ecng.Interop;

string username = "DOMAIN\\ServiceAccount";

using (var token = WindowsGrandAccess.GrantAccessToWindowStationAndDesktop(username))
{
    // The specified user now has access to the window station and desktop
    // Perform operations that require this access

    // Access is automatically restored when disposed
}

DDE Integration (Excel)

Classes for integrating with Excel via Dynamic Data Exchange protocol.

XlsDdeClient - Send Data to Excel
using Ecng.Interop.Dde;

// Configure DDE settings
var settings = new DdeSettings
{
    Server = "EXCEL",
    Topic = "[Book1.xlsx]Sheet1",
    RowOffset = 0,      // Start from row 0
    ColumnOffset = 0,   // Start from column 0
    ShowHeaders = true  // Include header row
};

// Create and start client
using var client = new XlsDdeClient(settings);
client.Start();

// Prepare data
var data = new List<IList<object>>
{
    // Header row
    new List<object> { "Name", "Value", "Date" },
    // Data rows
    new List<object> { "Item 1", 100, DateTime.Now },
    new List<object> { "Item 2", 200, DateTime.Now }
};

// Send data to Excel
client.Poke(data);

// Clean up
client.Stop();
XlsDdeServer - Receive Data from Excel
using Ecng.Interop.Dde;

// Create server with callbacks
var server = new XlsDdeServer(
    service: "MyDdeService",
    poke: (topic, rows) => {
        Console.WriteLine($"Received data for topic: {topic}");
        foreach (var row in rows)
        {
            foreach (var cell in row)
            {
                Console.Write($"{cell}\t");
            }
            Console.WriteLine();
        }
    },
    error: (ex) => {
        Console.WriteLine($"DDE Error: {ex.Message}");
    }
);

// Start the server
server.Start();

// Server is now listening for Excel to send data
// Keep application running...

// When done
server.Dispose();
DdeSettings Configuration
using Ecng.Interop.Dde;
using Ecng.Serialization;

var settings = new DdeSettings
{
    Server = "EXCEL",              // DDE server name
    Topic = "[Book1.xlsx]Sheet1",  // Excel workbook and sheet
    RowOffset = 2,                 // Skip first 2 rows
    ColumnOffset = 1,              // Skip first column
    ShowHeaders = false            // Don't include headers
};

// Settings can be persisted
var storage = new SettingsStorage();
settings.Save(storage);

// And loaded later
var loadedSettings = new DdeSettings();
loadedSettings.Load(storage);

// Clone settings
var clonedSettings = settings.Clone();

Usage Examples

Complete Excel DDE Data Export

using Ecng.Interop.Dde;

public class ExcelExporter
{
    private XlsDdeClient _client;

    public void Initialize()
    {
        var settings = new DdeSettings
        {
            Server = "EXCEL",
            Topic = "[Report.xlsx]Data",
            ShowHeaders = true
        };

        _client = new XlsDdeClient(settings);
        _client.Start();
    }

    public void ExportData(IEnumerable<DataRow> dataRows)
    {
        var excelData = new List<IList<object>>
        {
            // Headers
            new List<object> { "ID", "Name", "Price", "Quantity" }
        };

        // Add data rows
        foreach (var row in dataRows)
        {
            excelData.Add(new List<object>
            {
                row.Id,
                row.Name,
                row.Price,
                row.Quantity
            });
        }

        _client.Poke(excelData);
    }

    public void Cleanup()
    {
        _client?.Stop();
        _client?.Dispose();
    }
}

Windows Service with Clipboard Access

using Ecng.Interop;

public class WindowsService
{
    public string GetClipboardContent()
    {
        // Services run in non-interactive sessions
        // Use STA thread to access clipboard
        return new Func<string>(() =>
        {
            try
            {
                return Clipboard.GetText();
            }
            catch
            {
                return string.Empty;
            }
        }).InvokeAsSTA();
    }

    public void SetClipboardContent(string text)
    {
        new Action(() =>
        {
            Clipboard.SetText(text);
        }).InvokeAsSTA();
    }
}

Requirements

  • .NET 6.0 or later
  • Windows operating system
  • For DDE functionality: Microsoft Excel or compatible DDE server
  • Dependencies:
    • Ecng.Common
    • Ecng.Collections
    • Ecng.Serialization
    • NDde (for DDE support)
    • Windows.Win32 (for P/Invoke)

Platform Support

This library is Windows-specific and requires:

  • Target framework: net6.0-windows or net10.0-windows
  • Windows Forms references for some functionality
  • Windows Registry access for auto-run features

Notes

  • DDE is a legacy protocol; consider modern alternatives for new applications
  • STA thread invocation creates new threads; use sparingly for performance-critical code
  • Window station access modifications require appropriate Windows permissions
  • Always dispose of DDE clients and servers properly to release resources

Thread Safety

  • WinApi: Thread-safe (static methods)
  • WindowsThreadingHelper: Thread-safe (creates new threads)
  • XlsDdeClient: Not thread-safe; use one instance per thread or synchronize access
  • XlsDdeServer: Thread-safe internally; callbacks are dispatched on dedicated threads

License

Part of the Ecng framework. See the main repository for licensing information.

Product Compatible and additional computed target framework versions.
.NET net6.0-windows7.0 is compatible.  net7.0-windows was computed.  net8.0-windows was computed.  net9.0-windows was computed.  net10.0-windows was computed.  net10.0-windows7.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Ecng.Interop.Windows:

Package Downloads
StockSharp.Xaml

Misc graphical components. More info on web site https://stocksharp.com/store/

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.390 40 12/22/2025
1.0.389 76 12/21/2025
1.0.388 191 12/19/2025
1.0.387 225 12/19/2025
1.0.386 261 12/17/2025
1.0.385 243 12/15/2025
1.0.384 237 12/15/2025
1.0.383 205 12/14/2025
1.0.382 108 12/12/2025
1.0.381 108 12/12/2025
1.0.380 101 12/12/2025
1.0.379 107 12/12/2025
1.0.378 118 12/12/2025
1.0.377 665 12/2/2025
1.0.376 672 12/2/2025
1.0.375 668 12/2/2025
1.0.374 254 11/30/2025
1.0.373 117 11/29/2025
1.0.372 121 11/28/2025
1.0.371 130 11/28/2025
1.0.370 181 11/27/2025
1.0.369 189 11/24/2025
1.0.368 188 11/24/2025
1.0.367 186 11/23/2025
1.0.366 163 11/23/2025
1.0.365 209 11/22/2025
1.0.364 406 11/20/2025
1.0.363 405 11/18/2025
1.0.362 400 11/18/2025
1.0.361 288 11/13/2025
1.0.360 286 11/13/2025
1.0.359 236 11/10/2025
1.0.358 148 11/1/2025
1.0.357 194 10/28/2025
1.0.356 191 10/27/2025
1.0.355 187 10/27/2025
1.0.354 117 10/25/2025
1.0.353 146 10/11/2025
1.0.352 159 10/3/2025
1.0.351 196 9/28/2025
1.0.350 201 9/25/2025
1.0.349 1,957 9/2/2025
1.0.348 490 8/30/2025
1.0.347 236 8/30/2025
1.0.346 204 8/19/2025
1.0.345 181 8/15/2025
1.0.344 207 8/14/2025
1.0.343 828 7/16/2025
1.0.342 422 7/14/2025
1.0.341 206 7/13/2025
1.0.340 210 7/13/2025
1.0.339 174 7/12/2025
1.0.338 327 7/8/2025
1.0.337 301 7/4/2025
1.0.336 220 7/2/2025
1.0.335 678 6/16/2025
1.0.334 364 6/9/2025
1.0.333 277 6/8/2025
1.0.332 438 5/21/2025
1.0.331 223 5/17/2025
1.0.330 515 5/12/2025
1.0.329 314 5/12/2025
1.0.328 303 5/12/2025
1.0.327 238 5/11/2025
1.0.326 248 5/11/2025
1.0.325 253 5/11/2025
1.0.324 234 5/11/2025
1.0.323 239 5/11/2025
1.0.322 233 5/11/2025
1.0.321 176 5/10/2025
1.0.320 170 5/10/2025
1.0.319 224 5/6/2025
1.0.318 239 5/2/2025
1.0.317 306 4/17/2025
1.0.316 293 4/15/2025
1.0.315 247 4/12/2025
1.0.314 216 4/12/2025
1.0.313 826 3/22/2025
1.0.312 272 3/20/2025
1.0.311 269 3/20/2025
1.0.310 257 3/19/2025
1.0.309 701 2/26/2025
1.0.308 223 2/26/2025
1.0.307 611 2/6/2025
1.0.306 216 2/6/2025
1.0.305 218 2/6/2025
1.0.304 236 2/6/2025
1.0.303 223 2/5/2025
1.0.302 230 2/5/2025
1.0.301 224 2/5/2025
1.0.300 247 2/3/2025
1.0.299 225 2/2/2025
1.0.298 216 2/1/2025
1.0.297 227 1/31/2025
1.0.296 215 1/30/2025
1.0.295 221 1/26/2025
1.0.294 213 1/21/2025
1.0.293 233 1/20/2025
1.0.292 196 1/20/2025
1.0.291 216 1/19/2025
1.0.290 206 1/19/2025
1.0.289 211 1/14/2025
1.0.288 207 1/12/2025
1.0.287 186 1/12/2025
1.0.286 213 1/12/2025
1.0.285 198 1/12/2025
1.0.284 210 1/10/2025
1.0.283 885 12/30/2024
1.0.282 212 12/27/2024
1.0.281 232 12/19/2024
1.0.280 226 11/20/2024
1.0.279 229 11/19/2024
1.0.278 233 11/19/2024
1.0.277 853 11/18/2024
1.0.276 317 11/7/2024
1.0.275 228 10/31/2024
1.0.274 265 10/19/2024
1.0.273 259 10/19/2024
1.0.272 263 10/19/2024
1.0.271 726 10/13/2024
1.0.270 222 10/12/2024
1.0.269 323 10/9/2024
1.0.268 204 10/9/2024
1.0.267 250 10/5/2024
1.0.266 516 9/18/2024
1.0.265 234 9/17/2024
1.0.264 419 9/4/2024
1.0.263 237 9/3/2024
1.0.262 248 9/3/2024
1.0.261 239 9/1/2024
1.0.260 480 8/23/2024
1.0.259 252 8/22/2024
1.0.258 479 8/8/2024
1.0.257 898 6/12/2024
1.0.256 232 6/12/2024
1.0.255 336 5/28/2024
1.0.254 597 5/4/2024
1.0.253 346 4/23/2024
1.0.252 232 4/21/2024
1.0.251 253 4/14/2024
1.0.250 447 3/28/2024
1.0.249 232 3/17/2024
1.0.248 479 3/9/2024
1.0.247 394 2/23/2024
1.0.246 250 2/23/2024
1.0.245 364 2/18/2024
1.0.244 243 2/18/2024
1.0.243 224 2/16/2024
1.0.242 249 2/16/2024
1.0.241 316 2/13/2024
1.0.240 303 2/8/2024
1.0.239 291 2/5/2024
1.0.238 239 2/4/2024
1.0.237 352 1/23/2024
1.0.236 241 1/23/2024
1.0.235 413 1/12/2024
1.0.234 483 1/2/2024
1.0.233 284 12/29/2023
1.0.232 282 12/17/2023
1.0.231 593 12/15/2023
1.0.230 280 12/15/2023
1.0.229 259 12/15/2023
1.0.228 264 12/13/2023
1.0.227 233 12/13/2023
1.0.226 275 12/10/2023
1.0.225 528 11/18/2023
1.0.224 235 11/18/2023
1.0.223 220 11/18/2023
1.0.222 241 11/17/2023
1.0.221 217 11/12/2023
1.0.220 203 11/12/2023
1.0.219 218 11/10/2023
1.0.218 193 11/10/2023
1.0.217 231 11/9/2023
1.0.216 215 11/9/2023
1.0.215 212 11/9/2023
1.0.214 218 11/3/2023
1.0.213 237 11/1/2023
1.0.212 237 11/1/2023
1.0.211 1,126 9/8/2023
1.0.210 301 9/8/2023
1.0.209 295 9/8/2023
1.0.208 271 9/6/2023
1.0.207 283 9/6/2023
1.0.206 273 9/3/2023
1.0.205 288 8/27/2023
1.0.204 289 8/24/2023
1.0.203 272 8/21/2023
1.0.202 296 8/15/2023
1.0.201 306 8/14/2023
1.0.200 298 8/14/2023
1.0.199 309 8/10/2023
1.0.198 865 7/29/2023
1.0.197 661 7/1/2023
1.0.196 322 6/29/2023
1.0.195 554 5/27/2023
1.0.194 342 5/21/2023
1.0.193 351 5/19/2023
1.0.192 750 5/14/2023
1.0.191 483 5/8/2023
1.0.190 379 5/1/2023
1.0.189 394 4/22/2023
1.0.188 371 4/21/2023
1.0.187 1,062 4/3/2023
1.0.186 447 3/27/2023
1.0.185 444 3/21/2023
1.0.184 457 3/17/2023
1.0.183 416 3/13/2023
1.0.182 1,035 3/6/2023
1.0.181 457 2/26/2023
1.0.180 682 2/21/2023
1.0.179 468 2/20/2023
1.0.178 468 2/15/2023
1.0.177 451 2/14/2023
1.0.176 431 2/14/2023
1.0.175 772 2/9/2023
1.0.174 560 2/7/2023
1.0.173 491 2/4/2023
1.0.172 526 2/3/2023
1.0.171 609 2/2/2023
1.0.170 577 1/30/2023
1.0.169 520 1/18/2023
1.0.168 1,153 12/30/2022
1.0.167 512 12/23/2022
1.0.166 515 12/14/2022
1.0.165 502 12/14/2022
1.0.164 534 12/14/2022
1.0.163 522 12/14/2022
1.0.162 509 12/14/2022
1.0.161 870 12/12/2022
1.0.160 652 12/8/2022
1.0.159 580 12/4/2022
1.0.158 522 12/4/2022
1.0.157 549 11/30/2022
1.0.156 545 11/29/2022
1.0.155 544 11/28/2022
1.0.154 573 11/18/2022
1.0.153 1,070 11/11/2022
1.0.152 572 11/11/2022
1.0.151 564 11/10/2022
1.0.150 598 11/5/2022
1.0.149 604 11/4/2022
1.0.148 786 11/1/2022
1.0.147 919 10/16/2022
1.0.146 683 9/25/2022
1.0.145 667 9/10/2022
1.0.144 676 9/10/2022
1.0.143 1,394 9/8/2022
1.0.142 673 9/8/2022
1.0.141 687 9/8/2022
1.0.140 659 9/4/2022
1.0.139 646 9/4/2022
1.0.138 987 8/24/2022
1.0.137 660 8/8/2022
1.0.136 678 8/8/2022
1.0.135 669 7/26/2022
1.0.134 656 7/26/2022
1.0.133 1,423 7/19/2022
1.0.132 966 7/18/2022
1.0.131 734 7/13/2022
1.0.130 693 7/8/2022
1.0.129 655 6/30/2022
1.0.128 702 6/18/2022
1.0.127 737 6/6/2022
1.0.126 2,333 4/30/2022
1.0.125 744 4/20/2022
1.0.124 730 4/10/2022
1.0.123 710 4/7/2022
1.0.122 728 4/7/2022
1.0.121 710 4/2/2022
1.0.120 1,340 3/29/2022
1.0.119 710 3/27/2022
1.0.118 682 3/27/2022
1.0.117 1,119 2/20/2022
1.0.116 710 2/20/2022
1.0.115 723 2/20/2022
1.0.114 731 2/20/2022
1.0.113 745 2/20/2022
1.0.112 745 2/20/2022
1.0.111 731 2/20/2022
1.0.110 726 2/20/2022
1.0.109 742 2/20/2022
1.0.108 725 2/19/2022
1.0.107 1,655 1/24/2022
1.0.106 1,185 12/29/2021
1.0.105 790 12/20/2021
1.0.104 625 12/13/2021
1.0.103 818 12/7/2021
1.0.102 580 12/7/2021
1.0.101 1,005 12/6/2021
1.0.100 607 12/6/2021
1.0.99 601 12/5/2021
1.0.98 602 12/2/2021
1.0.97 1,296 11/29/2021
1.0.96 798 11/22/2021
1.0.95 642 11/17/2021
1.0.94 617 11/14/2021
1.0.93 858 11/13/2021
1.0.92 661 11/11/2021
1.0.91 574 11/11/2021
1.0.90 567 11/10/2021
1.0.89 590 11/9/2021
1.0.88 888 11/5/2021
1.0.87 650 11/5/2021
1.0.86 624 11/4/2021
1.0.85 609 11/4/2021
1.0.84 676 11/3/2021
1.0.83 694 10/30/2021
1.0.82 947 10/21/2021
1.0.81 750 10/17/2021
1.0.80 783 10/14/2021
1.0.79 661 10/13/2021
1.0.78 620 10/12/2021
1.0.77 699 10/11/2021
1.0.76 612 10/9/2021
1.0.75 737 10/7/2021
1.0.74 674 10/7/2021
1.0.73 597 10/7/2021
1.0.72 668 10/6/2021
1.0.71 666 9/28/2021
1.0.70 1,028 9/23/2021
1.0.69 693 9/11/2021
1.0.68 685 9/10/2021
1.0.67 681 9/9/2021
1.0.66 635 9/8/2021
1.0.65 664 9/8/2021
1.0.64 1,073 9/6/2021
1.0.63 643 8/31/2021
1.0.62 610 8/30/2021
1.0.61 1,807 7/31/2021
1.0.60 675 7/30/2021
1.0.59 711 7/26/2021
1.0.58 1,255 7/5/2021
1.0.57 629 7/1/2021
1.0.56 1,593 6/4/2021
1.0.55 2,020 4/26/2021
1.0.54 1,013 4/19/2021
1.0.53 1,187 4/7/2021
1.0.52 675 4/3/2021
1.0.51 1,311 3/22/2021
1.0.50 1,522 3/4/2021
1.0.49 895 2/26/2021
1.0.48 2,062 2/2/2021
1.0.47 997 1/26/2021
1.0.46 820 1/24/2021
1.0.45 689 1/24/2021
1.0.44 744 1/23/2021
1.0.43 1,031 1/20/2021
1.0.42 755 1/20/2021
1.0.41 804 1/18/2021
1.0.40 659 1/18/2021
1.0.39 868 1/16/2021
1.0.38 10,966 12/17/2020
1.0.37 3,006 12/16/2020
1.0.36 4,819 12/14/2020
1.0.35 5,984 12/9/2020
1.0.34 872 12/7/2020
1.0.33 1,057 12/6/2020
1.0.32 935 12/2/2020
1.0.31 884 12/2/2020
1.0.30 3,320 12/1/2020
1.0.29 12,599 11/12/2020
1.0.29-atestpub 658 11/11/2020
1.0.28 2,794 10/11/2020
1.0.27 6,948 9/9/2020
1.0.26 2,172 9/3/2020
1.0.25 2,418 8/20/2020
1.0.24 5,315 8/9/2020
1.0.23 2,269 7/28/2020
1.0.22 2,250 7/19/2020
1.0.21 3,226 7/6/2020
1.0.20 4,686 6/6/2020
1.0.19 2,141 6/4/2020
1.0.18 3,264 5/29/2020
1.0.17 3,306 5/21/2020
1.0.16 1,013 5/17/2020
1.0.15 3,565 5/12/2020
1.0.14 5,752 5/4/2020
1.0.13 1,664 4/24/2020
1.0.12 1,231 4/22/2020
1.0.11 1,219 4/22/2020
1.0.10 1,216 4/21/2020
1.0.9 2,770 4/18/2020
1.0.8 2,421 4/16/2020
1.0.7 1,232 4/16/2020
1.0.6 2,302 4/15/2020
1.0.5 2,540 4/11/2020
1.0.4 2,521 4/3/2020
1.0.3 1,277 4/1/2020
1.0.2 2,430 3/27/2020
1.0.1 2,626 3/22/2020
1.0.0 1,891 3/22/2020