Ecng.Interop.Windows 1.0.406

dotnet add package Ecng.Interop.Windows --version 1.0.406
                    
NuGet\Install-Package Ecng.Interop.Windows -Version 1.0.406
                    
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.406" />
                    
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.406" />
                    
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.406
                    
#r "nuget: Ecng.Interop.Windows, 1.0.406"
                    
#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.406
                    
#: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.406
                    
Install as a Cake Addin
#tool nuget:?package=Ecng.Interop.Windows&version=1.0.406
                    
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.406 0 1/9/2026
1.0.405 0 1/9/2026
1.0.404 31 1/9/2026
1.0.403 38 1/8/2026
1.0.402 86 1/4/2026
1.0.401 86 1/1/2026
1.0.400 95 12/31/2025
1.0.399 98 12/30/2025
1.0.398 88 12/30/2025
1.0.397 90 12/29/2025
1.0.396 96 12/26/2025
1.0.395 90 12/26/2025
1.0.394 90 12/26/2025
1.0.393 109 12/26/2025
1.0.392 177 12/25/2025
1.0.391 179 12/25/2025
1.0.390 176 12/22/2025
1.0.389 156 12/21/2025
1.0.388 205 12/19/2025
1.0.387 237 12/19/2025
1.0.386 273 12/17/2025
1.0.385 254 12/15/2025
1.0.384 249 12/15/2025
1.0.383 221 12/14/2025
1.0.382 127 12/12/2025
1.0.381 126 12/12/2025
1.0.380 119 12/12/2025
1.0.379 122 12/12/2025
1.0.378 137 12/12/2025
1.0.377 678 12/2/2025
1.0.376 690 12/2/2025
1.0.375 679 12/2/2025
1.0.374 269 11/30/2025
1.0.373 132 11/29/2025
1.0.372 138 11/28/2025
1.0.371 144 11/28/2025
1.0.370 198 11/27/2025
1.0.369 207 11/24/2025
1.0.368 205 11/24/2025
1.0.367 200 11/23/2025
1.0.366 178 11/23/2025
1.0.365 221 11/22/2025
1.0.364 422 11/20/2025
1.0.363 422 11/18/2025
1.0.362 415 11/18/2025
1.0.361 302 11/13/2025
1.0.360 299 11/13/2025
1.0.359 255 11/10/2025
1.0.358 161 11/1/2025
1.0.357 205 10/28/2025
1.0.356 203 10/27/2025
1.0.355 200 10/27/2025
1.0.354 129 10/25/2025
1.0.353 159 10/11/2025
1.0.352 173 10/3/2025
1.0.351 212 9/28/2025
1.0.350 212 9/25/2025
1.0.349 2,105 9/2/2025
1.0.348 500 8/30/2025
1.0.347 248 8/30/2025
1.0.346 215 8/19/2025
1.0.345 193 8/15/2025
1.0.344 218 8/14/2025
1.0.343 839 7/16/2025
1.0.342 436 7/14/2025
1.0.341 222 7/13/2025
1.0.340 222 7/13/2025
1.0.339 186 7/12/2025
1.0.338 339 7/8/2025
1.0.337 316 7/4/2025
1.0.336 234 7/2/2025
1.0.335 693 6/16/2025
1.0.334 376 6/9/2025
1.0.333 292 6/8/2025
1.0.332 451 5/21/2025
1.0.331 236 5/17/2025
1.0.330 528 5/12/2025
1.0.329 326 5/12/2025
1.0.328 317 5/12/2025
1.0.327 251 5/11/2025
1.0.326 265 5/11/2025
1.0.325 266 5/11/2025
1.0.324 246 5/11/2025
1.0.323 254 5/11/2025
1.0.322 249 5/11/2025
1.0.321 191 5/10/2025
1.0.320 182 5/10/2025
1.0.319 238 5/6/2025
1.0.318 253 5/2/2025
1.0.317 318 4/17/2025
1.0.316 307 4/15/2025
1.0.315 260 4/12/2025
1.0.314 227 4/12/2025
1.0.313 844 3/22/2025
1.0.312 286 3/20/2025
1.0.311 285 3/20/2025
1.0.310 266 3/19/2025
1.0.309 715 2/26/2025
1.0.308 234 2/26/2025
1.0.307 623 2/6/2025
1.0.306 225 2/6/2025
1.0.305 234 2/6/2025
1.0.304 252 2/6/2025
1.0.303 236 2/5/2025
1.0.302 245 2/5/2025
1.0.301 237 2/5/2025
1.0.300 257 2/3/2025
1.0.299 240 2/2/2025
1.0.298 227 2/1/2025
1.0.297 239 1/31/2025
1.0.296 227 1/30/2025
1.0.295 234 1/26/2025
1.0.294 225 1/21/2025
1.0.293 247 1/20/2025
1.0.292 210 1/20/2025
1.0.291 229 1/19/2025
1.0.290 218 1/19/2025
1.0.289 224 1/14/2025
1.0.288 227 1/12/2025
1.0.287 200 1/12/2025
1.0.286 226 1/12/2025
1.0.285 210 1/12/2025
1.0.284 222 1/10/2025
1.0.283 896 12/30/2024
1.0.282 227 12/27/2024
1.0.281 246 12/19/2024
1.0.280 239 11/20/2024
1.0.279 242 11/19/2024
1.0.278 247 11/19/2024
1.0.277 868 11/18/2024
1.0.276 328 11/7/2024
1.0.275 238 10/31/2024
1.0.274 277 10/19/2024
1.0.273 270 10/19/2024
1.0.272 280 10/19/2024
1.0.271 739 10/13/2024
1.0.270 238 10/12/2024
1.0.269 333 10/9/2024
1.0.268 217 10/9/2024
1.0.267 265 10/5/2024
1.0.266 528 9/18/2024
1.0.265 252 9/17/2024
1.0.264 436 9/4/2024
1.0.263 250 9/3/2024
1.0.262 262 9/3/2024
1.0.261 254 9/1/2024
1.0.260 494 8/23/2024
1.0.259 268 8/22/2024
1.0.258 492 8/8/2024
1.0.257 910 6/12/2024
1.0.256 242 6/12/2024
1.0.255 346 5/28/2024
1.0.254 611 5/4/2024
1.0.253 359 4/23/2024
1.0.252 245 4/21/2024
1.0.251 266 4/14/2024
1.0.250 457 3/28/2024
1.0.249 246 3/17/2024
1.0.248 494 3/9/2024
1.0.247 410 2/23/2024
1.0.246 267 2/23/2024
1.0.245 381 2/18/2024
1.0.244 262 2/18/2024
1.0.243 238 2/16/2024
1.0.242 267 2/16/2024
1.0.241 328 2/13/2024
1.0.240 316 2/8/2024
1.0.239 306 2/5/2024
1.0.238 255 2/4/2024
1.0.237 366 1/23/2024
1.0.236 256 1/23/2024
1.0.235 427 1/12/2024
1.0.234 497 1/2/2024
1.0.233 294 12/29/2023
1.0.232 296 12/17/2023
1.0.231 609 12/15/2023
1.0.230 290 12/15/2023
1.0.229 270 12/15/2023
1.0.228 276 12/13/2023
1.0.227 247 12/13/2023
1.0.226 288 12/10/2023
1.0.225 539 11/18/2023
1.0.224 240 11/18/2023
1.0.223 228 11/18/2023
1.0.222 249 11/17/2023
1.0.221 224 11/12/2023
1.0.220 210 11/12/2023
1.0.219 224 11/10/2023
1.0.218 200 11/10/2023
1.0.217 239 11/9/2023
1.0.216 221 11/9/2023
1.0.215 221 11/9/2023
1.0.214 224 11/3/2023
1.0.213 241 11/1/2023
1.0.212 245 11/1/2023
1.0.211 1,134 9/8/2023
1.0.210 309 9/8/2023
1.0.209 303 9/8/2023
1.0.208 282 9/6/2023
1.0.207 291 9/6/2023
1.0.206 282 9/3/2023
1.0.205 298 8/27/2023
1.0.204 298 8/24/2023
1.0.203 280 8/21/2023
1.0.202 302 8/15/2023
1.0.201 311 8/14/2023
1.0.200 305 8/14/2023
1.0.199 315 8/10/2023
1.0.198 873 7/29/2023
1.0.197 669 7/1/2023
1.0.196 333 6/29/2023
1.0.195 559 5/27/2023
1.0.194 350 5/21/2023
1.0.193 362 5/19/2023
1.0.192 756 5/14/2023
1.0.191 490 5/8/2023
1.0.190 389 5/1/2023
1.0.189 402 4/22/2023
1.0.188 378 4/21/2023
1.0.187 1,069 4/3/2023
1.0.186 453 3/27/2023
1.0.185 453 3/21/2023
1.0.184 464 3/17/2023
1.0.183 420 3/13/2023
1.0.182 1,041 3/6/2023
1.0.181 463 2/26/2023
1.0.180 689 2/21/2023
1.0.179 475 2/20/2023
1.0.178 477 2/15/2023
1.0.177 460 2/14/2023
1.0.176 441 2/14/2023
1.0.175 780 2/9/2023
1.0.174 564 2/7/2023
1.0.173 496 2/4/2023
1.0.172 531 2/3/2023
1.0.171 618 2/2/2023
1.0.170 582 1/30/2023
1.0.169 526 1/18/2023
1.0.168 1,161 12/30/2022
1.0.167 519 12/23/2022
1.0.166 522 12/14/2022
1.0.165 509 12/14/2022
1.0.164 542 12/14/2022
1.0.163 532 12/14/2022
1.0.162 517 12/14/2022
1.0.161 877 12/12/2022
1.0.160 657 12/8/2022
1.0.159 589 12/4/2022
1.0.158 532 12/4/2022
1.0.157 555 11/30/2022
1.0.156 551 11/29/2022
1.0.155 550 11/28/2022
1.0.154 580 11/18/2022
1.0.153 1,077 11/11/2022
1.0.152 582 11/11/2022
1.0.151 573 11/10/2022
1.0.150 607 11/5/2022
1.0.149 613 11/4/2022
1.0.148 794 11/1/2022
1.0.147 933 10/16/2022
1.0.146 690 9/25/2022
1.0.145 673 9/10/2022
1.0.144 683 9/10/2022
1.0.143 1,404 9/8/2022
1.0.142 679 9/8/2022
1.0.141 697 9/8/2022
1.0.140 666 9/4/2022
1.0.139 652 9/4/2022
1.0.138 994 8/24/2022
1.0.137 669 8/8/2022
1.0.136 688 8/8/2022
1.0.135 681 7/26/2022
1.0.134 668 7/26/2022
1.0.133 1,433 7/19/2022
1.0.132 977 7/18/2022
1.0.131 741 7/13/2022
1.0.130 702 7/8/2022
1.0.129 663 6/30/2022
1.0.128 711 6/18/2022
1.0.127 748 6/6/2022
1.0.126 2,340 4/30/2022
1.0.125 755 4/20/2022
1.0.124 739 4/10/2022
1.0.123 722 4/7/2022
1.0.122 738 4/7/2022
1.0.121 720 4/2/2022
1.0.120 1,346 3/29/2022
1.0.119 722 3/27/2022
1.0.118 695 3/27/2022
1.0.117 1,127 2/20/2022
1.0.116 721 2/20/2022
1.0.115 733 2/20/2022
1.0.114 740 2/20/2022
1.0.113 756 2/20/2022
1.0.112 750 2/20/2022
1.0.111 740 2/20/2022
1.0.110 736 2/20/2022
1.0.109 750 2/20/2022
1.0.108 733 2/19/2022
1.0.107 1,664 1/24/2022
1.0.106 1,196 12/29/2021
1.0.105 800 12/20/2021
1.0.104 632 12/13/2021
1.0.103 823 12/7/2021
1.0.102 591 12/7/2021
1.0.101 1,010 12/6/2021
1.0.100 613 12/6/2021
1.0.99 611 12/5/2021
1.0.98 612 12/2/2021
1.0.97 1,307 11/29/2021
1.0.96 807 11/22/2021
1.0.95 655 11/17/2021
1.0.94 626 11/14/2021
1.0.93 864 11/13/2021
1.0.92 671 11/11/2021
1.0.91 578 11/11/2021
1.0.90 575 11/10/2021
1.0.89 599 11/9/2021
1.0.88 898 11/5/2021
1.0.87 659 11/5/2021
1.0.86 631 11/4/2021
1.0.85 617 11/4/2021
1.0.84 683 11/3/2021
1.0.83 705 10/30/2021
1.0.82 959 10/21/2021
1.0.81 760 10/17/2021
1.0.80 792 10/14/2021
1.0.79 666 10/13/2021
1.0.78 630 10/12/2021
1.0.77 704 10/11/2021
1.0.76 624 10/9/2021
1.0.75 744 10/7/2021
1.0.74 685 10/7/2021
1.0.73 606 10/7/2021
1.0.72 678 10/6/2021
1.0.71 672 9/28/2021
1.0.70 1,037 9/23/2021
1.0.69 704 9/11/2021
1.0.68 694 9/10/2021
1.0.67 687 9/9/2021
1.0.66 644 9/8/2021
1.0.65 672 9/8/2021
1.0.64 1,080 9/6/2021
1.0.63 653 8/31/2021
1.0.62 618 8/30/2021
1.0.61 1,819 7/31/2021
1.0.60 688 7/30/2021
1.0.59 722 7/26/2021
1.0.58 1,263 7/5/2021
1.0.57 638 7/1/2021
1.0.56 1,601 6/4/2021
1.0.55 2,031 4/26/2021
1.0.54 1,024 4/19/2021
1.0.53 1,194 4/7/2021
1.0.52 683 4/3/2021
1.0.51 1,322 3/22/2021
1.0.50 1,530 3/4/2021
1.0.49 901 2/26/2021
1.0.48 2,070 2/2/2021
1.0.47 1,006 1/26/2021
1.0.46 831 1/24/2021
1.0.45 706 1/24/2021
1.0.44 752 1/23/2021
1.0.43 1,043 1/20/2021
1.0.42 763 1/20/2021
1.0.41 815 1/18/2021
1.0.40 669 1/18/2021
1.0.39 877 1/16/2021
1.0.38 10,971 12/17/2020
1.0.37 3,014 12/16/2020
1.0.36 4,827 12/14/2020
1.0.35 5,992 12/9/2020
1.0.34 885 12/7/2020
1.0.33 1,063 12/6/2020
1.0.32 944 12/2/2020
1.0.31 896 12/2/2020
1.0.30 3,332 12/1/2020
1.0.29 12,612 11/12/2020
1.0.29-atestpub 669 11/11/2020
1.0.28 2,803 10/11/2020
1.0.27 6,956 9/9/2020
1.0.26 2,184 9/3/2020
1.0.25 2,427 8/20/2020
1.0.24 5,322 8/9/2020
1.0.23 2,283 7/28/2020
1.0.22 2,260 7/19/2020
1.0.21 3,237 7/6/2020
1.0.20 4,694 6/6/2020
1.0.19 2,154 6/4/2020
1.0.18 3,272 5/29/2020
1.0.17 3,316 5/21/2020
1.0.16 1,025 5/17/2020
1.0.15 3,575 5/12/2020
1.0.14 5,763 5/4/2020
1.0.13 1,673 4/24/2020
1.0.12 1,238 4/22/2020
1.0.11 1,230 4/22/2020
1.0.10 1,223 4/21/2020
1.0.9 2,778 4/18/2020
1.0.8 2,432 4/16/2020
1.0.7 1,240 4/16/2020
1.0.6 2,315 4/15/2020
1.0.5 2,551 4/11/2020
1.0.4 2,529 4/3/2020
1.0.3 1,288 4/1/2020
1.0.2 2,444 3/27/2020
1.0.1 2,637 3/22/2020
1.0.0 1,900 3/22/2020