Ecng.Interop.Windows 1.0.402

dotnet add package Ecng.Interop.Windows --version 1.0.402
                    
NuGet\Install-Package Ecng.Interop.Windows -Version 1.0.402
                    
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.402" />
                    
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.402" />
                    
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.402
                    
#r "nuget: Ecng.Interop.Windows, 1.0.402"
                    
#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.402
                    
#: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.402
                    
Install as a Cake Addin
#tool nuget:?package=Ecng.Interop.Windows&version=1.0.402
                    
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.402 0 1/4/2026
1.0.401 37 1/1/2026
1.0.400 43 12/31/2025
1.0.399 46 12/30/2025
1.0.398 40 12/30/2025
1.0.397 48 12/29/2025
1.0.396 92 12/26/2025
1.0.395 83 12/26/2025
1.0.394 87 12/26/2025
1.0.393 104 12/26/2025
1.0.392 171 12/25/2025
1.0.391 174 12/25/2025
1.0.390 171 12/22/2025
1.0.389 150 12/21/2025
1.0.388 198 12/19/2025
1.0.387 233 12/19/2025
1.0.386 268 12/17/2025
1.0.385 249 12/15/2025
1.0.384 244 12/15/2025
1.0.383 213 12/14/2025
1.0.382 119 12/12/2025
1.0.381 119 12/12/2025
1.0.380 112 12/12/2025
1.0.379 117 12/12/2025
1.0.378 129 12/12/2025
1.0.377 673 12/2/2025
1.0.376 684 12/2/2025
1.0.375 674 12/2/2025
1.0.374 263 11/30/2025
1.0.373 129 11/29/2025
1.0.372 131 11/28/2025
1.0.371 137 11/28/2025
1.0.370 192 11/27/2025
1.0.369 200 11/24/2025
1.0.368 197 11/24/2025
1.0.367 195 11/23/2025
1.0.366 172 11/23/2025
1.0.365 217 11/22/2025
1.0.364 416 11/20/2025
1.0.363 415 11/18/2025
1.0.362 410 11/18/2025
1.0.361 298 11/13/2025
1.0.360 295 11/13/2025
1.0.359 249 11/10/2025
1.0.358 155 11/1/2025
1.0.357 200 10/28/2025
1.0.356 199 10/27/2025
1.0.355 193 10/27/2025
1.0.354 124 10/25/2025
1.0.353 153 10/11/2025
1.0.352 168 10/3/2025
1.0.351 205 9/28/2025
1.0.350 207 9/25/2025
1.0.349 2,051 9/2/2025
1.0.348 495 8/30/2025
1.0.347 243 8/30/2025
1.0.346 211 8/19/2025
1.0.345 187 8/15/2025
1.0.344 213 8/14/2025
1.0.343 835 7/16/2025
1.0.342 430 7/14/2025
1.0.341 214 7/13/2025
1.0.340 216 7/13/2025
1.0.339 180 7/12/2025
1.0.338 335 7/8/2025
1.0.337 309 7/4/2025
1.0.336 227 7/2/2025
1.0.335 685 6/16/2025
1.0.334 371 6/9/2025
1.0.333 285 6/8/2025
1.0.332 444 5/21/2025
1.0.331 230 5/17/2025
1.0.330 523 5/12/2025
1.0.329 322 5/12/2025
1.0.328 312 5/12/2025
1.0.327 246 5/11/2025
1.0.326 257 5/11/2025
1.0.325 260 5/11/2025
1.0.324 241 5/11/2025
1.0.323 248 5/11/2025
1.0.322 243 5/11/2025
1.0.321 184 5/10/2025
1.0.320 177 5/10/2025
1.0.319 232 5/6/2025
1.0.318 246 5/2/2025
1.0.317 312 4/17/2025
1.0.316 301 4/15/2025
1.0.315 253 4/12/2025
1.0.314 225 4/12/2025
1.0.313 836 3/22/2025
1.0.312 279 3/20/2025
1.0.311 279 3/20/2025
1.0.310 262 3/19/2025
1.0.309 709 2/26/2025
1.0.308 231 2/26/2025
1.0.307 619 2/6/2025
1.0.306 221 2/6/2025
1.0.305 228 2/6/2025
1.0.304 243 2/6/2025
1.0.303 231 2/5/2025
1.0.302 238 2/5/2025
1.0.301 231 2/5/2025
1.0.300 253 2/3/2025
1.0.299 232 2/2/2025
1.0.298 222 2/1/2025
1.0.297 233 1/31/2025
1.0.296 223 1/30/2025
1.0.295 230 1/26/2025
1.0.294 220 1/21/2025
1.0.293 242 1/20/2025
1.0.292 203 1/20/2025
1.0.291 224 1/19/2025
1.0.290 211 1/19/2025
1.0.289 219 1/14/2025
1.0.288 218 1/12/2025
1.0.287 196 1/12/2025
1.0.286 222 1/12/2025
1.0.285 205 1/12/2025
1.0.284 216 1/10/2025
1.0.283 892 12/30/2024
1.0.282 220 12/27/2024
1.0.281 239 12/19/2024
1.0.280 232 11/20/2024
1.0.279 237 11/19/2024
1.0.278 242 11/19/2024
1.0.277 862 11/18/2024
1.0.276 324 11/7/2024
1.0.275 235 10/31/2024
1.0.274 270 10/19/2024
1.0.273 266 10/19/2024
1.0.272 271 10/19/2024
1.0.271 731 10/13/2024
1.0.270 230 10/12/2024
1.0.269 329 10/9/2024
1.0.268 210 10/9/2024
1.0.267 256 10/5/2024
1.0.266 522 9/18/2024
1.0.265 244 9/17/2024
1.0.264 428 9/4/2024
1.0.263 245 9/3/2024
1.0.262 254 9/3/2024
1.0.261 245 9/1/2024
1.0.260 487 8/23/2024
1.0.259 261 8/22/2024
1.0.258 485 8/8/2024
1.0.257 904 6/12/2024
1.0.256 238 6/12/2024
1.0.255 342 5/28/2024
1.0.254 605 5/4/2024
1.0.253 352 4/23/2024
1.0.252 240 4/21/2024
1.0.251 259 4/14/2024
1.0.250 452 3/28/2024
1.0.249 237 3/17/2024
1.0.248 487 3/9/2024
1.0.247 401 2/23/2024
1.0.246 259 2/23/2024
1.0.245 375 2/18/2024
1.0.244 251 2/18/2024
1.0.243 231 2/16/2024
1.0.242 257 2/16/2024
1.0.241 323 2/13/2024
1.0.240 310 2/8/2024
1.0.239 301 2/5/2024
1.0.238 247 2/4/2024
1.0.237 362 1/23/2024
1.0.236 248 1/23/2024
1.0.235 420 1/12/2024
1.0.234 491 1/2/2024
1.0.233 289 12/29/2023
1.0.232 290 12/17/2023
1.0.231 602 12/15/2023
1.0.230 285 12/15/2023
1.0.229 265 12/15/2023
1.0.228 272 12/13/2023
1.0.227 241 12/13/2023
1.0.226 282 12/10/2023
1.0.225 534 11/18/2023
1.0.224 237 11/18/2023
1.0.223 226 11/18/2023
1.0.222 245 11/17/2023
1.0.221 220 11/12/2023
1.0.220 208 11/12/2023
1.0.219 221 11/10/2023
1.0.218 197 11/10/2023
1.0.217 235 11/9/2023
1.0.216 217 11/9/2023
1.0.215 216 11/9/2023
1.0.214 218 11/3/2023
1.0.213 240 11/1/2023
1.0.212 239 11/1/2023
1.0.211 1,130 9/8/2023
1.0.210 305 9/8/2023
1.0.209 298 9/8/2023
1.0.208 274 9/6/2023
1.0.207 286 9/6/2023
1.0.206 276 9/3/2023
1.0.205 293 8/27/2023
1.0.204 293 8/24/2023
1.0.203 277 8/21/2023
1.0.202 297 8/15/2023
1.0.201 307 8/14/2023
1.0.200 300 8/14/2023
1.0.199 312 8/10/2023
1.0.198 867 7/29/2023
1.0.197 666 7/1/2023
1.0.196 328 6/29/2023
1.0.195 557 5/27/2023
1.0.194 344 5/21/2023
1.0.193 357 5/19/2023
1.0.192 752 5/14/2023
1.0.191 485 5/8/2023
1.0.190 384 5/1/2023
1.0.189 397 4/22/2023
1.0.188 376 4/21/2023
1.0.187 1,064 4/3/2023
1.0.186 450 3/27/2023
1.0.185 448 3/21/2023
1.0.184 459 3/17/2023
1.0.183 418 3/13/2023
1.0.182 1,038 3/6/2023
1.0.181 462 2/26/2023
1.0.180 685 2/21/2023
1.0.179 469 2/20/2023
1.0.178 473 2/15/2023
1.0.177 455 2/14/2023
1.0.176 434 2/14/2023
1.0.175 774 2/9/2023
1.0.174 563 2/7/2023
1.0.173 493 2/4/2023
1.0.172 528 2/3/2023
1.0.171 612 2/2/2023
1.0.170 579 1/30/2023
1.0.169 521 1/18/2023
1.0.168 1,154 12/30/2022
1.0.167 516 12/23/2022
1.0.166 519 12/14/2022
1.0.165 504 12/14/2022
1.0.164 538 12/14/2022
1.0.163 529 12/14/2022
1.0.162 513 12/14/2022
1.0.161 875 12/12/2022
1.0.160 655 12/8/2022
1.0.159 587 12/4/2022
1.0.158 528 12/4/2022
1.0.157 552 11/30/2022
1.0.156 549 11/29/2022
1.0.155 546 11/28/2022
1.0.154 576 11/18/2022
1.0.153 1,073 11/11/2022
1.0.152 578 11/11/2022
1.0.151 569 11/10/2022
1.0.150 603 11/5/2022
1.0.149 608 11/4/2022
1.0.148 789 11/1/2022
1.0.147 926 10/16/2022
1.0.146 685 9/25/2022
1.0.145 671 9/10/2022
1.0.144 681 9/10/2022
1.0.143 1,399 9/8/2022
1.0.142 677 9/8/2022
1.0.141 692 9/8/2022
1.0.140 663 9/4/2022
1.0.139 649 9/4/2022
1.0.138 991 8/24/2022
1.0.137 665 8/8/2022
1.0.136 681 8/8/2022
1.0.135 675 7/26/2022
1.0.134 665 7/26/2022
1.0.133 1,427 7/19/2022
1.0.132 971 7/18/2022
1.0.131 737 7/13/2022
1.0.130 698 7/8/2022
1.0.129 660 6/30/2022
1.0.128 709 6/18/2022
1.0.127 744 6/6/2022
1.0.126 2,337 4/30/2022
1.0.125 749 4/20/2022
1.0.124 736 4/10/2022
1.0.123 717 4/7/2022
1.0.122 734 4/7/2022
1.0.121 715 4/2/2022
1.0.120 1,344 3/29/2022
1.0.119 716 3/27/2022
1.0.118 689 3/27/2022
1.0.117 1,123 2/20/2022
1.0.116 714 2/20/2022
1.0.115 729 2/20/2022
1.0.114 734 2/20/2022
1.0.113 751 2/20/2022
1.0.112 748 2/20/2022
1.0.111 736 2/20/2022
1.0.110 734 2/20/2022
1.0.109 748 2/20/2022
1.0.108 730 2/19/2022
1.0.107 1,661 1/24/2022
1.0.106 1,192 12/29/2021
1.0.105 796 12/20/2021
1.0.104 628 12/13/2021
1.0.103 821 12/7/2021
1.0.102 586 12/7/2021
1.0.101 1,009 12/6/2021
1.0.100 612 12/6/2021
1.0.99 606 12/5/2021
1.0.98 607 12/2/2021
1.0.97 1,302 11/29/2021
1.0.96 803 11/22/2021
1.0.95 650 11/17/2021
1.0.94 622 11/14/2021
1.0.93 862 11/13/2021
1.0.92 666 11/11/2021
1.0.91 577 11/11/2021
1.0.90 573 11/10/2021
1.0.89 595 11/9/2021
1.0.88 894 11/5/2021
1.0.87 655 11/5/2021
1.0.86 628 11/4/2021
1.0.85 613 11/4/2021
1.0.84 681 11/3/2021
1.0.83 702 10/30/2021
1.0.82 953 10/21/2021
1.0.81 755 10/17/2021
1.0.80 789 10/14/2021
1.0.79 664 10/13/2021
1.0.78 624 10/12/2021
1.0.77 701 10/11/2021
1.0.76 619 10/9/2021
1.0.75 742 10/7/2021
1.0.74 682 10/7/2021
1.0.73 602 10/7/2021
1.0.72 673 10/6/2021
1.0.71 670 9/28/2021
1.0.70 1,035 9/23/2021
1.0.69 700 9/11/2021
1.0.68 691 9/10/2021
1.0.67 686 9/9/2021
1.0.66 642 9/8/2021
1.0.65 668 9/8/2021
1.0.64 1,076 9/6/2021
1.0.63 648 8/31/2021
1.0.62 614 8/30/2021
1.0.61 1,814 7/31/2021
1.0.60 683 7/30/2021
1.0.59 716 7/26/2021
1.0.58 1,259 7/5/2021
1.0.57 632 7/1/2021
1.0.56 1,597 6/4/2021
1.0.55 2,026 4/26/2021
1.0.54 1,021 4/19/2021
1.0.53 1,189 4/7/2021
1.0.52 679 4/3/2021
1.0.51 1,316 3/22/2021
1.0.50 1,528 3/4/2021
1.0.49 900 2/26/2021
1.0.48 2,068 2/2/2021
1.0.47 1,002 1/26/2021
1.0.46 828 1/24/2021
1.0.45 703 1/24/2021
1.0.44 749 1/23/2021
1.0.43 1,039 1/20/2021
1.0.42 761 1/20/2021
1.0.41 811 1/18/2021
1.0.40 667 1/18/2021
1.0.39 874 1/16/2021
1.0.38 10,970 12/17/2020
1.0.37 3,011 12/16/2020
1.0.36 4,823 12/14/2020
1.0.35 5,991 12/9/2020
1.0.34 878 12/7/2020
1.0.33 1,060 12/6/2020
1.0.32 942 12/2/2020
1.0.31 890 12/2/2020
1.0.30 3,327 12/1/2020
1.0.29 12,608 11/12/2020
1.0.29-atestpub 665 11/11/2020
1.0.28 2,799 10/11/2020
1.0.27 6,954 9/9/2020
1.0.26 2,179 9/3/2020
1.0.25 2,423 8/20/2020
1.0.24 5,321 8/9/2020
1.0.23 2,277 7/28/2020
1.0.22 2,256 7/19/2020
1.0.21 3,232 7/6/2020
1.0.20 4,691 6/6/2020
1.0.19 2,150 6/4/2020
1.0.18 3,270 5/29/2020
1.0.17 3,313 5/21/2020
1.0.16 1,020 5/17/2020
1.0.15 3,570 5/12/2020
1.0.14 5,760 5/4/2020
1.0.13 1,672 4/24/2020
1.0.12 1,236 4/22/2020
1.0.11 1,226 4/22/2020
1.0.10 1,222 4/21/2020
1.0.9 2,774 4/18/2020
1.0.8 2,428 4/16/2020
1.0.7 1,237 4/16/2020
1.0.6 2,311 4/15/2020
1.0.5 2,546 4/11/2020
1.0.4 2,527 4/3/2020
1.0.3 1,284 4/1/2020
1.0.2 2,439 3/27/2020
1.0.1 2,634 3/22/2020
1.0.0 1,896 3/22/2020