I'm trying to replace some functions made in LazarusLib with functions written in C++ for Inno Setup installer.
So I created a Dynamic-Link Library (DLL) project in Visual studio and added the following code:
InstallerFunctions.h:
extern "C" { __declspec(dllexport) bool __stdcall CheckPortAvailable(int Port);}
InstallerFunctions.cpp:
#include "pch.h"#include "framework.h"#include "InstallerFunctions.h"#include <windows.h>#include <winsock.h>#include <string>#include <fstream>bool __stdcall CheckPortAvailable(int Port) { WSADATA WSAData; SOCKET Sock; sockaddr_in SockAddr; int ErrorCode; if (WSAStartup(MAKEWORD(2, 2), &WSAData) != 0) return false; Sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (Sock == INVALID_SOCKET) return false; ZeroMemory(&SockAddr, sizeof(SockAddr)); SockAddr.sin_family = AF_INET; SockAddr.sin_addr.s_addr = INADDR_ANY; SockAddr.sin_port = htons(Port); ErrorCode = bind(Sock, reinterpret_cast<sockaddr*>(&SockAddr), sizeof(SockAddr)); closesocket(Sock); WSACleanup(); return (ErrorCode != SOCKET_ERROR);}
This project builds successfully. The project is configured to output the DLL file to \Output\Then I added this to Inno Setup script:
[Files]Source: "..\InstallerFunctions\Output\InstallerFunctions.dll"; DestDir: "{app}"; Flags: ignoreversion
The path is correct. Then I declare the function as following:
function CheckPortAvailable(Port: Integer): Boolean;external 'CheckPortAvailable@files:InstallerFunctions.dll stdcall delayload';
When I try to call CheckPortAvailable I get the following error:Could not call proc.
I tried to use DLL explorer to find the functions I require and DLL explorers are able to find the functions. Any idea what else can I try?
Edit:It appears that the function is recognized, so the issue defenitly lies in C++ project: