NO

Author Topic: miniupnp Library  (Read 547 times)

Offline WiiLF23

  • Member
  • *
  • Posts: 66
miniupnp Library
« on: January 22, 2024, 05:42:06 AM »
Hey everyone. I have the need to use the miniupnp UPnP C library for my requirements.

https://github.com/miniupnp/miniupnp

Now, I have downloaded the source and included

ZIP path               New folder
-------------          ----------------
include\*.h   -- >  miniupnp
src\*.c         -- >  miniupnp

Now, I have the folder "miniupnp" containing the required files.

I create a new win64 static library project, and add "miniupnp.c" to my project tree. Compiles successfully.

libminiupnp.lib (25.2 KB)

Now, I copy the "miniupnp" directory to (Pelles C - Program Files) -> \Include\miniupnp

Now, in my main project requiring the library use, I added

Code: [Select]
#include <miniupnpc/miniupnpc.h>
#pragma comment(lib, "libminiupnpc.lib")

However, calling any of the functions required it does not resolve any external symbols. I do not know what to do from here.

I see on the GIT there are files (a .def file too) for building DLL, a .rc file for that too etc.

DEF file:

Code: [Select]
LIBRARY
; miniupnpc library
   miniupnpc

EXPORTS
; miniupnpc
   upnpDiscover
   upnpDiscoverDevice
   upnpDiscoverDevices
   upnpDiscoverAll
   freeUPNPDevlist
   parserootdesc
   UPNP_GetValidIGD
   UPNP_GetIGDFromUrl
   GetUPNPUrls
   FreeUPNPUrls
; miniwget
   miniwget
   miniwget_getaddr
; upnpcommands
   UPNP_GetTotalBytesSent
   UPNP_GetTotalBytesReceived
   UPNP_GetTotalPacketsSent
   UPNP_GetTotalPacketsReceived
   UPNP_GetStatusInfo
   UPNP_GetConnectionTypeInfo
   UPNP_GetExternalIPAddress
   UPNP_GetLinkLayerMaxBitRates
   UPNP_AddPortMapping
   UPNP_AddAnyPortMapping
   UPNP_DeletePortMapping
   UPNP_DeletePortMappingRange
   UPNP_GetPortMappingNumberOfEntries
   UPNP_GetSpecificPortMappingEntry
   UPNP_GetGenericPortMappingEntry
   UPNP_GetListOfPortMappings
   UPNP_AddPinhole
   UPNP_CheckPinholeWorking
   UPNP_UpdatePinhole
   UPNP_GetPinholePackets
   UPNP_DeletePinhole
   UPNP_GetFirewallStatus
   UPNP_GetOutboundPinholeTimeout
; upnperrors
   strupnperror
; portlistingparse
   ParsePortListing
   FreePortListing

But this is for a DLL. What exactly am I missing here? This is what I used for testing:

Code: [Select]
void testMiniUPnP() {
    // Discover UPnP devices on the network
    int error;
    struct UPNPDev* devlist = upnpDiscover(1000, NULL, NULL, 0, 0, 2, &error);

    if (devlist == NULL) {
        printf("No UPnP devices found. Error code: %d\n", error);
        return;
    }

    // Iterate through the list of discovered devices
    struct UPNPDev* device = devlist;
    while (device) {
        printf("Device: %s\n", device->descURL);
        // Perform additional actions if needed

        // Move to the next device in the list
        device = device->pNext;
    }

    // Free the device list
    freeUPNPDevlist(devlist);
}

Any help appreciated!  ;)

Lib project is attached for review.

Offline Vortex

  • Member
  • *
  • Posts: 802
    • http://www.vortex.masmcode.com
Re: miniupnp Library
« Reply #1 on: January 22, 2024, 07:02:29 AM »
Hello,

Trying to compile the source code in the attachment  :

Code: [Select]
Building upnpc.obj.
D:\libminiupnpc\miniupnpc\upnpc.c(150): warning #2018: Undeclared function '_scprintf' (did you mean: _snprintf?); assuming 'extern' returning 'int'.
D:\libminiupnpc\miniupnpc\upnpc.c(422): warning #2018: Undeclared function '_scprintf' (did you mean: _snprintf?); assuming 'extern' returning 'int'.
D:\libminiupnpc\miniupnpc\upnpc.c(427): warning #2018: Undeclared function '_scprintf' (did you mean: _snprintf?); assuming 'extern' returning 'int'.
Building libminiupnpc.lib.
Done.

_scprintf should be offered by the MS VC run-time library :

https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/scprintf-scprintf-l-scwprintf-scwprintf-l?view=msvc-170
Code it... That's all...

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: miniupnp Library
« Reply #2 on: January 22, 2024, 07:11:32 AM »
for static lib
Code: [Select]
MINIUPNP_STATICLIB
Code: [Select]
WIN32_SNPRINTF_H
for x64 exclude miniupnpcmodule.c from library, as pythonconfig.h have a pid_t conflict.
« Last Edit: January 22, 2024, 04:45:09 PM by TimoVJL »
May the source be with you

Offline Vortex

  • Member
  • *
  • Posts: 802
    • http://www.vortex.masmcode.com
Re: miniupnp Library
« Reply #3 on: January 22, 2024, 07:22:50 PM »
Hi Timo,

Thanks for your built. I can get a listing with the following command :

Code: [Select]
upnpc.exe -l
Code it... That's all...

Offline WiiLF23

  • Member
  • *
  • Posts: 66
Re: miniupnp Library
« Reply #4 on: January 22, 2024, 07:36:20 PM »
for static lib
Code: [Select]
MINIUPNP_STATICLIB
Code: [Select]
WIN32_SNPRINTF_H
for x64 exclude miniupnpcmodule.c from library, as pythonconfig.h have a pid_t conflict.

Wow, thank you TimoVJL! That is impressive. I did locate the 32bit and 64bit precomiled DLLs (different versions) but never got anywhere after checking functions with DLL Export Viewer.

Cheers!  ;D