-4

As a C# programmer, I've grown familiar with the protocol of using namespaces within .Net Framework libraries.

I was wondering, since WinAPI is implemented in C++, an unmanaged programming language with namespaces, if WinAPI libraries like User32 and Kernel32 for example, too have namespaces?

Edit: I am fully aware that C doesn't contain namespaces. I asked my question with an impression that there was some abstraction between WinAPI libraries and the C programming language it was designed to interface with.

joseph taylor
  • 123
  • 12
  • 3
    No. Those are not managed assemblies. – David Heffernan Feb 17 '18 at 05:11
  • 5
    The Win32 API is designed for C and C-compatible languages. C doesn't have namespaces. – Remy Lebeau Feb 17 '18 at 06:28
  • Please don't substantially edit your question after you have received an answer, thereby invalidating that answer. Consider asking a new question, and rolling back this one. And since you tried to edit the answer: I rejected the edit, because it was wrong. The answer is correct as written. – IInspectable Mar 14 '18 at 20:17
  • 1
    I am trying to get out of question ban. These edits are my valiant efforts, as advised. – joseph taylor Mar 14 '18 at 23:01
  • 1
    @IInspectable Does their edit really change the meaning of the question? I'm not experienced at all with WinAPI, but it appears joseph as merely clarified/provided a background for their question here. Also, this is being discussed on [meta](https://meta.stackoverflow.com/questions/364640/a-moderator-had-advised-not-improving-my-questions). – Rob Mar 15 '18 at 01:14
  • 1
    @Rob: Changing a question from *"Does the Windows API have namespaces"* to *"I know that it cannot have namespaces, but let me ask this other question"* substantially changes the question. That new question is not clear to me either. Besides, they are starting off with the false premise, that there were namespaces in .NET. There aren't. It's just an illusion programming languages like C# create. – IInspectable Mar 15 '18 at 09:40
  • @IInspectable My original question still stands, even beyond the edits: _Do WinAPI libraries have namespaces?_ I said I know C doesn't have namespaces, but do WinAPI libraries have namespaces? – joseph taylor Mar 15 '18 at 16:09

2 Answers2

1

The Windows API is exposed strictly as a C interface. There are no namespaces in C. If you need to access an API you have to:

  • Include the appropriate header file that declares the function.
  • Link to the import library that implements it.

The documentation tells you both which header to include as well as which library to link against (if any).


Update (after the question has been altered):

From a comment of yours it appears, that you are asking, whether some of the Windows API implementations use namespaces internally. Well, I don't know, and I don't care. And neither do you. Regardless of the answer, there is nothing you could do with that information.

Let's assume for a moment, that kernel32.dll were implemented in C++, and uses namespaces. To sustain a C interface, none of the namespace information can appear at the API surface. This leaves namespaces for internal use only. If they are used internally, all traces of namespaces are lost, once the linker has resolved the symbols. (The symbols may appear in private debugging symbols, or even public debugging symbols, and in string literals used for RTTI. None of these allow you to do anything meaningful, other than looking at them.)

IInspectable
  • 46,945
  • 8
  • 85
  • 181
  • 1
    That's what you need to do when programming in C and C++. For other languages it's different. The asker here is coding in C# and can't include header files and link to import libraries. – David Heffernan Feb 18 '18 at 08:26
  • @DavidHeffernan: The OP explains, that they are familiar with referencing libraries in C#. The question doesn't explicitly ask how to access the Windows API from C#, though. The [tag:C#] tag is likely not relevant (just like the [tag:user32] tag). – IInspectable Feb 19 '18 at 09:06
-1

The WinAPI libraries, despite having both C and C++ implementation, do not have namespaces, because they were designed to interface with C - a language that does not support namespaces.

joseph taylor
  • 123
  • 12
  • This is incorrect. Those Windows API libraries written in C++ may very well have namespaces. They are used internally only, and never appear at the API surface. The API wasn't designed to interface with C either. The API was designed to interface with **any** language, that can consume a C interface, e.g. C, C++, Delphi, Java, etc. – IInspectable Mar 15 '18 at 20:19
  • @IInspectable This is the answer I was looking for. I did read somewhere that all C compatible languages could interface with WinAPI, but failed to infer that it exclusively a C interface exclusively, disregarding its C++ implementations. – joseph taylor Mar 16 '18 at 04:16
  • 1
    I'm still not sure, why you are *this* obsessed with namespaces. They aren't C++' most valuable feature, and mostly serve to disambiguate symbols. Namespaces are rarely used in C++ to compartmentalize code. Also note, that there aren't any namespaces in .NET either. The CLR doesn't know about namespaces, nor does the assembly metadata have any provision to define namespaces. That doesn't prevent languages (like C#) from providing namespace support, that maps to the flat interface exposed by .NET. – IInspectable Mar 16 '18 at 09:07
  • @IInspectable As a C# programmer, "using" followed by a namespace is my primary means (other being DllImport Attribute) of importing data. And unless the Object Browser in Visual Studio 2017 is lying to me, the .NET framework libraries *do* have namespaces. – joseph taylor Mar 16 '18 at 19:07
  • [CorTokenType](https://learn.microsoft.com/en-us/dotnet/framework/unmanaged-api/metadata/cortokentype-enumeration) lists all possible tokens that can be used in .NET metadata. There is no token to encode a namespace. What looks like a namespace to a C# developer is simply the `.`-delimited common type prefix (e.g. `System.Data`). The raw type name includes that prefix (e.g. `System.Data.DataSet`). The Object Browser converts the raw metadata into a representation that developers are familiar with (i.e. namespaces in C#). It is just playing along in keeping the illusion. – IInspectable Mar 17 '18 at 09:25