Ecng.Interop.Windows 1.0.397

dotnet add package Ecng.Interop.Windows --version 1.0.397
                    
NuGet\Install-Package Ecng.Interop.Windows -Version 1.0.397
                    
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.397" />
                    
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.397" />
                    
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.397
                    
#r "nuget: Ecng.Interop.Windows, 1.0.397"
                    
#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.397
                    
#: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.397
                    
Install as a Cake Addin
#tool nuget:?package=Ecng.Interop.Windows&version=1.0.397
                    
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.397 2 12/29/2025
1.0.396 81 12/26/2025
1.0.395 73 12/26/2025
1.0.394 77 12/26/2025
1.0.393 94 12/26/2025
1.0.392 159 12/25/2025
1.0.391 163 12/25/2025
1.0.390 166 12/22/2025
1.0.389 146 12/21/2025
1.0.388 194 12/19/2025
1.0.387 229 12/19/2025
1.0.386 264 12/17/2025
1.0.385 246 12/15/2025
1.0.384 240 12/15/2025
1.0.383 209 12/14/2025
1.0.382 114 12/12/2025
1.0.381 115 12/12/2025
1.0.380 109 12/12/2025
1.0.379 113 12/12/2025
1.0.378 126 12/12/2025
1.0.377 670 12/2/2025
1.0.376 679 12/2/2025
1.0.375 671 12/2/2025
1.0.374 259 11/30/2025
1.0.373 125 11/29/2025
1.0.372 127 11/28/2025
1.0.371 134 11/28/2025
1.0.370 188 11/27/2025
1.0.369 196 11/24/2025
1.0.368 194 11/24/2025
1.0.367 191 11/23/2025
1.0.366 169 11/23/2025
1.0.365 211 11/22/2025
1.0.364 412 11/20/2025
1.0.363 410 11/18/2025
1.0.362 406 11/18/2025
1.0.361 293 11/13/2025
1.0.360 291 11/13/2025
1.0.359 243 11/10/2025
1.0.358 152 11/1/2025
1.0.357 197 10/28/2025
1.0.356 195 10/27/2025
1.0.355 190 10/27/2025
1.0.354 121 10/25/2025
1.0.353 149 10/11/2025
1.0.352 166 10/3/2025
1.0.351 203 9/28/2025
1.0.350 204 9/25/2025
1.0.349 2,006 9/2/2025
1.0.348 493 8/30/2025
1.0.347 240 8/30/2025
1.0.346 209 8/19/2025
1.0.345 184 8/15/2025
1.0.344 211 8/14/2025
1.0.343 832 7/16/2025
1.0.342 428 7/14/2025
1.0.341 211 7/13/2025
1.0.340 214 7/13/2025
1.0.339 178 7/12/2025
1.0.338 332 7/8/2025
1.0.337 306 7/4/2025
1.0.336 224 7/2/2025
1.0.335 683 6/16/2025
1.0.334 369 6/9/2025
1.0.333 282 6/8/2025
1.0.332 442 5/21/2025
1.0.331 228 5/17/2025
1.0.330 520 5/12/2025
1.0.329 319 5/12/2025
1.0.328 310 5/12/2025
1.0.327 243 5/11/2025
1.0.326 255 5/11/2025
1.0.325 257 5/11/2025
1.0.324 239 5/11/2025
1.0.323 245 5/11/2025
1.0.322 240 5/11/2025
1.0.321 181 5/10/2025
1.0.320 174 5/10/2025
1.0.319 228 5/6/2025
1.0.318 243 5/2/2025
1.0.317 310 4/17/2025
1.0.316 298 4/15/2025
1.0.315 251 4/12/2025
1.0.314 221 4/12/2025
1.0.313 831 3/22/2025
1.0.312 275 3/20/2025
1.0.311 276 3/20/2025
1.0.310 260 3/19/2025
1.0.309 705 2/26/2025
1.0.308 229 2/26/2025
1.0.307 615 2/6/2025
1.0.306 219 2/6/2025
1.0.305 225 2/6/2025
1.0.304 241 2/6/2025
1.0.303 227 2/5/2025
1.0.302 234 2/5/2025
1.0.301 229 2/5/2025
1.0.300 251 2/3/2025
1.0.299 228 2/2/2025
1.0.298 220 2/1/2025
1.0.297 231 1/31/2025
1.0.296 220 1/30/2025
1.0.295 227 1/26/2025
1.0.294 216 1/21/2025
1.0.293 239 1/20/2025
1.0.292 201 1/20/2025
1.0.291 220 1/19/2025
1.0.290 208 1/19/2025
1.0.289 216 1/14/2025
1.0.288 216 1/12/2025
1.0.287 193 1/12/2025
1.0.286 219 1/12/2025
1.0.285 201 1/12/2025
1.0.284 213 1/10/2025
1.0.283 890 12/30/2024
1.0.282 216 12/27/2024
1.0.281 236 12/19/2024
1.0.280 229 11/20/2024
1.0.279 235 11/19/2024
1.0.278 239 11/19/2024
1.0.277 860 11/18/2024
1.0.276 321 11/7/2024
1.0.275 233 10/31/2024
1.0.274 268 10/19/2024
1.0.273 263 10/19/2024
1.0.272 267 10/19/2024
1.0.271 728 10/13/2024
1.0.270 226 10/12/2024
1.0.269 326 10/9/2024
1.0.268 208 10/9/2024
1.0.267 253 10/5/2024
1.0.266 520 9/18/2024
1.0.265 241 9/17/2024
1.0.264 425 9/4/2024
1.0.263 241 9/3/2024
1.0.262 250 9/3/2024
1.0.261 242 9/1/2024
1.0.260 485 8/23/2024
1.0.259 258 8/22/2024
1.0.258 483 8/8/2024
1.0.257 902 6/12/2024
1.0.256 235 6/12/2024
1.0.255 340 5/28/2024
1.0.254 601 5/4/2024
1.0.253 350 4/23/2024
1.0.252 236 4/21/2024
1.0.251 257 4/14/2024
1.0.250 450 3/28/2024
1.0.249 234 3/17/2024
1.0.248 485 3/9/2024
1.0.247 399 2/23/2024
1.0.246 254 2/23/2024
1.0.245 371 2/18/2024
1.0.244 249 2/18/2024
1.0.243 228 2/16/2024
1.0.242 255 2/16/2024
1.0.241 320 2/13/2024
1.0.240 306 2/8/2024
1.0.239 299 2/5/2024
1.0.238 245 2/4/2024
1.0.237 358 1/23/2024
1.0.236 246 1/23/2024
1.0.235 418 1/12/2024
1.0.234 489 1/2/2024
1.0.233 287 12/29/2023
1.0.232 286 12/17/2023
1.0.231 598 12/15/2023
1.0.230 283 12/15/2023
1.0.229 263 12/15/2023
1.0.228 269 12/13/2023
1.0.227 237 12/13/2023
1.0.226 280 12/10/2023
1.0.225 533 11/18/2023
1.0.224 237 11/18/2023
1.0.223 226 11/18/2023
1.0.222 244 11/17/2023
1.0.221 220 11/12/2023
1.0.220 206 11/12/2023
1.0.219 220 11/10/2023
1.0.218 195 11/10/2023
1.0.217 234 11/9/2023
1.0.216 217 11/9/2023
1.0.215 215 11/9/2023
1.0.214 218 11/3/2023
1.0.213 239 11/1/2023
1.0.212 238 11/1/2023
1.0.211 1,129 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 285 9/6/2023
1.0.206 275 9/3/2023
1.0.205 293 8/27/2023
1.0.204 292 8/24/2023
1.0.203 276 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 311 8/10/2023
1.0.198 866 7/29/2023
1.0.197 666 7/1/2023
1.0.196 324 6/29/2023
1.0.195 557 5/27/2023
1.0.194 343 5/21/2023
1.0.193 355 5/19/2023
1.0.192 752 5/14/2023
1.0.191 485 5/8/2023
1.0.190 383 5/1/2023
1.0.189 395 4/22/2023
1.0.188 373 4/21/2023
1.0.187 1,063 4/3/2023
1.0.186 448 3/27/2023
1.0.185 446 3/21/2023
1.0.184 458 3/17/2023
1.0.183 417 3/13/2023
1.0.182 1,036 3/6/2023
1.0.181 461 2/26/2023
1.0.180 685 2/21/2023
1.0.179 469 2/20/2023
1.0.178 471 2/15/2023
1.0.177 454 2/14/2023
1.0.176 434 2/14/2023
1.0.175 773 2/9/2023
1.0.174 562 2/7/2023
1.0.173 492 2/4/2023
1.0.172 528 2/3/2023
1.0.171 611 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 513 12/23/2022
1.0.166 518 12/14/2022
1.0.165 504 12/14/2022
1.0.164 536 12/14/2022
1.0.163 527 12/14/2022
1.0.162 512 12/14/2022
1.0.161 874 12/12/2022
1.0.160 654 12/8/2022
1.0.159 586 12/4/2022
1.0.158 527 12/4/2022
1.0.157 551 11/30/2022
1.0.156 548 11/29/2022
1.0.155 546 11/28/2022
1.0.154 575 11/18/2022
1.0.153 1,073 11/11/2022
1.0.152 575 11/11/2022
1.0.151 567 11/10/2022
1.0.150 601 11/5/2022
1.0.149 608 11/4/2022
1.0.148 789 11/1/2022
1.0.147 925 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,398 9/8/2022
1.0.142 676 9/8/2022
1.0.141 691 9/8/2022
1.0.140 663 9/4/2022
1.0.139 648 9/4/2022
1.0.138 989 8/24/2022
1.0.137 664 8/8/2022
1.0.136 680 8/8/2022
1.0.135 674 7/26/2022
1.0.134 662 7/26/2022
1.0.133 1,426 7/19/2022
1.0.132 969 7/18/2022
1.0.131 736 7/13/2022
1.0.130 697 7/8/2022
1.0.129 659 6/30/2022
1.0.128 706 6/18/2022
1.0.127 741 6/6/2022
1.0.126 2,335 4/30/2022
1.0.125 748 4/20/2022
1.0.124 734 4/10/2022
1.0.123 715 4/7/2022
1.0.122 731 4/7/2022
1.0.121 713 4/2/2022
1.0.120 1,342 3/29/2022
1.0.119 714 3/27/2022
1.0.118 687 3/27/2022
1.0.117 1,121 2/20/2022
1.0.116 713 2/20/2022
1.0.115 727 2/20/2022
1.0.114 733 2/20/2022
1.0.113 750 2/20/2022
1.0.112 746 2/20/2022
1.0.111 735 2/20/2022
1.0.110 733 2/20/2022
1.0.109 746 2/20/2022
1.0.108 728 2/19/2022
1.0.107 1,659 1/24/2022
1.0.106 1,190 12/29/2021
1.0.105 794 12/20/2021
1.0.104 627 12/13/2021
1.0.103 819 12/7/2021
1.0.102 584 12/7/2021
1.0.101 1,008 12/6/2021
1.0.100 611 12/6/2021
1.0.99 605 12/5/2021
1.0.98 605 12/2/2021
1.0.97 1,301 11/29/2021
1.0.96 801 11/22/2021
1.0.95 646 11/17/2021
1.0.94 620 11/14/2021
1.0.93 861 11/13/2021
1.0.92 665 11/11/2021
1.0.91 576 11/11/2021
1.0.90 570 11/10/2021
1.0.89 594 11/9/2021
1.0.88 892 11/5/2021
1.0.87 654 11/5/2021
1.0.86 627 11/4/2021
1.0.85 611 11/4/2021
1.0.84 680 11/3/2021
1.0.83 697 10/30/2021
1.0.82 951 10/21/2021
1.0.81 753 10/17/2021
1.0.80 788 10/14/2021
1.0.79 663 10/13/2021
1.0.78 622 10/12/2021
1.0.77 700 10/11/2021
1.0.76 616 10/9/2021
1.0.75 740 10/7/2021
1.0.74 680 10/7/2021
1.0.73 601 10/7/2021
1.0.72 672 10/6/2021
1.0.71 668 9/28/2021
1.0.70 1,032 9/23/2021
1.0.69 699 9/11/2021
1.0.68 688 9/10/2021
1.0.67 685 9/9/2021
1.0.66 640 9/8/2021
1.0.65 667 9/8/2021
1.0.64 1,074 9/6/2021
1.0.63 646 8/31/2021
1.0.62 612 8/30/2021
1.0.61 1,812 7/31/2021
1.0.60 679 7/30/2021
1.0.59 714 7/26/2021
1.0.58 1,259 7/5/2021
1.0.57 631 7/1/2021
1.0.56 1,597 6/4/2021
1.0.55 2,024 4/26/2021
1.0.54 1,018 4/19/2021
1.0.53 1,189 4/7/2021
1.0.52 679 4/3/2021
1.0.51 1,315 3/22/2021
1.0.50 1,527 3/4/2021
1.0.49 899 2/26/2021
1.0.48 2,067 2/2/2021
1.0.47 1,001 1/26/2021
1.0.46 825 1/24/2021
1.0.45 695 1/24/2021
1.0.44 749 1/23/2021
1.0.43 1,037 1/20/2021
1.0.42 761 1/20/2021
1.0.41 810 1/18/2021
1.0.40 666 1/18/2021
1.0.39 873 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,989 12/9/2020
1.0.34 877 12/7/2020
1.0.33 1,060 12/6/2020
1.0.32 941 12/2/2020
1.0.31 889 12/2/2020
1.0.30 3,327 12/1/2020
1.0.29 12,606 11/12/2020
1.0.29-atestpub 664 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,320 8/9/2020
1.0.23 2,276 7/28/2020
1.0.22 2,255 7/19/2020
1.0.21 3,232 7/6/2020
1.0.20 4,691 6/6/2020
1.0.19 2,148 6/4/2020
1.0.18 3,270 5/29/2020
1.0.17 3,313 5/21/2020
1.0.16 1,019 5/17/2020
1.0.15 3,570 5/12/2020
1.0.14 5,759 5/4/2020
1.0.13 1,671 4/24/2020
1.0.12 1,235 4/22/2020
1.0.11 1,224 4/22/2020
1.0.10 1,220 4/21/2020
1.0.9 2,773 4/18/2020
1.0.8 2,428 4/16/2020
1.0.7 1,237 4/16/2020
1.0.6 2,309 4/15/2020
1.0.5 2,544 4/11/2020
1.0.4 2,527 4/3/2020
1.0.3 1,281 4/1/2020
1.0.2 2,438 3/27/2020
1.0.1 2,633 3/22/2020
1.0.0 1,895 3/22/2020