Возникла проблема с импортом DLL в единство - PullRequest
2 голосов
/ 26 июня 2019

Я пытаюсь получить user32.dll в мою БЕСПЛАТНУЮ версию.(Не профессионал)

Я просто поместил файл user32.dll в папку «Активы / Плагины /», и выдает ошибку:

DLLNotFoundException: Активы / Плагины / user32.dll

Вот код, который я использую:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Runtime.InteropServices;
using System;
using System.Diagnostics;

public class DatabaseManager : MonoBehaviour
{



    //DLL imports
    [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
    static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

    [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
    [return: MarshalAs(UnmanagedType.Bool)]
    static extern bool SetForegroundWindow(IntPtr hWnd);

    static Process proc = Process.GetProcessesByName("firefox")[0];
    IntPtr ptrFF = proc.Handle;
    //------------------------------------------------------------------------


    void Awake()
    {              
        SetForegroundWindow(ptrFF);
    }

   //Other code functions like Update etc.
}

Я где-то слышал, что неуправляемые dll (c ++) можно использовать только в Unity Pro, но мне действительно нужна эта DLL, я что-то не так делаю???Я не уверен, действительно ли user32.dll подпадает под неуправляемую DLL c ++.

Пожалуйста, помогите.

1 Ответ

0 голосов
/ 26 июня 2019

Изменить путь с Assets/Plugins/ на Assets/Plugins/x86_64/.

using UnityEngine;
using System.Runtime.InteropServices;

public class DatabaseManager : MonoBehaviour {

    [DllImport("user32.dll")] static extern int GetForegroundWindow();

    [DllImport("user32.dll", EntryPoint="MoveWindow")]  
    static extern int  MoveWindow (int hwnd, int x, int y,int nWidth,int nHeight,int bRepaint);

    void Awake()
    {
        int handle = GetForegroundWindow();
        Debug.Log(handle);

        int fWidth  = Screen.width;
        int fHeight = Screen.height;
        // Move the Unity windows.
        MoveWindow(handle,0,0,fWidth,fHeight,1); 

    }
}
...