Solved

Converting Windows HANDLE data type to Visual C#

Posted on 2009-07-06
1
1,030 Views
Last Modified: 2012-05-07
I want to convert the following line to Visual C# code.

HANDLE bob = INVALID_HANDLE_VALUE;

So I need a C# equivalent for HANDLE
And I want to define INVALID_HANDLE_VALUE as a C# constant.


Notes:
1. INVALID_HANDLE_VALUE is defined in WinBase.h thus;
#define INVALID_HANDLE_VALUE ((HANDLE)(LONG_PTR)-1)   in WinBase.h

2. HANDLE is defined in windows.h
0
Comment
Question by:rangers99
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 12

Accepted Solution

by:
williamcampbell earned 125 total points
ID: 24788804
public const int INVALID_HANDLE_VALUE = -1;

    IntPtr hFile = CreateFile(...);
    if (hFile.ToInt32() == INVALID_HANDLE_VALUE)
    {
        // invalid handle returned
    }

or

 IntPtr INVALID_HANDLE_VALUE = new IntPtr(-1);
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question