将DLL导入统一时遇到问题

时间:2019-06-26 17:19:35

标签: unity3d user32

我正在尝试将user32.dll转换为统一的免费版本。 (不是专业人士)

我只是将user32.dll放到了Assets / Plugins /文件夹中,它给我的错误是:

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是否实际上属于不受管理的c ++ dll。

请帮助。

1 个答案:

答案 0 :(得分:0)

将路径从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); 

    }
}