-1

What data type of HANDLE could be in C++ Linux?, or it can be any type based on the requirement.

HANDLE can be void type or other data types.

The example below to define the use of HANDLE type in my code.

HANDLE hFile;

HANDLE hFile = CreateFile(hldFile, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);

I need to define the data type to HANDLE to return value of calling other functions like CreateFile in the example above.

Yamur
  • 339
  • 6
  • 20
  • It's `int` like in : `int f = open(....`; – Jabberwocky Oct 12 '17 at 12:05
  • 2
    There is no equivalent. You use the types specified in each function's declaration. – David Heffernan Oct 12 '17 at 15:20
  • 1
    The question is not duplicated I SEARCHED BEFORE. I am not asking about `CreateFile`. I am asking about `HANDLE` – Yamur Oct 12 '17 at 15:25
  • 1
    `HANDLE` and `CreateFile` go hand in hand. If your code uses both then both need to change if you want your code to work on Linux. Linux has neither `HANDLE` nor `CreateFile`. If your code uses other functions that return `HANDLE` values or take `HANDLE` values as arguments, like `ReadFile` or `CloseHandle`, then those functions don't exist on Linux either and also need to be changed. – Ross Ridge Oct 12 '17 at 17:00
  • 2
    Doesn't look like a duplicate to me - but it is unclear what you're asking. If you can rewrite your question to make it clearer what you're actually trying to achieve, it might get reopened. – Harry Johnston Oct 12 '17 at 20:48
  • @Ross Ridge thanks for this declaration, it is really simple and clear. – Yamur Oct 13 '17 at 10:47
  • 1
    This question is not a duplicate, and it is wrong to close it just "because you can"... Anyway, @YAcaCsh I spent some time testing and I ended up using open() and pwrite(), and they get the job done exactly as CreateFile and WriteFile does. Here my piece for you... https://pastebin.com/gwn3PCDp – Mecanik Oct 14 '17 at 18:21
  • @Norbert Boros big thanks. It is really useful piece :) – Yamur Oct 16 '17 at 07:54
  • @YAcaCsh No problem, I am very happy I could help. Stackoverflow is a great place, but the people are overpowered and they play around by "marking as duplicate" and stuff... really disappointed. – Mecanik Oct 16 '17 at 15:59
  • @Norbert Boros yes, I am totally agree with you. – Yamur Oct 16 '17 at 16:07
  • I came across this question in the reopen queue. While I agree it is not a duplicate, it is not clear enough to me what you are asking that I could try and answer it. I regret that your question was closed for the wrong reason, but I do think it was right to close it in its current form. You're welcome to edit and improve the question so others who have similar problems can learn from your experience. – Sam Hartman Oct 19 '17 at 19:46

1 Answers1

2

That might be open() function with appropriate flags or creat(). Roughly speaking that would be int type.

Ron
  • 14,674
  • 4
  • 34
  • 47
  • Then, as I understand from your answer that `HANDLE` can be any type based on the use of it. Like `wchar` or `char` – Yamur Oct 12 '17 at 12:20
  • `HANDLE` is a *pointer*. You cannot coerce it into an integer. With the `STRICT` symbol defined, the Windows headers help you out by defining it as a pointer-to-struct to prevent you from interconverting between different types of incompatible pointers, but it's still a pointer, and you do have to worry about that. It is never a `wchar_t` or a `char`. – Cody Gray - on strike Oct 12 '17 at 15:26
  • 1
    @CodyGray, if `STRICT` is defined, as is normally the case (i.e. `NO_STRICT` is not defined), then `HANDLE` and `HGDIOBJ` are typedefs for `void *`; `HGLOBAL` and `HLOCAL` are typedefs for `HANDLE`; and most other handle types with a given type `name##` are typedefs for a `struct name##__{int unused;} *`. Otherwise with the non-strict definitions, `HANDLE` is a typedef for `PVOID`, and other handle types are typedefs for `HANDLE`. – Eryk Sun Oct 12 '17 at 17:29
  • 1
    @Cody, my interpretation of the question is that the OP is trying to build a library that emulates part of the Win32 API on Linux (e.g., he wants to write a CreateFile function) in which case he's probably not using the Windows headers. – Harry Johnston Oct 12 '17 at 20:49
  • I had a completely different view of the question, @Harry. It's possible my interpretation was wrong. It isn't especially clear to me. Also, I appear to have misremembered how `HANDLE` was defined. eryksun is right; it's unaffected by `STRICT`. It's always a `void*`. – Cody Gray - on strike Oct 13 '17 at 09:04