Ecng.Interop.Windows 1.0.409

There is a newer version of this package available.
See the version list below for details.
dotnet add package Ecng.Interop.Windows --version 1.0.409
                    
NuGet\Install-Package Ecng.Interop.Windows -Version 1.0.409
                    
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.409" />
                    
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.409" />
                    
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.409
                    
#r "nuget: Ecng.Interop.Windows, 1.0.409"
                    
#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.409
                    
#: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.409
                    
Install as a Cake Addin
#tool nuget:?package=Ecng.Interop.Windows&version=1.0.409
                    
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.411 0 1/18/2026
1.0.410 36 1/16/2026
1.0.409 40 1/14/2026
1.0.408 44 1/13/2026
1.0.407 40 1/13/2026
1.0.406 96 1/9/2026
1.0.405 93 1/9/2026
1.0.404 92 1/9/2026
1.0.403 93 1/8/2026
1.0.402 93 1/4/2026
1.0.401 94 1/1/2026
1.0.400 103 12/31/2025
1.0.399 106 12/30/2025
1.0.398 95 12/30/2025
1.0.397 96 12/29/2025
1.0.396 102 12/26/2025
1.0.395 96 12/26/2025
1.0.394 101 12/26/2025
1.0.393 117 12/26/2025
1.0.392 184 12/25/2025
1.0.391 188 12/25/2025
1.0.390 184 12/22/2025
1.0.389 163 12/21/2025
1.0.388 213 12/19/2025
1.0.387 247 12/19/2025
1.0.386 278 12/17/2025
1.0.385 261 12/15/2025
1.0.384 256 12/15/2025
1.0.383 227 12/14/2025
1.0.382 134 12/12/2025
1.0.381 136 12/12/2025
1.0.380 130 12/12/2025
1.0.379 130 12/12/2025
1.0.378 145 12/12/2025
1.0.377 684 12/2/2025
1.0.376 699 12/2/2025
1.0.375 685 12/2/2025
1.0.374 277 11/30/2025
1.0.373 141 11/29/2025
1.0.372 145 11/28/2025
1.0.371 152 11/28/2025
1.0.370 206 11/27/2025
1.0.369 214 11/24/2025
1.0.368 211 11/24/2025
1.0.367 209 11/23/2025
1.0.366 186 11/23/2025
1.0.365 228 11/22/2025
1.0.364 431 11/20/2025
1.0.363 429 11/18/2025
1.0.362 421 11/18/2025
1.0.361 312 11/13/2025
1.0.360 305 11/13/2025
1.0.359 262 11/10/2025
1.0.358 169 11/1/2025
1.0.357 213 10/28/2025
1.0.356 211 10/27/2025
1.0.355 210 10/27/2025
1.0.354 137 10/25/2025
1.0.353 169 10/11/2025
1.0.352 179 10/3/2025
1.0.351 219 9/28/2025
1.0.350 218 9/25/2025
1.0.349 2,214 9/2/2025
1.0.348 507 8/30/2025
1.0.347 254 8/30/2025
1.0.346 221 8/19/2025
1.0.345 199 8/15/2025
1.0.344 222 8/14/2025
1.0.343 845 7/16/2025
1.0.342 444 7/14/2025
1.0.341 231 7/13/2025
1.0.340 227 7/13/2025
1.0.339 195 7/12/2025
1.0.338 344 7/8/2025
1.0.337 323 7/4/2025
1.0.336 242 7/2/2025
1.0.335 701 6/16/2025
1.0.334 381 6/9/2025
1.0.333 299 6/8/2025
1.0.332 457 5/21/2025
1.0.331 244 5/17/2025
1.0.330 534 5/12/2025
1.0.329 335 5/12/2025
1.0.328 325 5/12/2025
1.0.327 258 5/11/2025
1.0.326 273 5/11/2025
1.0.325 272 5/11/2025
1.0.324 256 5/11/2025
1.0.323 262 5/11/2025
1.0.322 256 5/11/2025
1.0.321 200 5/10/2025
1.0.320 187 5/10/2025
1.0.319 245 5/6/2025
1.0.318 259 5/2/2025
1.0.317 326 4/17/2025
1.0.316 315 4/15/2025
1.0.315 266 4/12/2025
1.0.314 236 4/12/2025
1.0.313 855 3/22/2025
1.0.312 291 3/20/2025
1.0.311 293 3/20/2025
1.0.310 274 3/19/2025
1.0.309 723 2/26/2025
1.0.308 240 2/26/2025
1.0.307 628 2/6/2025
1.0.306 232 2/6/2025
1.0.305 240 2/6/2025
1.0.304 261 2/6/2025
1.0.303 243 2/5/2025
1.0.302 252 2/5/2025
1.0.301 243 2/5/2025
1.0.300 262 2/3/2025
1.0.299 246 2/2/2025
1.0.298 232 2/1/2025
1.0.297 249 1/31/2025
1.0.296 235 1/30/2025
1.0.295 243 1/26/2025
1.0.294 232 1/21/2025
1.0.293 255 1/20/2025
1.0.292 218 1/20/2025
1.0.291 238 1/19/2025
1.0.290 224 1/19/2025
1.0.289 232 1/14/2025
1.0.288 235 1/12/2025
1.0.287 209 1/12/2025
1.0.286 232 1/12/2025
1.0.285 218 1/12/2025
1.0.284 228 1/10/2025
1.0.283 901 12/30/2024
1.0.282 234 12/27/2024
1.0.281 251 12/19/2024
1.0.280 246 11/20/2024
1.0.279 253 11/19/2024
1.0.278 255 11/19/2024
1.0.277 873 11/18/2024
1.0.276 333 11/7/2024
1.0.275 244 10/31/2024
1.0.274 284 10/19/2024
1.0.273 275 10/19/2024
1.0.272 284 10/19/2024
1.0.271 745 10/13/2024
1.0.270 248 10/12/2024
1.0.269 338 10/9/2024
1.0.268 222 10/9/2024
1.0.267 275 10/5/2024
1.0.266 532 9/18/2024
1.0.265 259 9/17/2024
1.0.264 446 9/4/2024
1.0.263 260 9/3/2024
1.0.262 267 9/3/2024
1.0.261 258 9/1/2024
1.0.260 500 8/23/2024
1.0.259 275 8/22/2024
1.0.258 499 8/8/2024
1.0.257 919 6/12/2024
1.0.256 252 6/12/2024
1.0.255 355 5/28/2024
1.0.254 619 5/4/2024
1.0.253 364 4/23/2024
1.0.252 252 4/21/2024
1.0.251 272 4/14/2024
1.0.250 463 3/28/2024
1.0.249 253 3/17/2024
1.0.248 500 3/9/2024
1.0.247 418 2/23/2024
1.0.246 275 2/23/2024
1.0.245 386 2/18/2024
1.0.244 268 2/18/2024
1.0.243 244 2/16/2024
1.0.242 273 2/16/2024
1.0.241 337 2/13/2024
1.0.240 323 2/8/2024
1.0.239 313 2/5/2024
1.0.238 260 2/4/2024
1.0.237 372 1/23/2024
1.0.236 261 1/23/2024
1.0.235 437 1/12/2024
1.0.234 502 1/2/2024
1.0.233 303 12/29/2023
1.0.232 306 12/17/2023
1.0.231 618 12/15/2023
1.0.230 296 12/15/2023
1.0.229 278 12/15/2023
1.0.228 283 12/13/2023
1.0.227 254 12/13/2023
1.0.226 295 12/10/2023
1.0.225 540 11/18/2023
1.0.224 243 11/18/2023
1.0.223 229 11/18/2023
1.0.222 254 11/17/2023
1.0.221 227 11/12/2023
1.0.220 212 11/12/2023
1.0.219 225 11/10/2023
1.0.218 203 11/10/2023
1.0.217 247 11/9/2023
1.0.216 224 11/9/2023
1.0.215 226 11/9/2023
1.0.214 228 11/3/2023
1.0.213 243 11/1/2023
1.0.212 250 11/1/2023
1.0.211 1,136 9/8/2023
1.0.210 312 9/8/2023
1.0.209 309 9/8/2023
1.0.208 286 9/6/2023
1.0.207 297 9/6/2023
1.0.206 286 9/3/2023
1.0.205 299 8/27/2023
1.0.204 303 8/24/2023
1.0.203 280 8/21/2023
1.0.202 304 8/15/2023
1.0.201 313 8/14/2023
1.0.200 308 8/14/2023
1.0.199 316 8/10/2023
1.0.198 876 7/29/2023
1.0.197 674 7/1/2023
1.0.196 338 6/29/2023
1.0.195 566 5/27/2023
1.0.194 352 5/21/2023
1.0.193 365 5/19/2023
1.0.192 759 5/14/2023
1.0.191 493 5/8/2023
1.0.190 389 5/1/2023
1.0.189 406 4/22/2023
1.0.188 381 4/21/2023
1.0.187 1,071 4/3/2023
1.0.186 456 3/27/2023
1.0.185 457 3/21/2023
1.0.184 466 3/17/2023
1.0.183 423 3/13/2023
1.0.182 1,047 3/6/2023
1.0.181 465 2/26/2023
1.0.180 690 2/21/2023
1.0.179 477 2/20/2023
1.0.178 479 2/15/2023
1.0.177 466 2/14/2023
1.0.176 446 2/14/2023
1.0.175 785 2/9/2023
1.0.174 567 2/7/2023
1.0.173 500 2/4/2023
1.0.172 534 2/3/2023
1.0.171 622 2/2/2023
1.0.170 586 1/30/2023
1.0.169 532 1/18/2023
1.0.168 1,164 12/30/2022
1.0.167 521 12/23/2022
1.0.166 526 12/14/2022
1.0.165 511 12/14/2022
1.0.164 542 12/14/2022
1.0.163 535 12/14/2022
1.0.162 523 12/14/2022
1.0.161 879 12/12/2022
1.0.160 664 12/8/2022
1.0.159 591 12/4/2022
1.0.158 534 12/4/2022
1.0.157 557 11/30/2022
1.0.156 553 11/29/2022
1.0.155 555 11/28/2022
1.0.154 584 11/18/2022
1.0.153 1,081 11/11/2022
1.0.152 584 11/11/2022
1.0.151 576 11/10/2022
1.0.150 610 11/5/2022
1.0.149 616 11/4/2022
1.0.148 798 11/1/2022
1.0.147 938 10/16/2022
1.0.146 695 9/25/2022
1.0.145 679 9/10/2022
1.0.144 686 9/10/2022
1.0.143 1,404 9/8/2022
1.0.142 680 9/8/2022
1.0.141 701 9/8/2022
1.0.140 668 9/4/2022
1.0.139 656 9/4/2022
1.0.138 996 8/24/2022
1.0.137 673 8/8/2022
1.0.136 690 8/8/2022
1.0.135 685 7/26/2022
1.0.134 670 7/26/2022
1.0.133 1,438 7/19/2022
1.0.132 980 7/18/2022
1.0.131 743 7/13/2022
1.0.130 705 7/8/2022
1.0.129 665 6/30/2022
1.0.128 713 6/18/2022
1.0.127 751 6/6/2022
1.0.126 2,344 4/30/2022
1.0.125 755 4/20/2022
1.0.124 740 4/10/2022
1.0.123 724 4/7/2022
1.0.122 740 4/7/2022
1.0.121 724 4/2/2022
1.0.120 1,349 3/29/2022
1.0.119 726 3/27/2022
1.0.118 696 3/27/2022
1.0.117 1,131 2/20/2022
1.0.116 724 2/20/2022
1.0.115 735 2/20/2022
1.0.114 745 2/20/2022
1.0.113 757 2/20/2022
1.0.112 752 2/20/2022
1.0.111 746 2/20/2022
1.0.110 736 2/20/2022
1.0.109 753 2/20/2022
1.0.108 735 2/19/2022
1.0.107 1,668 1/24/2022
1.0.106 1,200 12/29/2021
1.0.105 802 12/20/2021
1.0.104 634 12/13/2021
1.0.103 826 12/7/2021
1.0.102 592 12/7/2021
1.0.101 1,010 12/6/2021
1.0.100 618 12/6/2021
1.0.99 612 12/5/2021
1.0.98 614 12/2/2021
1.0.97 1,311 11/29/2021
1.0.96 809 11/22/2021
1.0.95 658 11/17/2021
1.0.94 628 11/14/2021
1.0.93 868 11/13/2021
1.0.92 673 11/11/2021
1.0.91 582 11/11/2021
1.0.90 576 11/10/2021
1.0.89 602 11/9/2021
1.0.88 898 11/5/2021
1.0.87 664 11/5/2021
1.0.86 633 11/4/2021
1.0.85 620 11/4/2021
1.0.84 689 11/3/2021
1.0.83 711 10/30/2021
1.0.82 965 10/21/2021
1.0.81 763 10/17/2021
1.0.80 795 10/14/2021
1.0.79 666 10/13/2021
1.0.78 634 10/12/2021
1.0.77 708 10/11/2021
1.0.76 625 10/9/2021
1.0.75 747 10/7/2021
1.0.74 689 10/7/2021
1.0.73 610 10/7/2021
1.0.72 680 10/6/2021
1.0.71 673 9/28/2021
1.0.70 1,040 9/23/2021
1.0.69 705 9/11/2021
1.0.68 696 9/10/2021
1.0.67 690 9/9/2021
1.0.66 647 9/8/2021
1.0.65 674 9/8/2021
1.0.64 1,080 9/6/2021
1.0.63 658 8/31/2021
1.0.62 621 8/30/2021
1.0.61 1,822 7/31/2021
1.0.60 689 7/30/2021
1.0.59 726 7/26/2021
1.0.58 1,266 7/5/2021
1.0.57 639 7/1/2021
1.0.56 1,602 6/4/2021
1.0.55 2,032 4/26/2021
1.0.54 1,028 4/19/2021
1.0.53 1,198 4/7/2021
1.0.52 688 4/3/2021
1.0.51 1,324 3/22/2021
1.0.50 1,533 3/4/2021
1.0.49 903 2/26/2021
1.0.48 2,073 2/2/2021
1.0.47 1,010 1/26/2021
1.0.46 833 1/24/2021
1.0.45 710 1/24/2021
1.0.44 754 1/23/2021
1.0.43 1,050 1/20/2021
1.0.42 767 1/20/2021
1.0.41 820 1/18/2021
1.0.40 671 1/18/2021
1.0.39 882 1/16/2021
1.0.38 10,973 12/17/2020
1.0.37 3,018 12/16/2020
1.0.36 4,829 12/14/2020
1.0.35 5,996 12/9/2020
1.0.34 888 12/7/2020
1.0.33 1,066 12/6/2020
1.0.32 948 12/2/2020
1.0.31 899 12/2/2020
1.0.30 3,336 12/1/2020
1.0.29 12,616 11/12/2020
1.0.29-atestpub 671 11/11/2020
1.0.28 2,807 10/11/2020
1.0.27 6,959 9/9/2020
1.0.26 2,189 9/3/2020
1.0.25 2,429 8/20/2020
1.0.24 5,324 8/9/2020
1.0.23 2,286 7/28/2020
1.0.22 2,263 7/19/2020
1.0.21 3,240 7/6/2020
1.0.20 4,697 6/6/2020
1.0.19 2,159 6/4/2020
1.0.18 3,276 5/29/2020
1.0.17 3,318 5/21/2020
1.0.16 1,029 5/17/2020
1.0.15 3,579 5/12/2020
1.0.14 5,769 5/4/2020
1.0.13 1,677 4/24/2020
1.0.12 1,244 4/22/2020
1.0.11 1,233 4/22/2020
1.0.10 1,229 4/21/2020
1.0.9 2,785 4/18/2020
1.0.8 2,435 4/16/2020
1.0.7 1,243 4/16/2020
1.0.6 2,317 4/15/2020
1.0.5 2,557 4/11/2020
1.0.4 2,532 4/3/2020
1.0.3 1,291 4/1/2020
1.0.2 2,448 3/27/2020
1.0.1 2,640 3/22/2020
1.0.0 1,903 3/22/2020