Solved

Converting Windows HANDLE data type to Visual C#

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
What is Thread.Sleep? 5 45
Computer slow / BSOD 10 38
Why is compiler in oracle server ? 9 43
System.Speech 2 11
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

919 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