FileForums

FileForums (https://fileforums.com/index.php)
-   Conversion Tutorials (https://fileforums.com/forumdisplay.php?f=55)
-   -   Create Dll C++ in VS 2015 compatible with Inno Setup (https://fileforums.com/showthread.php?t=99510)

MCI 05-09-2017 16:09

Create Dll C++ in VS 2015 compatible with Inno Setup
 
Hi!

I would like to know if you can help create a post that explains in detail how to create a C ++ Dll Compatible with Inno Setup, since for some time I have not been able to do it in a stable way, to achieve this come here to see if they can help me.

my problem is always the same, the Dll does not run on a PC in which it has not been compiled ... I do not explain how this happens but I invite you to look at this code. and tell me if it contains errors or something.

Name of DLL is IsFunc.dll

for now it only contains a single function exported .. because it is not necessary to show all the source code if the error is always given ... with any number of internal functions or exporteds.

Header.h
Code:

#pragma once
#include <Windows.h>

DllMain.cpp
Code:

#include "Header.h"
HWND AppHandle = 0;

BOOL __stdcall EnumProc(HWND hWnd, LPARAM lParam)
{
        DWORD Pid;
        WCHAR cl[14];
        GetWindowThreadProcessId(hWnd, &Pid);
        GetClassNameW(hWnd, cl, 13);

        if (Pid == GetCurrentProcessId())
                if (wcsstr(cl, L"TApplication"))
                        AppHandle = hWnd;

        return TRUE;
};

void Dll_Start(void)
{
        EnumWindows(EnumProc, 0);
};

void Dll_Stop(void)
{};

BOOL __stdcall DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
        switch (ul_reason_for_call)
        {
        case DLL_PROCESS_ATTACH:
                Dll_Start();
                break;

        case DLL_PROCESS_DETACH:
                Dll_Stop();
                break;
        };

        return TRUE;
};

IsFunc.cpp
Code:

#include "Header.h"
extern HWND AppHandle;

HWND __stdcall GetAppHandle(void)
{
        return AppHandle;
};

Defin.def
Code:

LIBRARY "IsFunc"
EXPORTS
        GetAppHandle

The purpose of the GetAppHandle function is to get the Application.Handle which can not be obtained in version 5.5.9 of Inno Setup. I know that you can get this value without any Dll but it is indispensable that the Dll conosca the value of the Application.Handle so that the other functions that I will show you can work ... Personally I do not like working with Inno Setup version 5.5.1 Advance .. I prefer version 5.5.9 for the new features .. :cool:

Inno Setup Script

Code:

[Setup]
AppId={{684EB0C0-995E-4B93-916E-01B0AFA5EA45}
AppName=Test
AppVersion=1.5
;AppVerName=Test
AppPublisher=Test
AppPublisherURL=http://www.example.com/
AppSupportURL=http://www.example.com/
AppUpdatesURL=http://www.example.com/
CreateAppDir=no
OutputDir=.\
OutputBaseFilename=test
Compression=lzma
SolidCompression=yes

[Languages]
Name: "default"; MessagesFile: "compiler:Default.isl"

[Files]
Source: "IsFunc.dll"; Flags: dontcopy;

Code:

function GetAppHandle(): Longint;
external 'GetAppHandle@files:IsFunc.dll stdcall';

function InitializeSetup(): Boolean;
begin
  MsgBox(IntToStr(GetAppHandle()), mbInformation, MB_OK);
end;

[CENTER]That's all the source Code ..


https://i.imgur.com/lERzZQA.jpg

During compilation there are no errors or anything ..

It works perfectly in the image you see the value obtained by the function GetAppHandle

https://i.imgur.com/3posUP7.jpg

And here is the problem .. :mad:

but if I try on another PC this happens :mad:

Apparently it's as if the linked function does not exist.?? :confused:

And after performing debugging tests with VS I realized that the Dll is loaded into memory and the code of the DllMain function is executed but it just does not connect to the other functions :confused:

Despite my lack of experience in creating Dlls .. I have programming skills in the C ++, Delphi, Inno Setup, Java, PHP, HTML, and others languages and never had a problem of this type

I think maybe I'm missing some property in the VS solution or maybe I'm creating it in the wrong way, to work on Inno Setup

Thank you in advance for any help :D

felice2011 05-09-2017 23:39

wow seems interesting I follow with pleasure, but unfortunately this is not a programming forum, let's see who goes on..:)

ravencrow 06-09-2017 01:41

Code:

#include <windows.h>

HANDLE __stdcall MyHandle(void)
{
  return GetCurrentProcess();
}

Code:

EXPORTS
  MyHandle


MCI 06-09-2017 05:19

Thank you
 
Quote:

Originally Posted by ravencrow (Post 462178)
Code:

#include <windows.h>

HANDLE __stdcall MyHandle(void)
{
  return GetCurrentProcess();
}

Code:

EXPORTS
  MyHandle


Friend this function does not return the desired value .. But thanks .. the problem in is the why the dll does not work on another pc, and it is still trying and I think it is that it has some dependence but they do not understand why .. :confuso: :confuso:

felice2011 06-09-2017 07:30

It does not work on another PC because the *.dll created/written, must be saved in the executable to be rewritten/read in other PC systems. Or at least I guess this is your problem..:confused::rolleyes:

MCI 06-09-2017 08:43

Quote:

Originally Posted by felice2011 (Post 462182)
It does not work on another PC because the *.dll created/written, must be saved in the executable to be rewritten/read in other PC systems. Or at least I guess this is your problem..:confused::rolleyes:

The problem is that the DLL does not run .... on another PC ... It only works on the PC on which it was written / created :mad: :confused: :confused:

MCI 06-09-2017 08:45

I'm going to upload the complete source code to see if that makes it easier to solve the problem.

felice2011 06-09-2017 08:53

Quote:

Originally Posted by MCI (Post 462183)
The problem is that the DLL does not run .... on another PC ... It only works on the PC on which it was written / created :mad: :confused: :confused:

Check that the code creates the same path on another PC and reads and decodes the DLL in the existing path;)

MCI 06-09-2017 09:06

Quote:

Originally Posted by felice2011 (Post 462185)
Check that the code creates the same path on another PC and reads and decodes the DLL in the existing path;)

In effect this happens since the DLL is included in a test with Inno Setup :D , and when transferring the creator file by Inno Setup, the displayed error occurs. at the time of running it on another PC. :confused: :confused:

kassane 06-09-2017 09:41

Code:

HANDLE __stdcall MyHandle(void)
{
  return AppHandler;
}

to:
Code:

extern "C" __declspec(dllexport) HANDLE MyHandle(void)
{
  return AppHandler;
}

My Example: using [Inno-Setup 5.5.1 + DLL(MSVC 2017 x86)] Works!
Code:


//MyDll.cpp

#pragma once

typedef long int HWND;

extern "C" __declspec(dllexport) HWND Func(void)
{
        return 30*5; //150
}


MCI 06-09-2017 11:21

Quote:

Originally Posted by kassane (Post 462187)
Code:

HANDLE __stdcall MyHandle(void)
{
  return AppHandler;
}

to:
Code:

extern "C" __declspec(dllexport) HANDLE MyHandle(void)
{
  return AppHandler;
}

My Example: using [Inno-Setup 5.5.1 + DLL(MSVC 2017 x86)] Works!
Code:


//MyDll.cpp

#pragma once

#ifdef MYDLL_EXPORTS
#define MYDLL __declspec(dllexport)
#else
#define MYDLL __declspec(dllimport)
#endif

typedef long int HWND;

extern "C" __declspec(dllexport) HWND Func(void)
{
        return 30*5;
}


not working, same problem occurs :confused: :confused:

kassane 06-09-2017 11:58

1 Attachment(s)
Quote:

Originally Posted by MCI (Post 462190)
not working, same problem occurs :confused: :confused:

Weird! Well, it worked normally here. Did you test my simple example?

--------------------------------------------------------------------
Update:

-- c++ src updated english strings example
-- Obj. Pascal (freepascal and Delphi) src added
-- setup src and demo

Note: (demo) C++ DLL require vcredist 2017!
Install vcredist 2017:
Code:

https://go.microsoft.com/fwlink/?LinkId=746571

MCI 06-09-2017 12:14

Thank you..
 
Quote:

Originally Posted by kassane (Post 462191)
Weird! Well, it worked normally here. Did you test my simple example?

The problem seems to have already been resolved. Apparently a bad set up the C ++ compiler. :) :D :D ;)

anyway, thank you.

I'm going to upload a file so that you can test it all that you want, and I'd appreciate it if you inform me the result .. :D :D

kassane 08-09-2017 07:51

Update example!

MCI 08-09-2017 09:07

Not Work.
 
1 Attachment(s)
Quote:

Originally Posted by kassane (Post 462219)
Update example!

Try it on another pc so you can see that it does not work. :confused:


All times are GMT -7. The time now is 10:46.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
FileForums @ https://fileforums.com