<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="FeedCreator 1.8" -->
<?xml-stylesheet href="http://wiki.nathancampos.me/lib/exe/css.php?s=feed" type="text/css"?>
<rdf:RDF
    xmlns="http://purl.org/rss/1.0/"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
    xmlns:dc="http://purl.org/dc/elements/1.1/">
    <channel rdf:about="http://wiki.nathancampos.me/feed.php">
        <title>Nathan&#039;s KB - devnotes</title>
        <description>Hello</description>
        <link>http://wiki.nathancampos.me/</link>
        <image rdf:resource="http://wiki.nathancampos.me/lib/exe/fetch.php?media=wiki:dokuwiki.svg" />
       <dc:date>2026-05-13T08:28:14+00:00</dc:date>
        <items>
            <rdf:Seq>
                <rdf:li rdf:resource="http://wiki.nathancampos.me/doku.php?id=devnotes:groundlift"/>
                <rdf:li rdf:resource="http://wiki.nathancampos.me/doku.php?id=devnotes:macos"/>
                <rdf:li rdf:resource="http://wiki.nathancampos.me/doku.php?id=devnotes:msvc-porting"/>
                <rdf:li rdf:resource="http://wiki.nathancampos.me/doku.php?id=devnotes:netaddr"/>
                <rdf:li rdf:resource="http://wiki.nathancampos.me/doku.php?id=devnotes:shortcircuit"/>
                <rdf:li rdf:resource="http://wiki.nathancampos.me/doku.php?id=devnotes:unity"/>
            </rdf:Seq>
        </items>
    </channel>
    <image rdf:about="http://wiki.nathancampos.me/lib/exe/fetch.php?media=wiki:dokuwiki.svg">
        <title>Nathan's KB</title>
        <link>http://wiki.nathancampos.me/</link>
        <url>http://wiki.nathancampos.me/lib/exe/fetch.php?media=wiki:dokuwiki.svg</url>
    </image>
    <item rdf:about="http://wiki.nathancampos.me/doku.php?id=devnotes:groundlift">
        <dc:format>text/html</dc:format>
        <dc:date>2023-05-13T07:58:28+00:00</dc:date>
        <dc:creator>Anonymous (anonymous@undisclosed.example.com)</dc:creator>
        <title>groundlift</title>
        <link>http://wiki.nathancampos.me/doku.php?id=devnotes:groundlift</link>
        <description>
&lt;h1 class=&quot;sectionedit1&quot; id=&quot;groundlift&quot;&gt;GroundLift&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;p&gt;
The development notes are to be used for reference while developing &lt;a href=&quot;http://wiki.nathancampos.me/doku.php?id=groundlift&quot; class=&quot;wikilink2&quot; title=&quot;groundlift&quot; rel=&quot;nofollow&quot; data-wiki-id=&quot;groundlift&quot;&gt;GroundLift&lt;/a&gt;. Keep in mind that when this page was created the library and command line application were almost finished. More specifically we were in &lt;a href=&quot;https://github.com/nathanpc/groundlift/commit/dda76fece9929c324ab672f3b8e9e7bc7903f268&quot; class=&quot;urlextern&quot; title=&quot;https://github.com/nathanpc/groundlift/commit/dda76fece9929c324ab672f3b8e9e7bc7903f268&quot; rel=&quot;ugc nofollow&quot;&gt;commit dda76fe&lt;/a&gt;. For reference, the last commit before the Windows port was &lt;a href=&quot;https://github.com/nathanpc/groundlift/commit/35c5c888d357db6fc468e22c36c67009a3693ea7&quot; class=&quot;urlextern&quot; title=&quot;https://github.com/nathanpc/groundlift/commit/35c5c888d357db6fc468e22c36c67009a3693ea7&quot; rel=&quot;ugc nofollow&quot;&gt;commit 35c5c88&lt;/a&gt;.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;GroundLift&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;groundlift&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:1,&amp;quot;range&amp;quot;:&amp;quot;1-533&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit2&quot; id=&quot;porting_to_apple_systems&quot;&gt;Porting to Apple Systems&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Porting to Apple Systems&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;porting_to_apple_systems&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:2,&amp;quot;range&amp;quot;:&amp;quot;534-571&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit3&quot; id=&quot;multicast_entitlement&quot;&gt;Multicast Entitlement&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
Apparently in order to send any sort of general broadcast or multicast packet outside of very strict mDNS (or Bonjour as Apple likes to call it) rules you are &lt;a href=&quot;https://developer.apple.com/documentation/bundleresources/entitlements/com_apple_developer_networking_multicast&quot; class=&quot;urlextern&quot; title=&quot;https://developer.apple.com/documentation/bundleresources/entitlements/com_apple_developer_networking_multicast&quot; rel=&quot;ugc nofollow&quot;&gt;required to request an entitlement from Apple&lt;/a&gt;, namely &lt;code&gt;com.apple.developer.networking.multicast&lt;/code&gt;. This will only be required when porting our library to more strict platforms like iOS or sandboxed macOS, but we need to perform some tests in order to ensure that Xcode won&amp;#039;t block us by default even when not targeting the App Store for macOS deployments.
&lt;/p&gt;

&lt;p&gt;
The worst part about all of this is that &lt;a href=&quot;https://developer.apple.com/forums/thread/661283&quot; class=&quot;urlextern&quot; title=&quot;https://developer.apple.com/forums/thread/661283&quot; rel=&quot;ugc nofollow&quot;&gt;the entitlement is required even for development&lt;/a&gt;! This is the dumbest move ever, but let&amp;#039;s ignore it for now. Maybe, since Apple apparently takes its sweet time processing requests, we could wrap the network discovery code behind a preprocessor flag and ensure that we have an alternative mechanism for doing “manual discovery” (i.e. something like asking your buddy to tell you their IP).
&lt;/p&gt;

&lt;p&gt;
If we ever need more information on the subject, the great &lt;a href=&quot;https://developer.apple.com/forums/profile/eskimo&quot; class=&quot;urlextern&quot; title=&quot;https://developer.apple.com/forums/profile/eskimo&quot; rel=&quot;ugc nofollow&quot;&gt;eskimo&lt;/a&gt; has blessed us with a &lt;a href=&quot;https://developer.apple.com/forums/thread/663271&quot; class=&quot;urlextern&quot; title=&quot;https://developer.apple.com/forums/thread/663271&quot; rel=&quot;ugc nofollow&quot;&gt;summary of everything we may want to know about the entitlement&lt;/a&gt;.
&lt;/p&gt;

&lt;p&gt;
All of this is part of Apple&amp;#039;s &lt;a href=&quot;https://developer.apple.com/forums/thread/663858&quot; class=&quot;urlextern&quot; title=&quot;https://developer.apple.com/forums/thread/663858&quot; rel=&quot;ugc nofollow&quot;&gt;Local Network Privacy&lt;/a&gt; initiative, which is just some bullshit to restrict things in the name of privacy.
&lt;/p&gt;

&lt;p&gt;
If we still want to test the discovery code before or during the entitlement requisition process the only option we have available is to &lt;a href=&quot;https://developer.apple.com/forums/thread/714211&quot; class=&quot;urlextern&quot; title=&quot;https://developer.apple.com/forums/thread/714211&quot; rel=&quot;ugc nofollow&quot;&gt;use a real iOS device running iOS &amp;lt;= 14.5&lt;/a&gt;.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Multicast Entitlement&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;multicast_entitlement&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:3,&amp;quot;range&amp;quot;:&amp;quot;572-2407&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit4&quot; id=&quot;porting_to_older_systems&quot;&gt;Porting to Older Systems&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Porting to Older Systems&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;porting_to_older_systems&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:4,&amp;quot;range&amp;quot;:&amp;quot;2408-2445&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit5&quot; id=&quot;getxbyy_functions&quot;&gt;getXbyY Functions&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
Take a look into these &lt;strong&gt;deprecated&lt;/strong&gt; functions as maybe a portability path for functionality like &lt;code&gt;&lt;a href=&quot;https://man7.org/linux/man-pages/man3/getaddrinfo.3.html&quot; class=&quot;urlextern&quot; title=&quot;https://man7.org/linux/man-pages/man3/getaddrinfo.3.html&quot; rel=&quot;ugc nofollow&quot;&gt;getaddrinfo(3)&lt;/a&gt;&lt;/code&gt; on much older, pre-IPv6, systems. One quick example of such a function would be &lt;code&gt;&lt;a href=&quot;https://man7.org/linux/man-pages/man3/gethostbyname.3.html&quot; class=&quot;urlextern&quot; title=&quot;https://man7.org/linux/man-pages/man3/gethostbyname.3.html&quot; rel=&quot;ugc nofollow&quot;&gt;gethostbyname(3)&lt;/a&gt;&lt;/code&gt;.
&lt;/p&gt;

&lt;p&gt;
According to &lt;a href=&quot;https://learn.microsoft.com/en-us/windows/win32/winsock/error-codes-errno-h-errno-and-wsagetlasterror-2&quot; class=&quot;urlextern&quot; title=&quot;https://learn.microsoft.com/en-us/windows/win32/winsock/error-codes-errno-h-errno-and-wsagetlasterror-2&quot; rel=&quot;ugc nofollow&quot;&gt;Microsoft&lt;/a&gt;:
&lt;/p&gt;
&lt;blockquote&gt;&lt;div class=&quot;no&quot;&gt;
 Additional functions have been added over time to enhance Winsock for use by developers. For example, new name service functions (&lt;code&gt;getaddrinfo&lt;/code&gt; and &lt;code&gt;getnameinfo&lt;/code&gt;, for example) were added that support both IPv6 and IPv4 on Windows XP and later. Some of the older IPv4-only name service functions (the &lt;code&gt;getXbyY&lt;/code&gt; class of functions, for example) have been deprecated.&lt;/div&gt;&lt;/blockquote&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;getXbyY Functions&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;getxbyy_functions&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:5,&amp;quot;range&amp;quot;:&amp;quot;2446-3327&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit6&quot; id=&quot;peer_discovery_service&quot;&gt;Peer Discovery Service&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
Currently, we have implemented our peer discovery mechanism by sending a simple UDP broadcast message to the generic broadcast address (&lt;code&gt;255.255.255.255&lt;/code&gt;). This means that the &lt;abbr title=&quot;Operating System&quot;&gt;OS&lt;/abbr&gt; is choosing one interface to send this broadcast message through, we have no control over which network interface is chosen, and we desperately need to start working on changing this since we&amp;#039;ve already started bumping into the &lt;abbr title=&quot;Operating System&quot;&gt;OS&lt;/abbr&gt; choosing the wrong interface to send the message through when porting the software to Windows.
&lt;/p&gt;

&lt;p&gt;
Since our Windows machines usually have Hyper-V or some other type of virtualization software that creates virtual network interfaces installed, the &lt;abbr title=&quot;Operating System&quot;&gt;OS&lt;/abbr&gt; was choosing the wrong interface to send the broadcast message through (either this or Windows has some issue with using the generic broadcast address). This was verified by hardcoding the local network&amp;#039;s broadcast address in the peer discovery code, which immediately sprung back to life and started working.
&lt;/p&gt;

&lt;p&gt;
We must implement a way of, on modern platforms, to iterate over the network interfaces available, figure out the broadcast address of each one, send the broadcasts on each network, and combine the replies into a single pool. We must also provide a fallback mechanism for older systems to still just broadcast to the generic address since some of the functions to support multiple network interfaces might not be available on such older or constrained systems.
&lt;/p&gt;

&lt;p&gt;
Whenever we go down the path of iterating over multiple network interfaces we must take special consideration of the fact that we may end up in a weird situation where two network interfaces might be connected to the same physical network (i.e. Ethernet and Wi-Fi are both connected on the same home network) and we&amp;#039;ll be duplicating the peers discovered. We still need to research how we can address this issue and check if both interfaces are connected to the same physical network.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Peer Discovery Service&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;peer_discovery_service&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:6,&amp;quot;range&amp;quot;:&amp;quot;3328-5282&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit7&quot; id=&quot;encoding_mechanisms&quot;&gt;Encoding Mechanisms&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
Instead of having to tell your friend that wants to share some data with you your entire IP address, which a lot of people will not do and is extremely cumbersome, we could encode this data in such a way that it is small enough for people to be comfortable speaking it out loud. Look into &lt;a href=&quot;https://en.wikipedia.org/wiki/Base36&quot; class=&quot;urlextern&quot; title=&quot;https://en.wikipedia.org/wiki/Base36&quot; rel=&quot;ugc nofollow&quot;&gt;Base36&lt;/a&gt; and &lt;a href=&quot;https://en.wikipedia.org/wiki/Base64&quot; class=&quot;urlextern&quot; title=&quot;https://en.wikipedia.org/wiki/Base64&quot; rel=&quot;ugc nofollow&quot;&gt;Base64&lt;/a&gt; as possible ways to encode the binary representation of the IP address.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Encoding Mechanisms&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;encoding_mechanisms&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:7,&amp;quot;range&amp;quot;:&amp;quot;5283-5775&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit8&quot; id=&quot;windows_porting&quot;&gt;Windows Porting&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
&lt;em&gt;General topics of this section have been moved to &lt;a href=&quot;http://wiki.nathancampos.me/doku.php?id=devnotes:msvc-porting#sockets_and_network_programming&quot; class=&quot;wikilink1&quot; title=&quot;devnotes:msvc-porting&quot; data-wiki-id=&quot;devnotes:msvc-porting&quot;&gt;devnotes:msvc-porting&lt;/a&gt;.&lt;/em&gt;
&lt;/p&gt;

&lt;p&gt;
Since we already have a lot of experience developing Win32 applications, our first &lt;abbr title=&quot;Graphical User Interface&quot;&gt;GUI&lt;/abbr&gt; application will be created for it. Here we&amp;#039;ll catalog a bunch of resources required to finish the Windows version of our application.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Windows Porting&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;windows_porting&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:8,&amp;quot;range&amp;quot;:&amp;quot;5776-6163&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit9&quot; id=&quot;tray_icon&quot;&gt;Tray Icon&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
Our application will live most of its life as a simple tray icon (also known as the system tray or notification area), guaranteeing that the server is running and providing quick access to some of the application&amp;#039;s functionality. Here are some resources to help us implement this feature:
&lt;/p&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;a href=&quot;https://learn.microsoft.com/en-us/windows/win32/shell/notification-area&quot; class=&quot;urlextern&quot; title=&quot;https://learn.microsoft.com/en-us/windows/win32/shell/notification-area&quot; rel=&quot;ugc nofollow&quot;&gt;MSDN: Notifications and the Notification Area&lt;/a&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;a href=&quot;https://www.codeproject.com/Articles/18783/Example-of-a-SysTray-App-in-Win32&quot; class=&quot;urlextern&quot; title=&quot;https://www.codeproject.com/Articles/18783/Example-of-a-SysTray-App-in-Win32&quot; rel=&quot;ugc nofollow&quot;&gt;CodeProject: Example of a SysTray App in Win32&lt;/a&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;a href=&quot;https://codingmisadventures.wordpress.com/2009/02/20/creating-a-system-tray-icon-using-visual-c-and-win32/&quot; class=&quot;urlextern&quot; title=&quot;https://codingmisadventures.wordpress.com/2009/02/20/creating-a-system-tray-icon-using-visual-c-and-win32/&quot; rel=&quot;ugc nofollow&quot;&gt;Creating a System Tray Icon using Visual C++ and Win32&lt;/a&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Tray Icon&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;tray_icon&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:9,&amp;quot;range&amp;quot;:&amp;quot;6164-&amp;quot;} --&gt;</description>
    </item>
    <item rdf:about="http://wiki.nathancampos.me/doku.php?id=devnotes:macos">
        <dc:format>text/html</dc:format>
        <dc:date>2024-07-14T13:56:12+00:00</dc:date>
        <dc:creator>Anonymous (anonymous@undisclosed.example.com)</dc:creator>
        <title>macos</title>
        <link>http://wiki.nathancampos.me/doku.php?id=devnotes:macos</link>
        <description>
&lt;h1 class=&quot;sectionedit1&quot; id=&quot;mac_os_x_development_notes&quot;&gt;Mac OS X Development Notes&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;p&gt;
Recently I&amp;#039;ve finally started learning how to develop applications for Mac &lt;abbr title=&quot;Operating System&quot;&gt;OS&lt;/abbr&gt; X, or macOS as Apple likes to call it these days. I want to get a good idea of how Cocoa applications actually work, so I&amp;#039;m learning Objective-C before diving into &lt;a href=&quot;https://www.swift.org/&quot; class=&quot;urlextern&quot; title=&quot;https://www.swift.org/&quot; rel=&quot;ugc nofollow&quot;&gt;Swift&lt;/a&gt;. I&amp;#039;m basing my learning heavily on the book &lt;a href=&quot;https://www.oreilly.com/library/view/cocoa-programming-for/9780132902199/&quot; class=&quot;urlextern&quot; title=&quot;https://www.oreilly.com/library/view/cocoa-programming-for/9780132902199/&quot; rel=&quot;ugc nofollow&quot;&gt;Cocoa Programming for Mac OS X&lt;/a&gt;.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Mac OS X Development Notes&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;mac_os_x_development_notes&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:1,&amp;quot;range&amp;quot;:&amp;quot;1-472&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit2&quot; id=&quot;common_design_features&quot;&gt;Common Design Features&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
As the years passed, many common design patterns in &lt;abbr title=&quot;Operating System&quot;&gt;OS&lt;/abbr&gt; X applications started emerging, this should provide resources on how to use them.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Common Design Features&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;common_design_features&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:2,&amp;quot;range&amp;quot;:&amp;quot;473-647&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit3&quot; id=&quot;nstableview_with_-_buttons&quot;&gt;NSTableView with +/- buttons&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
&lt;img src=&quot;http://wiki.nathancampos.me/lib/exe/fetch.php?media=devnotes:nstableview-plus-minus-toolbar.png&quot; class=&quot;medialeft&quot; align=&quot;left&quot; loading=&quot;lazy&quot; title=&quot;Example of NSTableView with +/- buttons&quot; alt=&quot;Example of NSTableView with +/- buttons&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;
Many applications in &lt;abbr title=&quot;Operating System&quot;&gt;OS&lt;/abbr&gt; X have an &lt;code&gt;NSTableView&lt;/code&gt; with +/- buttons in a toolbar at its bottom. This provides a sleek design solution to a problem: How to I provide users a way to add new items to a list? With this approach you just let the user click the + button and a new entry is created and ready to be edited.
&lt;/p&gt;

&lt;p&gt;
The way to create this element is by utilizing the &lt;code&gt;NSSegmentedControl&lt;/code&gt; component. A great tutorial on how to do this is available on StackOverflow: &lt;a href=&quot;https://stackoverflow.com/questions/22586313/nstableview-with-buttons-like-in-system-preferences-using-only-interface-bui&quot; class=&quot;urlextern&quot; title=&quot;https://stackoverflow.com/questions/22586313/nstableview-with-buttons-like-in-system-preferences-using-only-interface-bui&quot; rel=&quot;ugc nofollow&quot;&gt;NSTableView with +/- buttons like in System Preferences using only Interface Builder&lt;/a&gt;.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;NSTableView with +\/- buttons&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;nstableview_with_-_buttons&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:3,&amp;quot;range&amp;quot;:&amp;quot;648-1466&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit4&quot; id=&quot;references&quot;&gt;References&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
Here is a collection of great resources on old Mac &lt;abbr title=&quot;Operating System&quot;&gt;OS&lt;/abbr&gt; X programming:
&lt;/p&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;a href=&quot;https://forums.macrumors.com/threads/developing-for-tiger-and-leopard-powerpc-a-devlog.2383838/&quot; class=&quot;urlextern&quot; title=&quot;https://forums.macrumors.com/threads/developing-for-tiger-and-leopard-powerpc-a-devlog.2383838/&quot; rel=&quot;ugc nofollow&quot;&gt;Developing for Tiger and Leopard / PowerPC (a devlog)&lt;/a&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;References&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;references&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:4,&amp;quot;range&amp;quot;:&amp;quot;1467-&amp;quot;} --&gt;</description>
    </item>
    <item rdf:about="http://wiki.nathancampos.me/doku.php?id=devnotes:msvc-porting">
        <dc:format>text/html</dc:format>
        <dc:date>2026-02-01T16:49:55+00:00</dc:date>
        <dc:creator>Anonymous (anonymous@undisclosed.example.com)</dc:creator>
        <title>msvc-porting</title>
        <link>http://wiki.nathancampos.me/doku.php?id=devnotes:msvc-porting</link>
        <description>
&lt;h1 class=&quot;sectionedit1&quot; id=&quot;porting_to_microsoft_visual_c&quot;&gt;Porting to Microsoft Visual C++&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;p&gt;
Microsoft&amp;#039;s compiler is filled with weird quirks and was literally &lt;a href=&quot;https://stackoverflow.com/questions/48615184/does-visual-studio-2017-fully-support-c99&quot; class=&quot;urlextern&quot; title=&quot;https://stackoverflow.com/questions/48615184/does-visual-studio-2017-fully-support-c99&quot; rel=&quot;ugc nofollow&quot;&gt;not C99-compliant until 2019&lt;/a&gt;, which means it is quite difficult to port software meant for a more standards-compliant compiler to it. This page means to compile everything that we may want or need to know in order to port our code to this awful compiler.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Porting to Microsoft Visual C++&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;porting_to_microsoft_visual_c&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:1,&amp;quot;range&amp;quot;:&amp;quot;1-461&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit2&quot; id=&quot;installing_on_modern_systems&quot;&gt;Installing on Modern Systems&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
Since Visual Studio 6.0 is extremely old it&amp;#039;s expected that you may encounter some roadblocks when trying to install it on more modern systems. If you&amp;#039;re on Windows XP or earlier you don&amp;#039;t have to do anything, simply install as usual and everything should work out-of-the-box.
&lt;/p&gt;

&lt;p&gt;
If you are on Windows Vista or 7, as per &lt;a href=&quot;https://www.itwriting.com/blog/167-visual-studio-6-on-vista.html&quot; class=&quot;urlextern&quot; title=&quot;https://www.itwriting.com/blog/167-visual-studio-6-on-vista.html&quot; rel=&quot;ugc nofollow&quot;&gt;this blog post&lt;/a&gt;, you should deselect the &lt;code&gt;Tools | OLE/COM Object Viewer&lt;/code&gt; when installing, otherwise the installation will fail with an “RegCreateKey failed for \Interface\OLEViewerIViewerCLSID. Access is denied” error. Now if you are on Windows 8, 10 or later you should &lt;a href=&quot;https://www.codeproject.com/Articles/1191047/Install-Visual-Studio-6-0-on-Windows-10&quot; class=&quot;urlextern&quot; title=&quot;https://www.codeproject.com/Articles/1191047/Install-Visual-Studio-6-0-on-Windows-10&quot; rel=&quot;ugc nofollow&quot;&gt;follow these instructions&lt;/a&gt; and at the time can only install Visual Basic 6, no Visual C++ 6 yet.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Installing on Modern Systems&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;installing_on_modern_systems&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:2,&amp;quot;range&amp;quot;:&amp;quot;462-1349&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit3&quot; id=&quot;unicode&quot;&gt;Unicode&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
The most dreaded aspect of programming for Windows… Having to use UTF-16 for Unicode is just awful, but sadly it&amp;#039;s what was available at the time that Microsoft needed strings that could represent characters from all over the world. This horrible decision in the past means that today where we live in a more civilized, UTF-8 society, we have to be constantly performing conversions between &lt;code&gt;MBCS&lt;/code&gt; and &lt;code&gt;WCHAR&lt;/code&gt; when programming for Windows, this can be easily done with a couple of helper functions since Microsoft&amp;#039;s &lt;abbr title=&quot;Application Programming Interface&quot;&gt;API&lt;/abbr&gt; for this is absolutely awful:
&lt;/p&gt;
&lt;pre class=&quot;code c&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt;/**
 * Converts a UTF-8 multibyte string into an UTF-16 wide-character string.
 * @warning This function allocates memory that must be free&#039;d by you!
 *
 * @param str UTF-8 string to be converted.
 *
 * @return UTF-16 wide-character converted string or NULL if an error occurred.
 */&lt;/span&gt;
&lt;span class=&quot;kw4&quot;&gt;wchar_t&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;*&lt;/span&gt;utf16_mbstowcs&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;*&lt;/span&gt;str&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
	&lt;span class=&quot;kw4&quot;&gt;wchar_t&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;*&lt;/span&gt;wstr&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;co2&quot;&gt;#ifdef _WIN32&lt;/span&gt;
	&lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt; nLen&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
	&lt;span class=&quot;coMULTI&quot;&gt;/* Get required buffer size and allocate some memory for it. */&lt;/span&gt;
	wstr &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; NULL&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
	nLen &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; MultiByteToWideChar&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;GL_CODEPAGE&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; str&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; NULL&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;nLen &lt;span class=&quot;sy0&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
		&lt;span class=&quot;kw1&quot;&gt;goto&lt;/span&gt; failure&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
	wstr &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;wchar_t&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;a href=&quot;http://www.opengroup.org/onlinepubs/009695399/functions/malloc.html&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;malloc&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;nLen &lt;span class=&quot;sy0&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;sizeof&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;wchar_t&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;wstr &lt;span class=&quot;sy0&quot;&gt;==&lt;/span&gt; NULL&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
		&lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; NULL&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
	&lt;span class=&quot;coMULTI&quot;&gt;/* Perform the conversion. */&lt;/span&gt;
	nLen &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; MultiByteToWideChar&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;GL_CODEPAGE&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; str&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; wstr&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; nLen&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;nLen &lt;span class=&quot;sy0&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
failure&lt;span class=&quot;sy0&quot;&gt;:&lt;/span&gt;
		MessageBox&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;NULL&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; _T&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&amp;quot;Failed to convert UTF-8 string to UTF-16.&amp;quot;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;
			_T&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&amp;quot;String Conversion Failure&amp;quot;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; MB_ICONERROR &lt;span class=&quot;sy0&quot;&gt;|&lt;/span&gt; MB_OK&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;wstr&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
			&lt;a href=&quot;http://www.opengroup.org/onlinepubs/009695399/functions/free.html&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;free&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;wstr&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
		&lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; NULL&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&quot;co2&quot;&gt;#else&lt;/span&gt;
	&lt;span class=&quot;kw4&quot;&gt;size_t&lt;/span&gt; len&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
	&lt;span class=&quot;coMULTI&quot;&gt;/* Allocate some memory for our converted string. */&lt;/span&gt;
	len &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; mbstowcs&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;NULL&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; str&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
	wstr &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;wchar_t&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;a href=&quot;http://www.opengroup.org/onlinepubs/009695399/functions/malloc.html&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;malloc&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;len &lt;span class=&quot;sy0&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;sizeof&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;wchar_t&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;wstr &lt;span class=&quot;sy0&quot;&gt;==&lt;/span&gt; NULL&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
		&lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; NULL&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
	&lt;span class=&quot;coMULTI&quot;&gt;/* Perform the string conversion. */&lt;/span&gt;
	len &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; mbstowcs&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;wstr&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; str&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; len&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;len &lt;span class=&quot;sy0&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;size_t&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
		&lt;a href=&quot;http://www.opengroup.org/onlinepubs/009695399/functions/free.html&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;free&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;wstr&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; NULL&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&quot;co2&quot;&gt;#endif /* _WIN32 */&lt;/span&gt;
&amp;nbsp;
	&lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; wstr&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;coMULTI&quot;&gt;/**
 * Converts a UTF-16 wide-character string into a UTF-8 multibyte string.
 * @warning This function allocates memory that must be free&#039;d by you!
 *
 * @param wstr UTF-16 string to be converted.
 *
 * @return UTF-8 multibyte converted string or NULL if an error occurred.
 */&lt;/span&gt;
&lt;span class=&quot;kw4&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;*&lt;/span&gt;utf16_wcstombs&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;wchar_t&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;*&lt;/span&gt;wstr&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
	&lt;span class=&quot;kw4&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;*&lt;/span&gt;str&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;co2&quot;&gt;#ifdef _WIN32&lt;/span&gt;
	&lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt; nLen&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
	&lt;span class=&quot;coMULTI&quot;&gt;/* Get required buffer size and allocate some memory for it. */&lt;/span&gt;
	nLen &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; WideCharToMultiByte&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;GL_CODEPAGE&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; wstr&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; NULL&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; NULL&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; NULL&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;nLen &lt;span class=&quot;sy0&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
		&lt;span class=&quot;kw1&quot;&gt;goto&lt;/span&gt; failure&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
	str &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;a href=&quot;http://www.opengroup.org/onlinepubs/009695399/functions/malloc.html&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;malloc&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;nLen &lt;span class=&quot;sy0&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;sizeof&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;char&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;str &lt;span class=&quot;sy0&quot;&gt;==&lt;/span&gt; NULL&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
		&lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; NULL&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
	&lt;span class=&quot;coMULTI&quot;&gt;/* Perform the conversion. */&lt;/span&gt;
	nLen &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; WideCharToMultiByte&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;GL_CODEPAGE&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; wstr&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; str&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; nLen&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; NULL&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;
							   NULL&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;nLen &lt;span class=&quot;sy0&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
failure&lt;span class=&quot;sy0&quot;&gt;:&lt;/span&gt;
		MessageBox&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;NULL&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; _T&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&amp;quot;Failed to convert UTF-16 string to UTF-8.&amp;quot;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;
			_T&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&amp;quot;String Conversion Failure&amp;quot;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; MB_ICONERROR &lt;span class=&quot;sy0&quot;&gt;|&lt;/span&gt; MB_OK&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
		&lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; NULL&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&quot;co2&quot;&gt;#else&lt;/span&gt;
	&lt;span class=&quot;kw4&quot;&gt;size_t&lt;/span&gt; len&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
	&lt;span class=&quot;coMULTI&quot;&gt;/* Allocate some memory for our converted string. */&lt;/span&gt;
	len &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; wcstombs&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;NULL&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; wstr&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
	str &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;a href=&quot;http://www.opengroup.org/onlinepubs/009695399/functions/malloc.html&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;malloc&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;len &lt;span class=&quot;sy0&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;sizeof&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;char&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;str &lt;span class=&quot;sy0&quot;&gt;==&lt;/span&gt; NULL&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
		&lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; NULL&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
	&lt;span class=&quot;coMULTI&quot;&gt;/* Perform the string conversion. */&lt;/span&gt;
	len &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; wcstombs&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;str&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; wstr&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; len&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;len &lt;span class=&quot;sy0&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;size_t&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
		&lt;a href=&quot;http://www.opengroup.org/onlinepubs/009695399/functions/free.html&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;free&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;str&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; NULL&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&quot;co2&quot;&gt;#endif /* _WIN32 */&lt;/span&gt;
&amp;nbsp;
	&lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; str&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Unicode&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;unicode&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:3,&amp;quot;range&amp;quot;:&amp;quot;1350-4489&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit4&quot; id=&quot;setting_up_a_project&quot;&gt;Setting up a Project&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
Also by default if you&amp;#039;re using an old compiler like Visual C++ 6 you need to manually set up the project to use Unicode and be compatible with more modern versions of Windows. In order to do this you simply have to follow the following steps:
&lt;/p&gt;
&lt;ol&gt;
&lt;li class=&quot;level1 node&quot;&gt;&lt;div class=&quot;li&quot;&gt; Define the &lt;code&gt;UNICODE&lt;/code&gt; and &lt;code&gt;_UNICODE&lt;/code&gt; preprocessor symbols:&lt;/div&gt;
&lt;ol&gt;
&lt;li class=&quot;level2&quot;&gt;&lt;div class=&quot;li&quot;&gt; Select &lt;strong&gt;Project→Settings&lt;/strong&gt;.&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level2&quot;&gt;&lt;div class=&quot;li&quot;&gt; Click the &lt;strong&gt;C/C++&lt;/strong&gt; tab.&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level2&quot;&gt;&lt;div class=&quot;li&quot;&gt; Add the following symbols to the &lt;strong&gt;Preprocessor definitions&lt;/strong&gt; text box: &lt;code&gt;UNICODE&lt;/code&gt;,&lt;code&gt;_UNICODE&lt;/code&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li class=&quot;level1 node&quot;&gt;&lt;div class=&quot;li&quot;&gt; Choose the entry point for Unicode:&lt;/div&gt;
&lt;ol&gt;
&lt;li class=&quot;level2&quot;&gt;&lt;div class=&quot;li&quot;&gt; While still in the &lt;strong&gt;Project Settings&lt;/strong&gt; dialog box, click the &lt;strong&gt;Link&lt;/strong&gt; tab.&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level2&quot;&gt;&lt;div class=&quot;li&quot;&gt; From the &lt;strong&gt;Category&lt;/strong&gt; drop-down list, select &lt;strong&gt;Output&lt;/strong&gt;.&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level2 node&quot;&gt;&lt;div class=&quot;li&quot;&gt; In the &lt;strong&gt;Entry-point symbol&lt;/strong&gt; field, type the appropriate entry point for Unicode:&lt;/div&gt;
&lt;ol&gt;
&lt;li class=&quot;level3&quot;&gt;&lt;div class=&quot;li&quot;&gt; For a &lt;abbr title=&quot;Graphical User Interface&quot;&gt;GUI&lt;/abbr&gt; Unicode application, the entry point is &lt;code&gt;wWinMainCRTStartup&lt;/code&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level3&quot;&gt;&lt;div class=&quot;li&quot;&gt; For a console application, the entry point is &lt;code&gt;wmainCRTStartup&lt;/code&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li class=&quot;level2&quot;&gt;&lt;div class=&quot;li&quot;&gt; Click &lt;strong&gt;OK&lt;/strong&gt;.&lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li class=&quot;level1 node&quot;&gt;&lt;div class=&quot;li&quot;&gt; Set the debugger to display Unicode strings:&lt;/div&gt;
&lt;ol&gt;
&lt;li class=&quot;level2&quot;&gt;&lt;div class=&quot;li&quot;&gt; Select &lt;strong&gt;Tools→Options&lt;/strong&gt;.&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level2&quot;&gt;&lt;div class=&quot;li&quot;&gt; Click the &lt;strong&gt;Debug&lt;/strong&gt; tab.&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level2&quot;&gt;&lt;div class=&quot;li&quot;&gt; Make sure the &lt;strong&gt;Display unicode strings&lt;/strong&gt; check box is checked.&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level2&quot;&gt;&lt;div class=&quot;li&quot;&gt; Click &lt;strong&gt;OK&lt;/strong&gt;.&lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Setting up a Project&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;setting_up_a_project&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:1,&amp;quot;secid&amp;quot;:4,&amp;quot;range&amp;quot;:&amp;quot;4490-5655&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit5&quot; id=&quot;special_folders&quot;&gt;Special Folders&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
Sometimes we want to have access to “special folders” like the Desktop, My Documents, AppData, just to name a few. Most of these have environment variables associated with them, but expanding environment variables in a program seems very bad, thankfully Microsoft provides a couple of interesting functions for us to use in order to fetch these paths.
&lt;/p&gt;

&lt;p&gt;
If we are targeting Windows 95+ (with the Internet Explorer upgrade) we must use the &lt;code&gt;&lt;a href=&quot;https://learn.microsoft.com/en-us/windows/win32/api/shlobj_core/nf-shlobj_core-shgetspecialfolderpathw&quot; class=&quot;urlextern&quot; title=&quot;https://learn.microsoft.com/en-us/windows/win32/api/shlobj_core/nf-shlobj_core-shgetspecialfolderpathw&quot; rel=&quot;ugc nofollow&quot;&gt;SHGetSpecialFolderPath&lt;/a&gt;&lt;/code&gt; function. If we are targeting Windows 2000+, or can install a redistributable, the recommendation is to use &lt;code&gt;&lt;a href=&quot;https://learn.microsoft.com/en-us/windows/win32/api/shlobj_core/nf-shlobj_core-shgetfolderlocation&quot; class=&quot;urlextern&quot; title=&quot;https://learn.microsoft.com/en-us/windows/win32/api/shlobj_core/nf-shlobj_core-shgetfolderlocation&quot; rel=&quot;ugc nofollow&quot;&gt;SHGetFolderLocation&lt;/a&gt;&lt;/code&gt; since the previous function call has been deprecated in this version. If we are targeting Windows Vista+ then we can use the even fancier &lt;code&gt;&lt;a href=&quot;https://learn.microsoft.com/en-us/windows/win32/api/shlobj_core/nf-shlobj_core-shgetknownfolderpath&quot; class=&quot;urlextern&quot; title=&quot;https://learn.microsoft.com/en-us/windows/win32/api/shlobj_core/nf-shlobj_core-shgetknownfolderpath&quot; rel=&quot;ugc nofollow&quot;&gt;SHGetKnownFolderPath&lt;/a&gt;&lt;/code&gt;.
&lt;/p&gt;

&lt;p&gt;
Here are some examples of how to use these functions:
&lt;/p&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;a href=&quot;https://stackoverflow.com/questions/54297253/is-there-a-new-replacement-for-shgetspecialfolderlocation/54297607#54297607&quot; class=&quot;urlextern&quot; title=&quot;https://stackoverflow.com/questions/54297253/is-there-a-new-replacement-for-shgetspecialfolderlocation/54297607#54297607&quot; rel=&quot;ugc nofollow&quot;&gt;Showing how to use all of the functions described above&lt;/a&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;a href=&quot;https://stackoverflow.com/questions/17933917/get-the-users-desktop-folder-using-windows-api/17935926#17935926&quot; class=&quot;urlextern&quot; title=&quot;https://stackoverflow.com/questions/17933917/get-the-users-desktop-folder-using-windows-api/17935926#17935926&quot; rel=&quot;ugc nofollow&quot;&gt;Specially focused on how to use SHGetSpecialFolderPath&lt;/a&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Special Folders&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;special_folders&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:1,&amp;quot;secid&amp;quot;:5,&amp;quot;range&amp;quot;:&amp;quot;5656-7174&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit6&quot; id=&quot;shims&quot;&gt;Shims&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
A collection of functions that may require a bit of shimming if you come from the saner world of POSIX:
&lt;/p&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;code&gt;&lt;a href=&quot;https://man7.org/linux/man-pages/man3/basename.3.html&quot; class=&quot;urlextern&quot; title=&quot;https://man7.org/linux/man-pages/man3/basename.3.html&quot; rel=&quot;ugc nofollow&quot;&gt;basename&lt;/a&gt;&lt;/code&gt; equivalent is &lt;code&gt;&lt;a href=&quot;https://learn.microsoft.com/en-us/windows/win32/api/shlwapi/nf-shlwapi-pathfindfilenamea&quot; class=&quot;urlextern&quot; title=&quot;https://learn.microsoft.com/en-us/windows/win32/api/shlwapi/nf-shlwapi-pathfindfilenamea&quot; rel=&quot;ugc nofollow&quot;&gt;PathFindFileName&lt;/a&gt;&lt;/code&gt; (requires linking against &lt;code&gt;shlwapi.lib&lt;/code&gt;)&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;code&gt;&lt;a href=&quot;https://man7.org/linux/man-pages/man3/snprintf.3p.html&quot; class=&quot;urlextern&quot; title=&quot;https://man7.org/linux/man-pages/man3/snprintf.3p.html&quot; rel=&quot;ugc nofollow&quot;&gt;snprintf&lt;/a&gt;&lt;/code&gt; equivalent is &lt;code&gt;&lt;a href=&quot;https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/snprintf-snprintf-snprintf-l-snwprintf-snwprintf-l?view=msvc-170&quot; class=&quot;urlextern&quot; title=&quot;https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/snprintf-snprintf-snprintf-l-snwprintf-snwprintf-l?view=msvc-170&quot; rel=&quot;ugc nofollow&quot;&gt;_snprintf&lt;/a&gt;&lt;/code&gt; (can&amp;#039;t count the number of bytes required for allocation)&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Shims&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;shims&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:1,&amp;quot;secid&amp;quot;:6,&amp;quot;range&amp;quot;:&amp;quot;7175-7842&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit7&quot; id=&quot;multithreading&quot;&gt;Multithreading&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
As usual, when it comes to Windows, multithreading is not as simple or easy as under a POSIX system. Microsoft made sure to implement their multithreading &lt;abbr title=&quot;Application Programming Interface&quot;&gt;API&lt;/abbr&gt; in multiple ways, one you can use the CRT, the other one you can&amp;#039;t. In any case, just ignore everything and follow these instructions.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Multithreading&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;multithreading&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:1,&amp;quot;secid&amp;quot;:7,&amp;quot;range&amp;quot;:&amp;quot;7843-8165&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit8&quot; id=&quot;mutexes&quot;&gt;Mutexes&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
One of the most used capabilities when dealing with parallel operations are mutexes, they allow us to ensure that resources that are shared between multiple processes can be safely guarded against race conditions. Windows has the concept of mutexes, but they are &lt;a href=&quot;https://stackoverflow.com/questions/800383/what-is-the-difference-between-mutex-and-critical-section/800422#800422&quot; class=&quot;urlextern&quot; title=&quot;https://stackoverflow.com/questions/800383/what-is-the-difference-between-mutex-and-critical-section/800422#800422&quot; rel=&quot;ugc nofollow&quot;&gt;extremely bad in terms of performance&lt;/a&gt;, although they have the “benefit” of working across processes. Usually what you want to use is the &lt;code&gt;CRITICAL_SECTION&lt;/code&gt; and its &lt;a href=&quot;https://learn.microsoft.com/en-us/windows/win32/sync/using-critical-section-objects&quot; class=&quot;urlextern&quot; title=&quot;https://learn.microsoft.com/en-us/windows/win32/sync/using-critical-section-objects&quot; rel=&quot;ugc nofollow&quot;&gt;associated functions&lt;/a&gt;, these resemble much of the pthreads &lt;abbr title=&quot;Application Programming Interface&quot;&gt;API&lt;/abbr&gt;, although with that characteristic Win32 &lt;abbr title=&quot;Application Programming Interface&quot;&gt;API&lt;/abbr&gt; flavor, and are very lightweight.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Mutexes&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;mutexes&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:1,&amp;quot;secid&amp;quot;:8,&amp;quot;range&amp;quot;:&amp;quot;8166-8962&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit9&quot; id=&quot;windows_ce&quot;&gt;Windows CE&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
As with everything in Win32 land the Windows CE implementation of multithreading suffered a lot, especially when dealing with PocketPCs and non-Handheld PCs. We can understand that this was done due to the lack of resources of such devices, but still. Here are some online resources on the subject:
&lt;/p&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;a href=&quot;https://sourceware.org/pub/pthreads-win32/pthreads-dll-2002-11-04/WinCE-PORT&quot; class=&quot;urlextern&quot; title=&quot;https://sourceware.org/pub/pthreads-win32/pthreads-dll-2002-11-04/WinCE-PORT&quot; rel=&quot;ugc nofollow&quot;&gt;WinCE pthreads port&lt;/a&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;a href=&quot;https://web.archive.org/web/20090624190949/http://world.std.com/~jmhart/wince.htm&quot; class=&quot;urlextern&quot; title=&quot;https://web.archive.org/web/20090624190949/http://world.std.com/~jmhart/wince.htm&quot; rel=&quot;ugc nofollow&quot;&gt;Notes on Windows CE&lt;/a&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Windows CE&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;windows_ce&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:1,&amp;quot;secid&amp;quot;:9,&amp;quot;range&amp;quot;:&amp;quot;8963-9500&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit10&quot; id=&quot;additional_resources&quot;&gt;Additional Resources&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
Here are some resources that were used as references to write this section. These will most likely go into greater detail on the subject and give you a greater understanding of the &lt;abbr title=&quot;Application Programming Interface&quot;&gt;API&lt;/abbr&gt; instead of just providing a reference.
&lt;/p&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;a href=&quot;https://learn.microsoft.com/en-us/cpp/parallel/multithreading-with-c-and-win32?view=msvc-170&quot; class=&quot;urlextern&quot; title=&quot;https://learn.microsoft.com/en-us/cpp/parallel/multithreading-with-c-and-win32?view=msvc-170&quot; rel=&quot;ugc nofollow&quot;&gt;MSDN: Multithreading with C and Win32&lt;/a&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;a href=&quot;https://learn.microsoft.com/en-us/cpp/parallel/sample-multithread-c-program?view=msvc-170&quot; class=&quot;urlextern&quot; title=&quot;https://learn.microsoft.com/en-us/cpp/parallel/sample-multithread-c-program?view=msvc-170&quot; rel=&quot;ugc nofollow&quot;&gt;MSDN: Sample Multithread C Program&lt;/a&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;a href=&quot;https://community.intel.com/t5/Intel-Moderncode-for-Parallel/Why-Pthreads-are-better-than-Win32-threads/td-p/990131&quot; class=&quot;urlextern&quot; title=&quot;https://community.intel.com/t5/Intel-Moderncode-for-Parallel/Why-Pthreads-are-better-than-Win32-threads/td-p/990131&quot; rel=&quot;ugc nofollow&quot;&gt;Why Pthreads are better than Win32 threads&lt;/a&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;a href=&quot;https://stackoverflow.com/questions/331536/windows-threading-beginthread-vs-beginthreadex-vs-createthread-c&quot; class=&quot;urlextern&quot; title=&quot;https://stackoverflow.com/questions/331536/windows-threading-beginthread-vs-beginthreadex-vs-createthread-c&quot; rel=&quot;ugc nofollow&quot;&gt;Windows threading: _beginthread vs _beginthreadex vs CreateThread&lt;/a&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;a href=&quot;https://locklessinc.com/articles/pthreads_on_windows/&quot; class=&quot;urlextern&quot; title=&quot;https://locklessinc.com/articles/pthreads_on_windows/&quot; rel=&quot;ugc nofollow&quot;&gt;Pthreads on Microsoft Windows&lt;/a&gt; (probably the best resource on the subject of multithreading under Windows)&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Additional Resources&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;additional_resources&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:1,&amp;quot;secid&amp;quot;:10,&amp;quot;range&amp;quot;:&amp;quot;9501-10547&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit11&quot; id=&quot;windows_server_2003_platform_sdk&quot;&gt;Windows Server 2003 Platform SDK&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
If you want to have proper compatibility with every single 32-bit Intel-based Windows release ever made since Windows 95 you are required to use Microsoft&amp;#039;s Visual C++ 6, which is a whole can of worms, but it is what you need to do in order to have full backward compatibility. Something that alleviates a bit of the pain of using this toolchain is the Windows Server 2003 Platform SDK, which can be downloaded using the &lt;a href=&quot;https://social.msdn.microsoft.com/Forums/windowsapps/en-US/e1147034-9b0b-4494-a5bc-6dfebb6b7eb1/download-and-install-microsoft-platform-sdk-febuary-2003-last-version-with-vc6-support?forum=windowssdk&quot; class=&quot;urlextern&quot; title=&quot;https://social.msdn.microsoft.com/Forums/windowsapps/en-US/e1147034-9b0b-4494-a5bc-6dfebb6b7eb1/download-and-install-microsoft-platform-sdk-febuary-2003-last-version-with-vc6-support?forum=windowssdk&quot; rel=&quot;ugc nofollow&quot;&gt;following instructions&lt;/a&gt;.
&lt;/p&gt;

&lt;p&gt;
You may need to install each SDK individually from the &lt;code&gt;setup&lt;/code&gt; folder instead of running &lt;code&gt;setup.exe&lt;/code&gt;, since this may cause issues if you&amp;#039;re running a more modern version of Internet Explorer.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Windows Server 2003 Platform SDK&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;windows_server_2003_platform_sdk&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:1,&amp;quot;secid&amp;quot;:11,&amp;quot;range&amp;quot;:&amp;quot;10548-11440&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit12&quot; id=&quot;sockets_and_network_programming&quot;&gt;Sockets and Network Programming&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
Porting an application from the standard in UNIX land Berkley sockets to WinSock might be a bit of a nightmare, depending on the architecture of the project. If your application was developed with portability in mind, even going as far as wrapping every single socket function, you can more easily port your code to Winsock, but you may still run into problems.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Sockets and Network Programming&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;sockets_and_network_programming&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:1,&amp;quot;secid&amp;quot;:12,&amp;quot;range&amp;quot;:&amp;quot;11441-11848&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit13&quot; id=&quot;missing_functions_and_types&quot;&gt;Missing Functions and Types&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
As soon as we try to compile any piece of code that was made for a more standardized sockets implementation, one thing will become extremely apparent: You&amp;#039;ll be missing a lot of stuff. In order to get a saner environment for socket programming under Windows, it&amp;#039;s required to install the &lt;a href=&quot;#windows_server_2003_platform_sdk&quot; title=&quot;devnotes:msvc-porting ↵&quot; class=&quot;wikilink1&quot;&gt;Windows Server 2003 Platform SDK&lt;/a&gt;.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Missing Functions and Types&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;missing_functions_and_types&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:1,&amp;quot;secid&amp;quot;:13,&amp;quot;range&amp;quot;:&amp;quot;11849-12248&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit14&quot; id=&quot;headers&quot;&gt;Headers&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
According to Microsoft&amp;#039;s documentation, you should not include &lt;code&gt;windows.h&lt;/code&gt; when you are using Winsock2 since it tries to include the old Winsock 1.1 stuff, which generates loads of conflicts with the redefinitions in the Winsock2 headers. In order to get around this, since your application or libraries might be including &lt;code&gt;windows.h&lt;/code&gt; you should define globally (in the project&amp;#039;s settings) the &lt;code&gt;WIN32_LEAN_AND_MEAN&lt;/code&gt; preprocessor definition.
&lt;/p&gt;

&lt;p&gt;
A usual set of includes for Winsock2 should look like this:
&lt;/p&gt;
&lt;pre class=&quot;code c&quot;&gt;&lt;span class=&quot;co2&quot;&gt;#define WIN32_LEAN_AND_MEAN&lt;/span&gt;
&lt;span class=&quot;co2&quot;&gt;#include &amp;lt;windows.h&amp;gt;&lt;/span&gt;
&lt;span class=&quot;co2&quot;&gt;#include &amp;lt;winsock2.h&amp;gt;&lt;/span&gt;
&lt;span class=&quot;co2&quot;&gt;#include &amp;lt;ws2tcpip.h&amp;gt;&lt;/span&gt;
&lt;span class=&quot;co2&quot;&gt;#include &amp;lt;wspiapi.h&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Headers&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;headers&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:1,&amp;quot;secid&amp;quot;:14,&amp;quot;range&amp;quot;:&amp;quot;12249-12908&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit15&quot; id=&quot;setsockopt_parameters&quot;&gt;setsockopt() Parameters&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
Another difference from other platforms is that the &lt;code&gt;setsockopt()&lt;/code&gt; function takes its &lt;code&gt;optval&lt;/code&gt; parameter as a &lt;code&gt;const char *&lt;/code&gt; instead of the more common &lt;code&gt;void *&lt;/code&gt;, requiring your parameters to be redefined just for Windows.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;setsockopt() Parameters&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;setsockopt_parameters&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:2,&amp;quot;secid&amp;quot;:15,&amp;quot;range&amp;quot;:&amp;quot;12909-13174&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit16&quot; id=&quot;error_handling&quot;&gt;Error Handling&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
Whenever you must catch errors from resulting socket interactions, where under a POSIX system you simply check the contents of the &lt;code&gt;errno&lt;/code&gt; variable after a function returns &lt;code&gt;-1&lt;/code&gt;, under Winsock2 you must instead check if the function returned &lt;code&gt;SOCKET_ERROR&lt;/code&gt;, and then call and store the return value of &lt;code&gt;WSAGetLastError()&lt;/code&gt; and compare against Microsoft&amp;#039;s WSA-prefixed error code definitions. This is all described in Microsoft&amp;#039;s &lt;a href=&quot;https://learn.microsoft.com/en-us/windows/win32/winsock/return-values-on-function-failure-2&quot; class=&quot;urlextern&quot; title=&quot;https://learn.microsoft.com/en-us/windows/win32/winsock/return-values-on-function-failure-2&quot; rel=&quot;ugc nofollow&quot;&gt;Return Values on Function Failure&lt;/a&gt; MSDN article. For more in-depth information on the subject of how to deal with Winsock2 errors, read MSDN articles &lt;a href=&quot;https://learn.microsoft.com/en-us/windows/win32/winsock/handling-winsock-errors&quot; class=&quot;urlextern&quot; title=&quot;https://learn.microsoft.com/en-us/windows/win32/winsock/handling-winsock-errors&quot; rel=&quot;ugc nofollow&quot;&gt;Handling Winsock Errors&lt;/a&gt; and &lt;a href=&quot;https://learn.microsoft.com/en-us/windows/win32/winsock/error-codes-errno-h-errno-and-wsagetlasterror-2&quot; class=&quot;urlextern&quot; title=&quot;https://learn.microsoft.com/en-us/windows/win32/winsock/error-codes-errno-h-errno-and-wsagetlasterror-2&quot; rel=&quot;ugc nofollow&quot;&gt;Error Codes - errno, h_errno and WSAGetLastError&lt;/a&gt;.
&lt;/p&gt;

&lt;p&gt;
Another interesting quirk of Winsock error codes seems to be the fact that it doesn&amp;#039;t have a &lt;code&gt;EAGAIN&lt;/code&gt; definition, and that for situations where &lt;code&gt;EAGAIN&lt;/code&gt; would&amp;#039;ve been used &lt;a href=&quot;https://lists.gnu.org/archive/html/bug-gnulib/2008-10/msg00068.html&quot; class=&quot;urlextern&quot; title=&quot;https://lists.gnu.org/archive/html/bug-gnulib/2008-10/msg00068.html&quot; rel=&quot;ugc nofollow&quot;&gt;it&amp;#039;s suggested&lt;/a&gt; to instead use &lt;code&gt;WSAEWOULDBLOCK&lt;/code&gt;.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Error Handling&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;error_handling&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:2,&amp;quot;secid&amp;quot;:16,&amp;quot;range&amp;quot;:&amp;quot;13175-14451&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit17&quot; id=&quot;so_rcvtimeo_timeout_argument&quot;&gt;SO_RCVTIMEO Timeout Argument&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
Under all UNIX variants, the &lt;code&gt;SO_RCVTIMEO&lt;/code&gt; option for &lt;code&gt;setsockopt()&lt;/code&gt; receives a pointer to a &lt;code&gt;struct timeval&lt;/code&gt;. This is not the case on Windows, and it does create a whole bunch of weird bugs, since the code technically compiles and may even run depending on the value pointed by the structure in question. Every single time I&amp;#039;m porting a socket application from POSIX to WinSock2, I want to pull my hair out whenever I encounter this bug.
&lt;/p&gt;

&lt;p&gt;
Under WinSock2, the &lt;code&gt;SO_RCVTIMEO&lt;/code&gt; option &lt;a href=&quot;https://stackoverflow.com/a/9859300/126353&quot; class=&quot;urlextern&quot; title=&quot;https://stackoverflow.com/a/9859300/126353&quot; rel=&quot;ugc nofollow&quot;&gt;requires the timeout value to be passed as a &amp;#039;&amp;#039;DWORD&amp;#039;&amp;#039;&lt;/a&gt;, with the number of milliseconds to timeout, casted to a &lt;code&gt;const char *&lt;/code&gt;.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;SO_RCVTIMEO Timeout Argument&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;so_rcvtimeo_timeout_argument&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:2,&amp;quot;secid&amp;quot;:17,&amp;quot;range&amp;quot;:&amp;quot;14452-15158&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit18&quot; id=&quot;miscellaneous&quot;&gt;Miscellaneous&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
Beware that whenever you&amp;#039;re dealing with &lt;code&gt;in_addr_t&lt;/code&gt;, it isn&amp;#039;t defined and you must instead define it as &lt;code&gt;unsigned long&lt;/code&gt;.
&lt;/p&gt;

&lt;p&gt;
Yet another interesting quirk was discovered by us, where if you have a large TCP packet that gets split at the source and must be reassembled at the client, a call to &lt;code&gt;recv()&lt;/code&gt; will fail with a &lt;code&gt;WSAEFAULT&lt;/code&gt; even though the buffer is large enough to hold the received information, requiring us to always set the &lt;code&gt;MSG_WAITALL&lt;/code&gt; flag. This hasn&amp;#039;t been thoroughly tested, and we were unable to pinpoint with great accuracy the real cause of the issue, but at least for now, we&amp;#039;ve attributed it to the partial packet thing. Keep in mind that older versions of the compiler don&amp;#039;t have this flag available, so you&amp;#039;ll need to implement this functionality manually by looping through the &lt;code&gt;recv()&lt;/code&gt; call until all expected bytes have been received.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Miscellaneous&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;miscellaneous&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:2,&amp;quot;secid&amp;quot;:18,&amp;quot;range&amp;quot;:&amp;quot;15159-16055&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit19&quot; id=&quot;linking&quot;&gt;Linking&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
At the end of your journey, if all the compilation errors have gone away, be sure to link against the &lt;code&gt;ws2_32.lib&lt;/code&gt; library to avoid the dreaded linker errors.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Linking&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;linking&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:2,&amp;quot;secid&amp;quot;:19,&amp;quot;range&amp;quot;:&amp;quot;16056-16236&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit20&quot; id=&quot;initialization_and_cleanup&quot;&gt;Initialization and Cleanup&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
Most importantly, after all this, make sure to add the following code to your &lt;code&gt;main()&lt;/code&gt; application entry point:
&lt;/p&gt;
&lt;pre class=&quot;code c&quot;&gt;&lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt; main&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt; argc&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;**&lt;/span&gt;argv&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
&lt;span class=&quot;co2&quot;&gt;#ifdef _WIN32&lt;/span&gt;
	WORD wVersionRequested&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
	WSADATA wsaData&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt; ret&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;co2&quot;&gt;#endif /* _WIN32 */&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;co2&quot;&gt;#ifdef _WIN32&lt;/span&gt;
	&lt;span class=&quot;coMULTI&quot;&gt;/* Initialize the Winsock stuff. */&lt;/span&gt;
	wVersionRequested &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; MAKEWORD&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;ret &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; WSAStartup&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;wVersionRequested&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;&amp;amp;&lt;/span&gt;wsaData&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
		&lt;a href=&quot;http://www.opengroup.org/onlinepubs/009695399/functions/printf.html&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;printf&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&amp;quot;WSAStartup failed with error %d&lt;span class=&quot;es1&quot;&gt;\n&lt;/span&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; ret&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&quot;co2&quot;&gt;#endif /* _WIN32 */&lt;/span&gt;
&amp;nbsp;
	&lt;span class=&quot;coMULTI&quot;&gt;/* Perform everything in your application. */&lt;/span&gt;
&amp;nbsp;
	&lt;span class=&quot;coMULTI&quot;&gt;/**
	 * If your application exits prematurely, make sure that WSACleanup() gets
	 * called beforehand.
	 */&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;co2&quot;&gt;#ifdef _WIN32&lt;/span&gt;
	&lt;span class=&quot;coMULTI&quot;&gt;/* Clean up the Winsock stuff. */&lt;/span&gt;
	WSACleanup&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;co2&quot;&gt;#endif /* _WIN32 */&lt;/span&gt;
&amp;nbsp;
	&lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; ret&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Initialization and Cleanup&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;initialization_and_cleanup&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:2,&amp;quot;secid&amp;quot;:20,&amp;quot;range&amp;quot;:&amp;quot;16237-17024&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit21&quot; id=&quot;references&quot;&gt;References&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
Here are the references that were most likely consulted in order to find all of these issues in real-world codebases and catalog them here:
&lt;/p&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;a href=&quot;https://learn.microsoft.com/en-us/windows/win32/winsock/porting-socket-applications-to-winsock&quot; class=&quot;urlextern&quot; title=&quot;https://learn.microsoft.com/en-us/windows/win32/winsock/porting-socket-applications-to-winsock&quot; rel=&quot;ugc nofollow&quot;&gt;MSDN: Porting Socket Applications to Winsock&lt;/a&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;a href=&quot;https://handsonnetworkprogramming.com/articles/differences-windows-winsock-linux-unix-bsd-sockets-compatibility/&quot; class=&quot;urlextern&quot; title=&quot;https://handsonnetworkprogramming.com/articles/differences-windows-winsock-linux-unix-bsd-sockets-compatibility/&quot; rel=&quot;ugc nofollow&quot;&gt;Differences Between Socket Programming on Windows, Linux, and macOS&lt;/a&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;a href=&quot;https://umlautllama.com/w2/?action=view&amp;amp;page=Porting%20BSD%20Sockets%20to%20Winsock&quot; class=&quot;urlextern&quot; title=&quot;https://umlautllama.com/w2/?action=view&amp;amp;page=Porting%20BSD%20Sockets%20to%20Winsock&quot; rel=&quot;ugc nofollow&quot;&gt;Porting BSD Sockets to Winsock&lt;/a&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;References&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;references&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:3,&amp;quot;secid&amp;quot;:21,&amp;quot;range&amp;quot;:&amp;quot;17025-17648&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit22&quot; id=&quot;getting_a_console&quot;&gt;Getting a Console&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
You&amp;#039;ll quickly realize that if your target is a &lt;abbr title=&quot;Graphical User Interface&quot;&gt;GUI&lt;/abbr&gt; Win32 application you won&amp;#039;t have access to a console to print stuff out and quickly debug things. This is due to the way that Windows is architected and its subsystems work. In order to get a console you&amp;#039;ll either need to allocate one and redirect every stream to that one or create an EDIT control anywhere on your application, create a pipe, redirect the streams to your pipe, then read from it and append the text to your EDIT field. Either way here are some resources to get you started:
&lt;/p&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;a href=&quot;https://stackoverflow.com/a/57241985/126353&quot; class=&quot;urlextern&quot; title=&quot;https://stackoverflow.com/a/57241985/126353&quot; rel=&quot;ugc nofollow&quot;&gt;Allocating a console and getting stdout redirected - StackOverflow&lt;/a&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;a href=&quot;https://stackoverflow.com/a/573762/126353&quot; class=&quot;urlextern&quot; title=&quot;https://stackoverflow.com/a/573762/126353&quot; rel=&quot;ugc nofollow&quot;&gt;Piping the output to an EDIT control - StackOverflow&lt;/a&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Getting a Console&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;getting_a_console&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:3,&amp;quot;secid&amp;quot;:22,&amp;quot;range&amp;quot;:&amp;quot;17649-18447&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit23&quot; id=&quot;finding_memory_leaks&quot;&gt;Finding Memory Leaks&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
Finding memory leaks is always a though thing. &lt;a href=&quot;https://stackoverflow.com/a/60626788&quot; class=&quot;urlextern&quot; title=&quot;https://stackoverflow.com/a/60626788&quot; rel=&quot;ugc nofollow&quot;&gt;Visual Studio has some tools&lt;/a&gt; which can be extremely useful when trying to find leaks, but you can also do it programmatically on every debug run of your application:
&lt;/p&gt;
&lt;pre class=&quot;code c&quot;&gt;&lt;span class=&quot;co2&quot;&gt;#ifdef DEBUG&lt;/span&gt;
&lt;span class=&quot;co2&quot;&gt;#include &amp;lt;crtdbg.h&amp;gt;&lt;/span&gt;
&lt;span class=&quot;co2&quot;&gt;#endif // DEBUG&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt; _tmain&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt; argc&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; TCHAR&lt;span class=&quot;sy0&quot;&gt;*&lt;/span&gt; argv&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
&lt;span class=&quot;co2&quot;&gt;#ifdef DEBUG&lt;/span&gt;
	&lt;span class=&quot;co1&quot;&gt;// Initialize memory leak detection.&lt;/span&gt;
	_CrtMemState snapBegin&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
	_CrtMemState snapEnd&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
	_CrtMemState snapDiff&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
	_CrtMemCheckpoint&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;&amp;amp;&lt;/span&gt;snapBegin&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;co2&quot;&gt;#endif // DEBUG&lt;/span&gt;
&amp;nbsp;
	&lt;span class=&quot;co1&quot;&gt;// TODO: Do stuff here...&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;co2&quot;&gt;#ifdef DEBUG&lt;/span&gt;
	&lt;span class=&quot;co1&quot;&gt;// Detect memory leaks.&lt;/span&gt;
	_CrtMemCheckpoint&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;&amp;amp;&lt;/span&gt;snapEnd&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;_CrtMemDifference&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;&amp;amp;&lt;/span&gt;snapDiff&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;&amp;amp;&lt;/span&gt;snapBegin&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;&amp;amp;&lt;/span&gt;snapEnd&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
		OutputDebugString&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;_T&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&amp;quot;MEMORY LEAKS DETECTED&lt;span class=&quot;es1&quot;&gt;\r&lt;/span&gt;&lt;span class=&quot;es1&quot;&gt;\n&lt;/span&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
		OutputDebugString&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;L&lt;span class=&quot;st0&quot;&gt;&amp;quot;----------- _CrtMemDumpStatistics ---------&lt;span class=&quot;es1&quot;&gt;\r&lt;/span&gt;&lt;span class=&quot;es1&quot;&gt;\n&lt;/span&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
		_CrtMemDumpStatistics&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;&amp;amp;&lt;/span&gt;snapDiff&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
		OutputDebugString&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;L&lt;span class=&quot;st0&quot;&gt;&amp;quot;----------- _CrtMemDumpAllObjectsSince ---------&lt;span class=&quot;es1&quot;&gt;\r&lt;/span&gt;&lt;span class=&quot;es1&quot;&gt;\n&lt;/span&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
		_CrtMemDumpAllObjectsSince&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;&amp;amp;&lt;/span&gt;snapBegin&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
		OutputDebugString&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;L&lt;span class=&quot;st0&quot;&gt;&amp;quot;----------- _CrtDumpMemoryLeaks ---------&lt;span class=&quot;es1&quot;&gt;\r&lt;/span&gt;&lt;span class=&quot;es1&quot;&gt;\n&lt;/span&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
		_CrtDumpMemoryLeaks&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
		OutputDebugString&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;_T&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&amp;quot;No memory leaks detected. Congratulations!&lt;span class=&quot;es1&quot;&gt;\r&lt;/span&gt;&lt;span class=&quot;es1&quot;&gt;\n&lt;/span&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&quot;co2&quot;&gt;#endif // DEBUG&lt;/span&gt;
&amp;nbsp;
	&lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Finding Memory Leaks&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;finding_memory_leaks&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:3,&amp;quot;secid&amp;quot;:23,&amp;quot;range&amp;quot;:&amp;quot;18448-19666&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit24&quot; id=&quot;guidelines&quot;&gt;Guidelines&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
When developing applications for a given operating system it&amp;#039;s always good to know about its standards, defaults, and most importantly its interface guidelines in order to make your application look “native”. In order to get a comprehensive look at Microsoft&amp;#039;s recommendations of what Windows applications should look and feel you must check out their &lt;a href=&quot;https://learn.microsoft.com/en-us/windows/win32/uxguide/vis-layout&quot; class=&quot;urlextern&quot; title=&quot;https://learn.microsoft.com/en-us/windows/win32/uxguide/vis-layout&quot; rel=&quot;ugc nofollow&quot;&gt;Layout Guidelines&lt;/a&gt;, most importantly since Visual Studio provides no help in this area, you should check out their &lt;strong&gt;Recommended sizing and spacing&lt;/strong&gt; section which describes in detail how to size and space controls in Win32 applications.
&lt;/p&gt;

&lt;p&gt;
It&amp;#039;s not only important to follow Microsoft&amp;#039;s guidelines for the UI aspects of the application, but also for the developer side of the application, using naming conventions that are accepted by other Windows developers. Here are a collection of articles related to this topic:
&lt;/p&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;a href=&quot;https://learn.microsoft.com/en-us/windows/win32/stg/coding-style-conventions&quot; class=&quot;urlextern&quot; title=&quot;https://learn.microsoft.com/en-us/windows/win32/stg/coding-style-conventions&quot; rel=&quot;ugc nofollow&quot;&gt;Variable Naming&lt;/a&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;a href=&quot;https://learn.microsoft.com/en-us/cpp/mfc/tn020-id-naming-and-numbering-conventions?view=msvc-170&quot; class=&quot;urlextern&quot; title=&quot;https://learn.microsoft.com/en-us/cpp/mfc/tn020-id-naming-and-numbering-conventions?view=msvc-170&quot; rel=&quot;ugc nofollow&quot;&gt;Resource IDs and Numbering&lt;/a&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Guidelines&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;guidelines&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:4,&amp;quot;secid&amp;quot;:24,&amp;quot;range&amp;quot;:&amp;quot;19667-20864&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit25&quot; id=&quot;msc_ver&quot;&gt;_MSC_VER&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
Since Visual Studio is quite an old application with lots of versions and many changes along the years, one of the most important aspects that you need to know in order to develop a project that can be compiled in multiple versions of this platform is the &lt;code&gt;_MSC_VER&lt;/code&gt; constant that&amp;#039;s defined for every version of the application suite. &lt;a href=&quot;https://dev.to/yumetodo/list-of-mscver-and-mscfullver-8nd&quot; class=&quot;urlextern&quot; title=&quot;https://dev.to/yumetodo/list-of-mscver-and-mscfullver-8nd&quot; rel=&quot;ugc nofollow&quot;&gt;A comprehensive list of these definitions can be found here&lt;/a&gt;, but here are some of the most important ones for us:
&lt;/p&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; Visual Studio 2012: &lt;code&gt;1700&lt;/code&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; Visual Studio 2005: &lt;code&gt;1400&lt;/code&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; Visual C++ 6.0: &lt;code&gt;1200&lt;/code&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;_MSC_VER&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;msc_ver&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:4,&amp;quot;secid&amp;quot;:25,&amp;quot;range&amp;quot;:&amp;quot;20865-21496&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit26&quot; id=&quot;issues_with_stdinth_error_c2733&quot;&gt;Issues with stdint.h (Error C2733)&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
If you&amp;#039;re seeing things like &lt;code&gt;error C2733: second C linkage of overloaded function &amp;#039;wmemchr&amp;#039; not allowed&lt;/code&gt; when trying to compile an application under Visual C++ 6 using the official &lt;code&gt;stdint.h&lt;/code&gt; shim it means that you haven&amp;#039;t paid attention to the comments in the file itself:
&lt;/p&gt;
&lt;pre class=&quot;code c&quot;&gt;&lt;span class=&quot;co1&quot;&gt;// For Visual Studio 6 in C++ mode and for many Visual Studio versions when&lt;/span&gt;
&lt;span class=&quot;co1&quot;&gt;// compiling for ARM we should wrap &amp;lt;wchar.h&amp;gt; include with &#039;extern &amp;quot;C++&amp;quot; {}&#039;&lt;/span&gt;
&lt;span class=&quot;co1&quot;&gt;// or compiler give many errors like this:&lt;/span&gt;
&lt;span class=&quot;co1&quot;&gt;//   error C2733: second C linkage of overloaded function &#039;wmemchr&#039; not allowed&lt;/span&gt;
&lt;span class=&quot;co2&quot;&gt;#ifdef __cplusplus&lt;/span&gt;
&lt;span class=&quot;kw2&quot;&gt;extern&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;C&amp;quot;&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
&lt;span class=&quot;co2&quot;&gt;#endif&lt;/span&gt;
&lt;span class=&quot;co2&quot;&gt;#  include &amp;lt;wchar.h&amp;gt;&lt;/span&gt;
&lt;span class=&quot;co2&quot;&gt;#ifdef __cplusplus&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&quot;co2&quot;&gt;#endif&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;
Changing from &lt;code&gt;extern “C”&lt;/code&gt; to &lt;code&gt;extern “C++”&lt;/code&gt; should fix all your issues.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Issues with stdint.h (Error C2733)&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;issues_with_stdinth_error_c2733&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:4,&amp;quot;secid&amp;quot;:26,&amp;quot;range&amp;quot;:&amp;quot;21497-22284&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit27&quot; id=&quot;registry_functions&quot;&gt;Registry Functions&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
It&amp;#039;s extremely important to note that, only under eMbedded Visual C++ 3, all registry-related functions such as &lt;code&gt;RegOpenKeyEx&lt;/code&gt; and &lt;code&gt;RegQueryValueEx&lt;/code&gt; return &lt;code&gt;ERROR_INVALID_PARAMETER&lt;/code&gt; instead of &lt;code&gt;ERROR_INVALID_PARAMETER&lt;/code&gt; when a key hasn&amp;#039;t yet been created. Also the &lt;code&gt;lpdwDisposition&lt;/code&gt; parameter of &lt;code&gt;RegCreateKeyEx&lt;/code&gt; is mandatory under the same compiler, not including it will result in an Access Violation error.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Registry Functions&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;registry_functions&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:5,&amp;quot;secid&amp;quot;:27,&amp;quot;range&amp;quot;:&amp;quot;22285-22738&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit28&quot; id=&quot;image_lists&quot;&gt;Image Lists&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
&lt;a href=&quot;https://learn.microsoft.com/en-us/windows/win32/controls/image-lists&quot; class=&quot;urlextern&quot; title=&quot;https://learn.microsoft.com/en-us/windows/win32/controls/image-lists&quot; rel=&quot;ugc nofollow&quot;&gt;ImageLists&lt;/a&gt; are a crucial component from the CommonControls library. They allow us to add icons to our applications in a much easier manner and lets us associate indexes with them, but they do have some gotchas that are nice to know in order to take full advantage of them, specially when developing with multiple versions of Windows in mind.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Image Lists&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;image_lists&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:5,&amp;quot;secid&amp;quot;:28,&amp;quot;range&amp;quot;:&amp;quot;22739-23179&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit29&quot; id=&quot;system_metrics&quot;&gt;System Metrics&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
Most of the time when building ImageLists we want to use them for standardized icons throughout our application, these usually use the small and large metrics defined by the operating system. In order to get these we can use the &lt;code&gt;GetDeviceMetrics()&lt;/code&gt; function and ask for the &lt;code&gt;SM_CXSMICON&lt;/code&gt; and &lt;code&gt;SM_CYSMICON&lt;/code&gt; for small icons and &lt;code&gt;SM_CXICON&lt;/code&gt; and &lt;code&gt;SM_CYICON&lt;/code&gt; for large icons. The values returned by the function can be directly used to create an ImageList with &lt;code&gt;ImageList_Create()&lt;/code&gt;. To learn more about these metrics consult the &lt;a href=&quot;https://learn.microsoft.com/en-us/windows/win32/menurc/about-icons#icon-sizes&quot; class=&quot;urlextern&quot; title=&quot;https://learn.microsoft.com/en-us/windows/win32/menurc/about-icons#icon-sizes&quot; rel=&quot;ugc nofollow&quot;&gt;About icons page&lt;/a&gt; of the Microsoft documentation.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;System Metrics&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;system_metrics&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:5,&amp;quot;secid&amp;quot;:29,&amp;quot;range&amp;quot;:&amp;quot;23180-23874&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit30&quot; id=&quot;loadicon_in_windows_ce&quot;&gt;LoadIcon in Windows CE&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
When loading icons under Windows CE it&amp;#039;s very important to note that the &lt;code&gt;LoadIcon()&lt;/code&gt; function only loads icons of size &lt;code&gt;SM_CXICON&lt;/code&gt;, if you use these in other size contexts the icon will simply be clipped. As the documentation states:
&lt;/p&gt;
&lt;blockquote&gt;&lt;div class=&quot;no&quot;&gt;
 &lt;code&gt;LoadIcon&lt;/code&gt; can only load an icon whose size conforms to the &lt;code&gt;SM_CXICON&lt;/code&gt; and &lt;code&gt;SM_CYICON&lt;/code&gt; system metric values. Use the &lt;code&gt;LoadImage&lt;/code&gt; function to load icons of other sizes.&lt;/div&gt;&lt;/blockquote&gt;

&lt;p&gt;
Given this explanation we can substitute our uses of &lt;code&gt;LoadIcon()&lt;/code&gt; with the following to get a different resolution:
&lt;/p&gt;
&lt;pre class=&quot;code c&quot;&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;HICON&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;LoadImage&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;m_hInst&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; MAKEINTRESOURCE&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;IDI_ICONRES&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; IMAGE_ICON&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; SM_CXSMICON&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; SM_CXSMICON&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;
The issue now is that we need to keep the &lt;code&gt;HICON&lt;/code&gt; handles in a list somewhere so that we can call &lt;code&gt;DestroyIcon()&lt;/code&gt; on them when its time to dispose of them. This was done automatically when we used &lt;code&gt;LoadIcon()&lt;/code&gt;.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;LoadIcon in Windows CE&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;loadicon_in_windows_ce&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:5,&amp;quot;secid&amp;quot;:30,&amp;quot;range&amp;quot;:&amp;quot;23875-24780&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit31&quot; id=&quot;bit_depth&quot;&gt;Bit Depth&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
Throughout the many versions of Windows, specially in the XP and pre-XP days, it was common for computers to not be capable of rendering in 24-bit or 32-bit colors, so whenever we are creating ImageLists we have to take this into consideration. One easy cop out from this situation is instead of passing a specific bit depth for the &lt;code&gt;ImageList_Create()&lt;/code&gt; function we pass the &lt;code&gt;ILC_COLORDDB&lt;/code&gt; flag. There was &lt;a href=&quot;https://stackoverflow.com/questions/19016115/mfc-image-list-create-ilc-colorddb-messing-up-highlight&quot; class=&quot;urlextern&quot; title=&quot;https://stackoverflow.com/questions/19016115/mfc-image-list-create-ilc-colorddb-messing-up-highlight&quot; rel=&quot;ugc nofollow&quot;&gt;this interesting discussion&lt;/a&gt; on when to use this flag.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Bit Depth&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;bit_depth&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:6,&amp;quot;secid&amp;quot;:31,&amp;quot;range&amp;quot;:&amp;quot;24781-25371&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit32&quot; id=&quot;c_stl_for_embedded_visual_c&quot;&gt;C++ STL for eMbedded Visual C++&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
If you think you could have a sane standard library for C++ under Microsoft&amp;#039;s eMbedded Visual C++ you are completely wrong. For some reason they shipped it with one that was missing some bits and in some cases it was completely different from the published standard back in the day. You can get a much better and standards-compliant STL (based on SGI&amp;#039;s work) from &lt;a href=&quot;https://users.libero.it/g.govi/stlport_ce_en.html&quot; class=&quot;urlextern&quot; title=&quot;https://users.libero.it/g.govi/stlport_ce_en.html&quot; rel=&quot;ugc nofollow&quot;&gt;STL for eMbedded Visual C++&lt;/a&gt;. Also you should read the &lt;a href=&quot;https://users.libero.it/g.govi/info_ce_en.html&quot; class=&quot;urlextern&quot; title=&quot;https://users.libero.it/g.govi/info_ce_en.html&quot; rel=&quot;ugc nofollow&quot;&gt;additional information on limitations and usage&lt;/a&gt; to learn more about it.
&lt;/p&gt;

&lt;p&gt;
To install this we just have to decompress it either in the project&amp;#039;s folder or somewhere else, go to &lt;code&gt;Tools/Options…/Directories&lt;/code&gt; and add the folder where it was decompressed to the includes path for all targets.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;C++ STL for eMbedded Visual C++&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;c_stl_for_embedded_visual_c&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:6,&amp;quot;secid&amp;quot;:32,&amp;quot;range&amp;quot;:&amp;quot;25372-&amp;quot;} --&gt;</description>
    </item>
    <item rdf:about="http://wiki.nathancampos.me/doku.php?id=devnotes:netaddr">
        <dc:format>text/html</dc:format>
        <dc:date>2023-06-05T09:46:35+00:00</dc:date>
        <dc:creator>Anonymous (anonymous@undisclosed.example.com)</dc:creator>
        <title>netaddr</title>
        <link>http://wiki.nathancampos.me/doku.php?id=devnotes:netaddr</link>
        <description>
&lt;h1 class=&quot;sectionedit1&quot; id=&quot;network_addressing_programatically&quot;&gt;Network Addressing Programatically&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;p&gt;
Network addresses have always been a massive pain in the ass for programmers since the dawn of time, but it doesn&amp;#039;t necessarily have to be that way. Here you&amp;#039;ll find some interesting tips and tricks to get you up to speed on how to deal with them like a pro!
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Network Addressing Programatically&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;network_addressing_programatically&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:1,&amp;quot;range&amp;quot;:&amp;quot;1-310&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit2&quot; id=&quot;getting_network_interface_information&quot;&gt;Getting Network Interface Information&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
It&amp;#039;s very common to have to get information on the network interfaces of a device in order to get more information about the network or just to be capable of talking to all devices on all the networks that you may have available. This can be a bit tricky and might involve a lot of platform-dependent code since most of the functions surrounding network interfaces are not portable and are deeply tied to the operating system.
&lt;/p&gt;

&lt;p&gt;
According to &lt;a href=&quot;https://web.archive.org/web/20150514222449/http://code.google.com/p/openpgm/source/browse/trunk/openpgm/pgm/getifaddrs.c#1092&quot; class=&quot;urlextern&quot; title=&quot;https://web.archive.org/web/20150514222449/http://code.google.com/p/openpgm/source/browse/trunk/openpgm/pgm/getifaddrs.c#1092&quot; rel=&quot;ugc nofollow&quot;&gt;this very comprehensive piece of code&lt;/a&gt; there are four ways of fetching the network interfaces of a device, two involve system functions and the other two involve &lt;code&gt;ioctls&lt;/code&gt;:
&lt;/p&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;code&gt;&lt;a href=&quot;https://man7.org/linux/man-pages/man3/getifaddrs.3.html&quot; class=&quot;urlextern&quot; title=&quot;https://man7.org/linux/man-pages/man3/getifaddrs.3.html&quot; rel=&quot;ugc nofollow&quot;&gt;getifaddrs(3)&lt;/a&gt;&lt;/code&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;code&gt;&lt;a href=&quot;https://learn.microsoft.com/en-us/windows/win32/api/iphlpapi/nf-iphlpapi-getadaptersaddresses&quot; class=&quot;urlextern&quot; title=&quot;https://learn.microsoft.com/en-us/windows/win32/api/iphlpapi/nf-iphlpapi-getadaptersaddresses&quot; rel=&quot;ugc nofollow&quot;&gt;GetAdaptersAddresses&lt;/a&gt;&lt;/code&gt; (Win32)&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;code&gt;&lt;a href=&quot;https://linux.die.net/man/7/netdevice&quot; class=&quot;urlextern&quot; title=&quot;https://linux.die.net/man/7/netdevice&quot; rel=&quot;ugc nofollow&quot;&gt;SIOCGLIFCONF&lt;/a&gt;&lt;/code&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;code&gt;&lt;a href=&quot;https://linux.die.net/man/7/netdevice&quot; class=&quot;urlextern&quot; title=&quot;https://linux.die.net/man/7/netdevice&quot; rel=&quot;ugc nofollow&quot;&gt;SIOCGIFCONF&lt;/a&gt;&lt;/code&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Getting Network Interface Information&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;getting_network_interface_information&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:2,&amp;quot;range&amp;quot;:&amp;quot;311-1449&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit3&quot; id=&quot;broadcast_address&quot;&gt;Broadcast Address&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
The broadcast address of a network is essential when dealing with device discovery (unless you can use proper multicast), you can get away with using &lt;code&gt;INADDR_BROADCAST&lt;/code&gt;, but that&amp;#039;s very hacky and not recommended for devices that already have an IP address on the network. The correct way to broadcast a packet on a network is to get a list of all the network interfaces of the device and then get the broadcast address of each one of them.
&lt;/p&gt;

&lt;p&gt;
Here are a couple of ways that you can get the broadcast address of interfaces on various platforms:
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Broadcast Address&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;broadcast_address&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:3,&amp;quot;range&amp;quot;:&amp;quot;1450-2025&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit4&quot; id=&quot;using_ioctls&quot;&gt;Using ioctls&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
&lt;a href=&quot;https://gist.github.com/loderunner/ec7d4725daca39283606&quot; class=&quot;urlextern&quot; title=&quot;https://gist.github.com/loderunner/ec7d4725daca39283606&quot; rel=&quot;ugc nofollow&quot;&gt;This interesting bit of code&lt;/a&gt; shows how to use &lt;code&gt;ioctls&lt;/code&gt; under most UNIX operating systems to get a list of the interfaces and their respective broadcast addresses:
&lt;/p&gt;
&lt;dl class=&quot;file&quot;&gt;
&lt;dt&gt;&lt;a href=&quot;http://wiki.nathancampos.me/doku.php?do=export_code&amp;amp;id=devnotes:netaddr&amp;amp;codeblock=0&quot; title=&quot;Download Snippet&quot; class=&quot;mediafile mf_c&quot;&gt;getbroadaddr.c&lt;/a&gt;&lt;/dt&gt;
&lt;dd&gt;&lt;pre class=&quot;code file c&quot;&gt;&lt;span class=&quot;co2&quot;&gt;#include &amp;lt;net/if.h&amp;gt;&lt;/span&gt;
&lt;span class=&quot;co2&quot;&gt;#include &amp;lt;netdb.h&amp;gt;&lt;/span&gt;
&lt;span class=&quot;co2&quot;&gt;#include &amp;lt;stdio.h&amp;gt;&lt;/span&gt;
&lt;span class=&quot;co2&quot;&gt;#include &amp;lt;stdlib.h&amp;gt;&lt;/span&gt;
&lt;span class=&quot;co2&quot;&gt;#include &amp;lt;string.h&amp;gt;&lt;/span&gt;
&lt;span class=&quot;co2&quot;&gt;#include &amp;lt;sys/ioctl.h&amp;gt;&lt;/span&gt;
&lt;span class=&quot;co2&quot;&gt;#include &amp;lt;sys/socket.h&amp;gt;&lt;/span&gt;
&lt;span class=&quot;co2&quot;&gt;#include &amp;lt;sys/types.h&amp;gt;&lt;/span&gt;
&lt;span class=&quot;co2&quot;&gt;#include &amp;lt;unistd.h&amp;gt;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw4&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt; show_interface_broadaddr&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt; fd&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;*&lt;/span&gt;name&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
	&lt;span class=&quot;kw4&quot;&gt;struct&lt;/span&gt; ifreq ifreq&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kw4&quot;&gt;char&lt;/span&gt; host&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;128&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
	&lt;a href=&quot;http://www.opengroup.org/onlinepubs/009695399/functions/memset.html&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;memset&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;&amp;amp;&lt;/span&gt;ifreq&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;sizeof&lt;/span&gt; ifreq&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
	&lt;a href=&quot;http://www.opengroup.org/onlinepubs/009695399/functions/strncpy.html&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;strncpy&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;ifreq.&lt;span class=&quot;me1&quot;&gt;ifr_name&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; name&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; IFNAMSIZ&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
	&lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;ioctl&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;fd&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; SIOCGIFBRDADDR&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;&amp;amp;&lt;/span&gt;ifreq&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
		&lt;a href=&quot;http://www.opengroup.org/onlinepubs/009695399/functions/fprintf.html&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;fprintf&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;stderr&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;Could not find interface named %s&lt;span class=&quot;es1&quot;&gt;\n&lt;/span&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; name&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;coMULTI&quot;&gt;/* ignore */&lt;/span&gt;
	&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
	getnameinfo&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;&amp;amp;&lt;/span&gt;ifreq.&lt;span class=&quot;me1&quot;&gt;ifr_broadaddr&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;sizeof&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;ifreq.&lt;span class=&quot;me1&quot;&gt;ifr_broadaddr&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; host&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;sizeof&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;host&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; NI_NUMERICHOST&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
	&lt;a href=&quot;http://www.opengroup.org/onlinepubs/009695399/functions/printf.html&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;printf&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&amp;quot;%-24s%s&lt;span class=&quot;es1&quot;&gt;\n&lt;/span&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; name&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; host&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw4&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt; list_interfaces&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt; fd&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
	&lt;span class=&quot;kw4&quot;&gt;struct&lt;/span&gt; ifreq &lt;span class=&quot;sy0&quot;&gt;*&lt;/span&gt;ifreq&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kw4&quot;&gt;struct&lt;/span&gt; ifconf ifconf&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kw4&quot;&gt;char&lt;/span&gt; buf&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;16384&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kw4&quot;&gt;unsigned&lt;/span&gt; i&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kw4&quot;&gt;size_t&lt;/span&gt; len&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
	ifconf.&lt;span class=&quot;me1&quot;&gt;ifc_len&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;sizeof&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;buf&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
	ifconf.&lt;span class=&quot;me1&quot;&gt;ifc_buf&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; buf&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
	&lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;ioctl&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;fd&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; SIOCGIFCONF&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;&amp;amp;&lt;/span&gt;ifconf&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
		&lt;a href=&quot;http://www.opengroup.org/onlinepubs/009695399/functions/perror.html&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;perror&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&amp;quot;ioctl(SIOCGIFCONF)&amp;quot;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
		&lt;a href=&quot;http://www.opengroup.org/onlinepubs/009695399/functions/exit.html&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;exit&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;EXIT_FAILURE&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
	&lt;a href=&quot;http://www.opengroup.org/onlinepubs/009695399/functions/printf.html&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;printf&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&amp;quot;Listing all interfaces:&lt;span class=&quot;es1&quot;&gt;\n&lt;/span&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
	ifreq &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; ifconf.&lt;span class=&quot;me1&quot;&gt;ifc_req&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
	i &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kw1&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;i &lt;span class=&quot;sy0&quot;&gt;&amp;lt;&lt;/span&gt; ifconf.&lt;span class=&quot;me1&quot;&gt;ifc_len&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
&lt;span class=&quot;co2&quot;&gt;#ifndef linux&lt;/span&gt;
		len &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; IFNAMSIZ &lt;span class=&quot;sy0&quot;&gt;+&lt;/span&gt; ifreq&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;ifr_addr.&lt;span class=&quot;me1&quot;&gt;sa_len&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;co2&quot;&gt;#else&lt;/span&gt;
		len &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;sizeof&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;struct&lt;/span&gt; ifreq&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;co2&quot;&gt;#endif&lt;/span&gt;
&amp;nbsp;
		&lt;a href=&quot;http://www.opengroup.org/onlinepubs/009695399/functions/printf.html&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;printf&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&amp;quot;%s&lt;span class=&quot;es1&quot;&gt;\n&lt;/span&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; ifreq&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;ifr_name&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
		ifreq &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;struct&lt;/span&gt; ifreq &lt;span class=&quot;sy0&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;ifreq &lt;span class=&quot;sy0&quot;&gt;+&lt;/span&gt; len&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
		i &lt;span class=&quot;sy0&quot;&gt;+=&lt;/span&gt; len&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt; main&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt; argc&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;**&lt;/span&gt;argv&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
	&lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt; sock&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
	sock &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; socket&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;AF_INET&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; SOCK_DGRAM&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;sock &lt;span class=&quot;sy0&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
		&lt;a href=&quot;http://www.opengroup.org/onlinepubs/009695399/functions/perror.html&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;perror&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&amp;quot;socket()&amp;quot;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
		&lt;a href=&quot;http://www.opengroup.org/onlinepubs/009695399/functions/exit.html&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;exit&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;EXIT_FAILURE&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
	&lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;argc &lt;span class=&quot;sy0&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
		list_interfaces&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;sock&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;argc &lt;span class=&quot;sy0&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
		show_interface_broadaddr&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;sock&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; argv&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
	close&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;sock&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
	&lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; EXIT_SUCCESS&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;
&lt;/dd&gt;&lt;/dl&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Using ioctls&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;using_ioctls&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:4,&amp;quot;range&amp;quot;:&amp;quot;2026-&amp;quot;} --&gt;</description>
    </item>
    <item rdf:about="http://wiki.nathancampos.me/doku.php?id=devnotes:shortcircuit">
        <dc:format>text/html</dc:format>
        <dc:date>2024-07-14T14:03:14+00:00</dc:date>
        <dc:creator>Anonymous (anonymous@undisclosed.example.com)</dc:creator>
        <title>shortcircuit</title>
        <link>http://wiki.nathancampos.me/doku.php?id=devnotes:shortcircuit</link>
        <description>
&lt;h1 class=&quot;sectionedit1&quot; id=&quot;shortcircuit&quot;&gt;Shortcircuit&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;p&gt;
The development notes are to be used for reference while developing &lt;a href=&quot;https://github.com/nathanpc/Shortcircuit&quot; class=&quot;urlextern&quot; title=&quot;https://github.com/nathanpc/Shortcircuit&quot; rel=&quot;ugc nofollow&quot;&gt;Shortcircuit&lt;/a&gt;.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Shortcircuit&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;shortcircuit&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:1,&amp;quot;range&amp;quot;:&amp;quot;1-156&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit2&quot; id=&quot;concept_and_idea&quot;&gt;Concept and Idea&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
Create a simple small toolbar icon utility that’s simply a shortcut to the “Connect to Server…” option in macOS so that it&amp;#039;s simple to automatically mount our network shares on macOS.
&lt;/p&gt;

&lt;p&gt;
It&amp;#039;s also very important, since it&amp;#039;s a common feature on Windows and many organizations would love this, add the ability to automatically mount certain drives when the system boots.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Concept and Idea&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;concept_and_idea&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:2,&amp;quot;range&amp;quot;:&amp;quot;157-558&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit3&quot; id=&quot;resources&quot;&gt;Resources&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
Some resources gathered while researching what would be needed for the macOS application:
&lt;/p&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;a href=&quot;https://support.apple.com/guide/mac-help/servers-shared-computers-connect-mac-mchlp3015/14.0/mac/14.0&quot; class=&quot;urlextern&quot; title=&quot;https://support.apple.com/guide/mac-help/servers-shared-computers-connect-mac-mchlp3015/14.0/mac/14.0&quot; rel=&quot;ugc nofollow&quot;&gt;Servers and shared computers you can connect to on Mac - Apple Support&lt;/a&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;a href=&quot;https://developer.apple.com/design/human-interface-guidelines/the-menu-bar&quot; class=&quot;urlextern&quot; title=&quot;https://developer.apple.com/design/human-interface-guidelines/the-menu-bar&quot; rel=&quot;ugc nofollow&quot;&gt;The menu bar | Apple Developer Documentation&lt;/a&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;a href=&quot;https://developer.apple.com/documentation/SwiftUI/MenuBarExtra&quot; class=&quot;urlextern&quot; title=&quot;https://developer.apple.com/documentation/SwiftUI/MenuBarExtra&quot; rel=&quot;ugc nofollow&quot;&gt;MenuBarExtra | Apple Developer Documentation&lt;/a&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;a href=&quot;https://stackoverflow.com/questions/28100736/mount-smb-drive-in-xcode-using-cocoa-and-objective-c#28201386&quot; class=&quot;urlextern&quot; title=&quot;https://stackoverflow.com/questions/28100736/mount-smb-drive-in-xcode-using-cocoa-and-objective-c#28201386&quot; rel=&quot;ugc nofollow&quot;&gt;Mount SMB drive in Xcode using cocoa and objective-c - Stack Overflow&lt;/a&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Resources&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;resources&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:3,&amp;quot;range&amp;quot;:&amp;quot;559-1283&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit4&quot; id=&quot;mounting_network_shares_programatically&quot;&gt;Mounting network shares programatically&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
Whenever you search online for ways to mount a network share programatically on macOS you&amp;#039;ll inevitably find the &lt;code&gt;NetFSMountURLSync&lt;/code&gt; and &lt;code&gt;NetFSMountURLAsync&lt;/code&gt; functions that apparently are available if you include the &lt;code&gt;NetFS.framework&lt;/code&gt; to your project. Apple really wants to hide this framework from the world, since its documentation isn&amp;#039;t available anywhere online, and even when using the full offline docsets on Xcode 5.1 I only get changelogs and not the proper documentation.
&lt;/p&gt;

&lt;p&gt;
From what I was able to gather the &lt;code&gt;NetFS.framework&lt;/code&gt; &lt;a href=&quot;https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/OSX_Technology_Overview/SystemFrameworks/SystemFrameworks.html#:~:text=NetFS.framework,network%20file%20systems.&quot; class=&quot;urlextern&quot; title=&quot;https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/OSX_Technology_Overview/SystemFrameworks/SystemFrameworks.html#:~:text=NetFS.framework,network%20file%20systems.&quot; rel=&quot;ugc nofollow&quot;&gt;was introduced in OS X 10.6&lt;/a&gt;, and according to the chapter “NetFS Changes” in the “&lt;abbr title=&quot;Operating System&quot;&gt;OS&lt;/abbr&gt; X 10.8 &lt;abbr title=&quot;Application Programming Interface&quot;&gt;API&lt;/abbr&gt; Diffs” collection, the &lt;code&gt;NetFSMountURLSync&lt;/code&gt; and &lt;code&gt;NetFSMountURLAsync&lt;/code&gt; functions were only introduced in &lt;abbr title=&quot;Operating System&quot;&gt;OS&lt;/abbr&gt; X 10.8.
&lt;/p&gt;

&lt;p&gt;
This presents a problem, since our application is supposed to work all the way down to the &lt;abbr title=&quot;Operating System&quot;&gt;OS&lt;/abbr&gt; X 10.4 release on PowerPC (to at least target the Powerbook G4s), these APIs won&amp;#039;t be available to us, so we can use them in builds for newer operating systems, but we need to ensure that we have an alternative for older platforms. It&amp;#039;s important to have both approaches since using the newer APIs will most likely give us a bit more compatibility with ultra modern versions of the &lt;abbr title=&quot;Operating System&quot;&gt;OS&lt;/abbr&gt;.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Mounting network shares programatically&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;mounting_network_shares_programatically&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:4,&amp;quot;range&amp;quot;:&amp;quot;1284-2767&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit5&quot; id=&quot;mount_2&quot;&gt;mount(2)&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
POSIX will always come to our rescue! We can use the low-level &lt;code&gt;&lt;a href=&quot;https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/mount.2.html&quot; class=&quot;urlextern&quot; title=&quot;https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/mount.2.html&quot; rel=&quot;ugc nofollow&quot;&gt;mount(2)&lt;/a&gt;&lt;/code&gt; function (and its &lt;code&gt;umount(2)&lt;/code&gt; counterpart) to perform the same operation. In fact this will allow us an even greater level of flexibility since we can let the user specify custom mount options. According to &lt;a href=&quot;https://www.linuxquestions.org/questions/programming-9/how-to-use-mount-function-from-c-920210/#post4558141&quot; class=&quot;urlextern&quot; title=&quot;https://www.linuxquestions.org/questions/programming-9/how-to-use-mount-function-from-c-920210/#post4558141&quot; rel=&quot;ugc nofollow&quot;&gt;this post&lt;/a&gt; the &lt;code&gt;data&lt;/code&gt; argument is simply a string with the mount options as used in the &lt;code&gt;-o&lt;/code&gt; parameter when using the command line interface to &lt;code&gt;mount&lt;/code&gt;.
&lt;/p&gt;

&lt;p&gt;
Given the flexibility afforded with this approach, we should reconsider the idea of using this only for older systems. I&amp;#039;m sure many users will find it useful to have access to these advanced options. We may even be able to create a nice UI for setting some of the more common options.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;mount(2)&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;mount_2&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:5,&amp;quot;range&amp;quot;:&amp;quot;2768-3746&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit6&quot; id=&quot;help&quot;&gt;Help&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
I&amp;#039;ve been stuck trying to implement this for way too long. Apparently instead of implementing &lt;code&gt;mount(2)&lt;/code&gt; in a sane way we are supposed to pass complex structures and the mount point should be part of that structure, not a parameter in the function call. I&amp;#039;ve asked about this on &lt;a href=&quot;https://stackoverflow.com/questions/78744919/unable-to-mount-nfs-share-using-mount2-on-macos&quot; class=&quot;urlextern&quot; title=&quot;https://stackoverflow.com/questions/78744919/unable-to-mount-nfs-share-using-mount2-on-macos&quot; rel=&quot;ugc nofollow&quot;&gt;StackOverflow&lt;/a&gt; and on &lt;a href=&quot;https://developer.apple.com/forums/thread/759514&quot; class=&quot;urlextern&quot; title=&quot;https://developer.apple.com/forums/thread/759514&quot; rel=&quot;ugc nofollow&quot;&gt;Apple&amp;#039;s Developer Forums&lt;/a&gt;. Let&amp;#039;s hope someone is able to help me out.
&lt;/p&gt;

&lt;p&gt;
In the mean time I&amp;#039;ve been able to find these two questions about using &lt;code&gt;mount(2)&lt;/code&gt; and its syntax, although they are both trying to mount an HFS file system:
&lt;/p&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;a href=&quot;https://stackoverflow.com/questions/3478500/using-mount2-function-in-c&quot; class=&quot;urlextern&quot; title=&quot;https://stackoverflow.com/questions/3478500/using-mount2-function-in-c&quot; rel=&quot;ugc nofollow&quot;&gt;using mount(2) function in C - StackOverflow&lt;/a&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;a href=&quot;https://discussions.apple.com/thread/2542778?sortBy=best&quot; class=&quot;urlextern&quot; title=&quot;https://discussions.apple.com/thread/2542778?sortBy=best&quot; rel=&quot;ugc nofollow&quot;&gt;Mount(2) function c - Apple Forums&lt;/a&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;
I&amp;#039;ve also located an interesting structure in under &lt;code&gt;/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/nfs/nfs.h&lt;/code&gt;:
&lt;/p&gt;
&lt;pre class=&quot;code c&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt;/*
 * Old-style arguments to mount NFS
 */&lt;/span&gt;
&lt;span class=&quot;co2&quot;&gt;#define NFS_ARGSVERSION 6               /* change when nfs_args changes */&lt;/span&gt;
&lt;span class=&quot;kw4&quot;&gt;struct&lt;/span&gt; nfs_args &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt;             version&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;        &lt;span class=&quot;coMULTI&quot;&gt;/* args structure version number */&lt;/span&gt;
        &lt;span class=&quot;kw4&quot;&gt;struct&lt;/span&gt; sockaddr &lt;span class=&quot;sy0&quot;&gt;*&lt;/span&gt;addr&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;          &lt;span class=&quot;coMULTI&quot;&gt;/* file server address */&lt;/span&gt;
        &lt;span class=&quot;kw4&quot;&gt;uint8_t&lt;/span&gt;         addrlen&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;        &lt;span class=&quot;coMULTI&quot;&gt;/* length of address */&lt;/span&gt;
        &lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt;             sotype&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;         &lt;span class=&quot;coMULTI&quot;&gt;/* Socket type */&lt;/span&gt;
        &lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt;             proto&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;          &lt;span class=&quot;coMULTI&quot;&gt;/* and Protocol */&lt;/span&gt;
        u_char          &lt;span class=&quot;sy0&quot;&gt;*&lt;/span&gt;fh&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;            &lt;span class=&quot;coMULTI&quot;&gt;/* File handle to be mounted */&lt;/span&gt;
        &lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt;             fhsize&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;         &lt;span class=&quot;coMULTI&quot;&gt;/* Size, in bytes, of fh */&lt;/span&gt;
        &lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt;             flags&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;          &lt;span class=&quot;coMULTI&quot;&gt;/* flags */&lt;/span&gt;
        &lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt;             wsize&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;          &lt;span class=&quot;coMULTI&quot;&gt;/* write size in bytes */&lt;/span&gt;
        &lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt;             rsize&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;          &lt;span class=&quot;coMULTI&quot;&gt;/* read size in bytes */&lt;/span&gt;
        &lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt;             readdirsize&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;    &lt;span class=&quot;coMULTI&quot;&gt;/* readdir size in bytes */&lt;/span&gt;
        &lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt;             timeo&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;          &lt;span class=&quot;coMULTI&quot;&gt;/* initial timeout in .1 secs */&lt;/span&gt;
        &lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt;             retrans&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;        &lt;span class=&quot;coMULTI&quot;&gt;/* times to retry send */&lt;/span&gt;
        &lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt;             maxgrouplist&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;   &lt;span class=&quot;coMULTI&quot;&gt;/* Max. size of group list */&lt;/span&gt;
        &lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt;             readahead&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;      &lt;span class=&quot;coMULTI&quot;&gt;/* # of blocks to readahead */&lt;/span&gt;
        &lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt;             leaseterm&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;      &lt;span class=&quot;coMULTI&quot;&gt;/* obsolete: Term (sec) of lease */&lt;/span&gt;
        &lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt;             deadthresh&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;     &lt;span class=&quot;coMULTI&quot;&gt;/* obsolete: Retrans threshold */&lt;/span&gt;
        &lt;span class=&quot;kw4&quot;&gt;char&lt;/span&gt;            &lt;span class=&quot;sy0&quot;&gt;*&lt;/span&gt;hostname&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;      &lt;span class=&quot;coMULTI&quot;&gt;/* server&#039;s name */&lt;/span&gt;
        &lt;span class=&quot;coMULTI&quot;&gt;/* NFS_ARGSVERSION 3 ends here */&lt;/span&gt;
        &lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt;             acregmin&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;       &lt;span class=&quot;coMULTI&quot;&gt;/* reg file min attr cache timeout */&lt;/span&gt;
        &lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt;             acregmax&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;       &lt;span class=&quot;coMULTI&quot;&gt;/* reg file max attr cache timeout */&lt;/span&gt;
        &lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt;             acdirmin&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;       &lt;span class=&quot;coMULTI&quot;&gt;/* dir min attr cache timeout */&lt;/span&gt;
        &lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt;             acdirmax&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;       &lt;span class=&quot;coMULTI&quot;&gt;/* dir max attr cache timeout */&lt;/span&gt;
        &lt;span class=&quot;coMULTI&quot;&gt;/* NFS_ARGSVERSION 4 ends here */&lt;/span&gt;
        &lt;span class=&quot;kw4&quot;&gt;uint32_t&lt;/span&gt;        auth&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;           &lt;span class=&quot;coMULTI&quot;&gt;/* security mechanism flavor */&lt;/span&gt;
        &lt;span class=&quot;coMULTI&quot;&gt;/* NFS_ARGSVERSION 5 ends here */&lt;/span&gt;
        &lt;span class=&quot;kw4&quot;&gt;uint32_t&lt;/span&gt;        deadtimeout&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;    &lt;span class=&quot;coMULTI&quot;&gt;/* secs until unresponsive mount considered dead */&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;
Although I haven&amp;#039;t been able to use this in a way that works.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Help&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;help&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:6,&amp;quot;range&amp;quot;:&amp;quot;3747-6861&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit7&quot; id=&quot;windows_version&quot;&gt;Windows version&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
It would be interesting to also offer a Windows version to help everyone that wants to simply map a network share to a drive letter without messing with Windows&amp;#039; super complicated and buggy wizards. It will also make mounting NFS shares a breeze for the first time.
&lt;/p&gt;

&lt;p&gt;
Simply create the same UI in a .NET application, since NFS is only supported on Windows 8+, that hides itself on the system tray and allows the same functionality as its macOS counterpart. If we are interested in pain we can always write the application using the Win32 &lt;abbr title=&quot;Application Programming Interface&quot;&gt;API&lt;/abbr&gt; and target all the way down to Windows 95 and only support NFS mounts on supporting OSes.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Windows version&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;windows_version&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:1,&amp;quot;secid&amp;quot;:7,&amp;quot;range&amp;quot;:&amp;quot;6862-7522&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit8&quot; id=&quot;resources1&quot;&gt;Resources&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
Some research on what would be needed to pull this off on Windows:
&lt;/p&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;a href=&quot;https://learn.microsoft.com/en-us/windows/win32/netshare/network-share-functions&quot; class=&quot;urlextern&quot; title=&quot;https://learn.microsoft.com/en-us/windows/win32/netshare/network-share-functions&quot; rel=&quot;ugc nofollow&quot;&gt;Network Share Functions - Win32 apps | Microsoft Learn&lt;/a&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;a href=&quot;https://learn.microsoft.com/en-us/windows/win32/api/winnetwk/nf-winnetwk-wnetaddconnection2a&quot; class=&quot;urlextern&quot; title=&quot;https://learn.microsoft.com/en-us/windows/win32/api/winnetwk/nf-winnetwk-wnetaddconnection2a&quot; rel=&quot;ugc nofollow&quot;&gt;WNetAddConnection2A function (winnetwk.h) - Win32 apps | Microsoft Learn&lt;/a&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;a href=&quot;https://stackoverflow.com/questions/43173970/map-network-drive-programmatically-in-c-sharp-on-windows-10&quot; class=&quot;urlextern&quot; title=&quot;https://stackoverflow.com/questions/43173970/map-network-drive-programmatically-in-c-sharp-on-windows-10&quot; rel=&quot;ugc nofollow&quot;&gt;Map network drive programmatically in C# on Windows 10 - Stack Overflow&lt;/a&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;a href=&quot;https://www.codeproject.com/Articles/90143/Mapping-Network-Drive-using-C&quot; class=&quot;urlextern&quot; title=&quot;https://www.codeproject.com/Articles/90143/Mapping-Network-Drive-using-C&quot; rel=&quot;ugc nofollow&quot;&gt;Mapping Network Drive using C#&lt;/a&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Resources&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;resources1&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:1,&amp;quot;secid&amp;quot;:8,&amp;quot;range&amp;quot;:&amp;quot;7523-&amp;quot;} --&gt;</description>
    </item>
    <item rdf:about="http://wiki.nathancampos.me/doku.php?id=devnotes:unity">
        <dc:format>text/html</dc:format>
        <dc:date>2023-05-20T20:02:44+00:00</dc:date>
        <dc:creator>Anonymous (anonymous@undisclosed.example.com)</dc:creator>
        <title>unity</title>
        <link>http://wiki.nathancampos.me/doku.php?id=devnotes:unity</link>
        <description>
&lt;h1 class=&quot;sectionedit1&quot; id=&quot;unity_game_engine&quot;&gt;Unity Game Engine&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Unity Game Engine&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;unity_game_engine&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:1,&amp;quot;range&amp;quot;:&amp;quot;1-33&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit2&quot; id=&quot;input_system&quot;&gt;Input System&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
&lt;a href=&quot;https://gamedevbeginner.com/input-in-unity-made-easy-complete-guide-to-the-new-system/&quot; class=&quot;urlextern&quot; title=&quot;https://gamedevbeginner.com/input-in-unity-made-easy-complete-guide-to-the-new-system/&quot; rel=&quot;ugc nofollow&quot;&gt;https://gamedevbeginner.com/input-in-unity-made-easy-complete-guide-to-the-new-system/&lt;/a&gt;
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Input System&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;input_system&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:2,&amp;quot;range&amp;quot;:&amp;quot;34-147&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit3&quot; id=&quot;vr&quot;&gt;VR&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
&lt;a href=&quot;https://forum.unity.com/threads/oculus-quest-how-to-detect-a-b-x-y-button-presses.1108232/&quot; class=&quot;urlextern&quot; title=&quot;https://forum.unity.com/threads/oculus-quest-how-to-detect-a-b-x-y-button-presses.1108232/&quot; rel=&quot;ugc nofollow&quot;&gt;https://forum.unity.com/threads/oculus-quest-how-to-detect-a-b-x-y-button-presses.1108232/&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;
&lt;a href=&quot;https://developer.oculus.com/documentation/unity/unity-ovrinput/&quot; class=&quot;urlextern&quot; title=&quot;https://developer.oculus.com/documentation/unity/unity-ovrinput/&quot; rel=&quot;ugc nofollow&quot;&gt;https://developer.oculus.com/documentation/unity/unity-ovrinput/&lt;/a&gt;
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;VR&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;vr&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:3,&amp;quot;range&amp;quot;:&amp;quot;148-&amp;quot;} --&gt;</description>
    </item>
</rdf:RDF>
