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
#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:
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:
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.
Hello,
Trying to compile the source code in the attachment :
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
for static libMINIUPNP_STATICLIB
WIN32_SNPRINTF_H
for x64 exclude miniupnpcmodule.c from library, as pythonconfig.h have a pid_t conflict.
Hi Timo,
Thanks for your built. I can get a listing with the following command :
upnpc.exe -l
Quote from: TimoVJL on January 22, 2024, 07:11:32 AM
for static libMINIUPNP_STATICLIB
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