Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Zephir Call Windows External DLL functions LoadLibrary()

I'm trying to call function from Windows dll file but i dont get dll handle. Can i call function from external library? Any solution?

Here attached example code

namespace Newapp;

%{
// top statement before class, add to after headers
// test include .h
#include "core/stdafx.h"
#include <Windows.h>
#include <stdio.h>

#include "kernel/require.h"

typedef int(__stdcall *msgbox)(HWND, LPCSTR, LPCSTR, UINT);
typedef HWND(__stdcall *actiwin)(void);

int GetHandleA(){

    HMODULE dll = LoadLibrary(L"C:\\Windows\\System32\\user32.dll");
    if (NULL != dll)
    {
        actiwin func = (actiwin)GetProcAddress(dll, "GetForegroundWindow");

        if (func != NULL)
        {
            HWND  ret = func();
            return (int)ret;
        }
        else return -2;
    }
    else{
        return -1;
    }
}

static long Sumik(long a, long b)
{
    return a + b;
}

}%

class Greeting
{

    public static function say()
    {
        echo "hello world!";
    }

    public function alpha(string str)
    {
        char ch;

        for ch in str {
            echo ch, "\n";
        }
    }
    public static function dllcall()
    {
        long ret = 0;
        %{
            HMODULE dll = LoadLibrary(L"user32.dll");
            if (NULL != dll)
            {
                msgbox func = (msgbox)GetProcAddress(dll, "MessageBoxA");

                if (func != NULL)
                {
                    int ret = func(0, "text", "Textr1", MB_OK);
                }
                else {

                }
            }
        }%
        return ret;
    }

    public static function getHandlerEx()
        {
            long a = 10;

            %{
            a = GetHandleA();
            }%

            return a;
        }

    public static function SumC(int x, int y)
    {
        long a = 0;
        %{
            a = Sumik(x, y);
        }%
        return a;
    }

}

It's not solution and this case at github is created by me :)

Could You explain me why HMODULE dll = LoadLibrary(L"user32.dll"); return 0/NILL?