Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Converting Windows HANDLE data type to Visual C#

Posted on 2009-07-06
1
Medium Priority
?
1,052 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 500 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
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 how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

636 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