Ecng.Interop.Windows 1.0.394

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.394
                    
NuGet\Install-Package Ecng.Interop.Windows -Version 1.0.394
                    
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.394" />
                    
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.394" />
                    
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.394
                    
#r "nuget: Ecng.Interop.Windows, 1.0.394"
                    
#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.394
                    
#: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.394
                    
Install as a Cake Addin
#tool nuget:?package=Ecng.Interop.Windows&version=1.0.394
                    
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.400 33 12/31/2025
1.0.399 43 12/30/2025
1.0.398 37 12/30/2025
1.0.397 45 12/29/2025
1.0.396 90 12/26/2025
1.0.395 81 12/26/2025
1.0.394 85 12/26/2025
1.0.393 102 12/26/2025
1.0.392 169 12/25/2025
1.0.391 172 12/25/2025
1.0.390 168 12/22/2025
1.0.389 148 12/21/2025
1.0.388 196 12/19/2025
1.0.387 231 12/19/2025
1.0.386 266 12/17/2025
1.0.385 248 12/15/2025
1.0.384 242 12/15/2025
1.0.383 212 12/14/2025
1.0.382 117 12/12/2025
1.0.381 117 12/12/2025
1.0.380 111 12/12/2025
1.0.379 115 12/12/2025
1.0.378 128 12/12/2025
1.0.377 672 12/2/2025
1.0.376 681 12/2/2025
1.0.375 673 12/2/2025
1.0.374 262 11/30/2025
1.0.373 128 11/29/2025
1.0.372 129 11/28/2025
1.0.371 136 11/28/2025
1.0.370 190 11/27/2025
1.0.369 199 11/24/2025
1.0.368 196 11/24/2025
1.0.367 194 11/23/2025
1.0.366 171 11/23/2025
1.0.365 214 11/22/2025
1.0.364 414 11/20/2025
1.0.363 412 11/18/2025
1.0.362 408 11/18/2025
1.0.361 296 11/13/2025
1.0.360 294 11/13/2025
1.0.359 246 11/10/2025
1.0.358 154 11/1/2025
1.0.357 199 10/28/2025
1.0.356 198 10/27/2025
1.0.355 192 10/27/2025
1.0.354 123 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,028 9/2/2025
1.0.348 495 8/30/2025
1.0.347 242 8/30/2025
1.0.346 211 8/19/2025
1.0.345 186 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 334 7/8/2025
1.0.337 308 7/4/2025
1.0.336 226 7/2/2025
1.0.335 685 6/16/2025
1.0.334 371 6/9/2025
1.0.333 284 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 321 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 247 5/11/2025
1.0.322 243 5/11/2025
1.0.321 183 5/10/2025
1.0.320 177 5/10/2025
1.0.319 230 5/6/2025
1.0.318 245 5/2/2025
1.0.317 312 4/17/2025
1.0.316 300 4/15/2025
1.0.315 253 4/12/2025
1.0.314 223 4/12/2025
1.0.313 835 3/22/2025
1.0.312 278 3/20/2025
1.0.311 278 3/20/2025
1.0.310 262 3/19/2025
1.0.309 708 2/26/2025
1.0.308 231 2/26/2025
1.0.307 618 2/6/2025
1.0.306 221 2/6/2025
1.0.305 227 2/6/2025
1.0.304 243 2/6/2025
1.0.303 230 2/5/2025
1.0.302 237 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 222 1/30/2025
1.0.295 229 1/26/2025
1.0.294 219 1/21/2025
1.0.293 241 1/20/2025
1.0.292 203 1/20/2025
1.0.291 224 1/19/2025
1.0.290 210 1/19/2025
1.0.289 219 1/14/2025
1.0.288 218 1/12/2025
1.0.287 195 1/12/2025
1.0.286 222 1/12/2025
1.0.285 204 1/12/2025
1.0.284 215 1/10/2025
1.0.283 892 12/30/2024
1.0.282 219 12/27/2024
1.0.281 238 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 323 11/7/2024
1.0.275 235 10/31/2024
1.0.274 270 10/19/2024
1.0.273 265 10/19/2024
1.0.272 269 10/19/2024
1.0.271 730 10/13/2024
1.0.270 229 10/12/2024
1.0.269 329 10/9/2024
1.0.268 210 10/9/2024
1.0.267 255 10/5/2024
1.0.266 522 9/18/2024
1.0.265 243 9/17/2024
1.0.264 427 9/4/2024
1.0.263 244 9/3/2024
1.0.262 253 9/3/2024
1.0.261 245 9/1/2024
1.0.260 487 8/23/2024
1.0.259 260 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 603 5/4/2024
1.0.253 352 4/23/2024
1.0.252 238 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 256 2/23/2024
1.0.245 374 2/18/2024
1.0.244 251 2/18/2024
1.0.243 230 2/16/2024
1.0.242 257 2/16/2024
1.0.241 323 2/13/2024
1.0.240 309 2/8/2024
1.0.239 301 2/5/2024
1.0.238 247 2/4/2024
1.0.237 360 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 289 12/17/2023
1.0.231 600 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 239 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 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 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 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 286 9/6/2023
1.0.206 276 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 867 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 344 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 396 4/22/2023
1.0.188 374 4/21/2023
1.0.187 1,064 4/3/2023
1.0.186 449 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,037 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 472 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 493 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 514 12/23/2022
1.0.166 518 12/14/2022
1.0.165 504 12/14/2022
1.0.164 537 12/14/2022
1.0.163 529 12/14/2022
1.0.162 513 12/14/2022
1.0.161 874 12/12/2022
1.0.160 654 12/8/2022
1.0.159 587 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 603 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 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 664 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 708 6/18/2022
1.0.127 743 6/6/2022
1.0.126 2,336 4/30/2022
1.0.125 749 4/20/2022
1.0.124 735 4/10/2022
1.0.123 717 4/7/2022
1.0.122 732 4/7/2022
1.0.121 715 4/2/2022
1.0.120 1,343 3/29/2022
1.0.119 715 3/27/2022
1.0.118 688 3/27/2022
1.0.117 1,122 2/20/2022
1.0.116 714 2/20/2022
1.0.115 728 2/20/2022
1.0.114 734 2/20/2022
1.0.113 751 2/20/2022
1.0.112 747 2/20/2022
1.0.111 736 2/20/2022
1.0.110 734 2/20/2022
1.0.109 747 2/20/2022
1.0.108 729 2/19/2022
1.0.107 1,661 1/24/2022
1.0.106 1,191 12/29/2021
1.0.105 796 12/20/2021
1.0.104 628 12/13/2021
1.0.103 820 12/7/2021
1.0.102 585 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 648 11/17/2021
1.0.94 621 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 571 11/10/2021
1.0.89 595 11/9/2021
1.0.88 893 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 699 10/30/2021
1.0.82 952 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 623 10/12/2021
1.0.77 701 10/11/2021
1.0.76 618 10/9/2021
1.0.75 741 10/7/2021
1.0.74 681 10/7/2021
1.0.73 602 10/7/2021
1.0.72 673 10/6/2021
1.0.71 669 9/28/2021
1.0.70 1,033 9/23/2021
1.0.69 700 9/11/2021
1.0.68 690 9/10/2021
1.0.67 686 9/9/2021
1.0.66 641 9/8/2021
1.0.65 668 9/8/2021
1.0.64 1,075 9/6/2021
1.0.63 647 8/31/2021
1.0.62 613 8/30/2021
1.0.61 1,813 7/31/2021
1.0.60 682 7/30/2021
1.0.59 716 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,019 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,527 3/4/2021
1.0.49 900 2/26/2021
1.0.48 2,067 2/2/2021
1.0.47 1,002 1/26/2021
1.0.46 825 1/24/2021
1.0.45 701 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,990 12/9/2020
1.0.34 877 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,607 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,149 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,671 4/24/2020
1.0.12 1,236 4/22/2020
1.0.11 1,224 4/22/2020
1.0.10 1,221 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,545 4/11/2020
1.0.4 2,527 4/3/2020
1.0.3 1,282 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