Solved

Converting Windows HANDLE data type to Visual C#

Posted on 2009-07-06
1
1,014 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
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now