Trying to load a C# DLL for Macro Scheduler, won't load

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
kevinkalexander67
Newbie
Posts: 8
Joined: Tue Jul 11, 2017 2:36 pm

Trying to load a C# DLL for Macro Scheduler, won't load

Post by kevinkalexander67 » Tue Jul 11, 2017 3:11 pm

I'm writing a DLL in C# using the NuGet Package "Unmanaged Exports (DllExport for .Net)". I'm trying to write a supplemental DLL to Macro Scheduler that allows me to hide and show client windows. Here's the C# code:

Code: Select all

        [DllExport("HideWnd", CallingConvention.StdCall)]
        public static int HideWnd(string sTitle)
        {
            int ret = 0;
            var win = FindWindowsWithText(sTitle);
            foreach (int wnd in win)
            {
                hwndHiddenWnd = wnd;
                ret = ShowWindow(hwndHiddenWnd, 0); //// SW_HIDE
            }
            return ret;
        }

        /// <summary>
        /// Shows the window.
        /// </summary>
        /// <returns>Whether the ShowWindow call fails or not</returns>
        [DllExport("ShowWnd", CallingConvention.StdCall)]
        public static int ShowWnd()
        {
            int ret = 0;
            ret = ShowWindow(hwndHiddenWnd, 1); ////SW_SHOWNORMAL
            hwndHiddenWnd = 0;
            return ret;
        }
    }
All of the documentation that I've been able to find says that Macro Scheduler wants the functions as __stdcall calling convention. Also, everything that I've read says that the DLL must be compiled as x64 or x86 for the functions to be exported properly. But when I compile the DLL with X64 as the platform, the DLL will not load into Macro Scheduler. Here's the Macro Scheduler code:

Code: Select all

Let>Lib=D:\ArgoDev\trunk\ArgoEmpiScriptingTools\bin\x64\Release\ArgoEmpiScriptingTools.dll
LibLoad>Lib,hLib
LibFunc>hLib,HideWnd,funcHide,WinDiff
LibFunc>hLib,ShowWnd,funcShow
LibFree>hLib
If I compile the DLL with the platform as "Any CPU", the library appears to load because hLib is non-zero. But then the exported functions aren't visible. I'm in a catch-22. If I compile with x64, then the library won't load. If I compile as "Any CPU", then the functions won't load.

Has anyone gotten a C# DLL to work with Macro Scheduler? If so, would you mind telling me how you did it?

I've even gone so far as to create a C++ DLL with just a simple "HelloWorld" function and even that won't load:

Code: Select all

#ifndef ARGOEMPICPPSCRIPTINGTOOLS_H
#define ARGOEMPICPPSCRIPTINGTOOLS_H

extern "C"
{
#ifdef EXPORTING_DLL
	extern __declspec(dllexport) int __stdcall HelloWorld();
#else
	extern __declspec(dllimport) int HelloWorld();
#endif
}
#endif

Code: Select all

// dllmain.cpp : Defines the entry point for the DLL application.
#include "stdafx.h"

#define EXPORTING_DLL
#include "ArgoEmpiCppScriptingTools.h"

BOOL APIENTRY DllMain(HANDLE hModule, DWORD  ul_reason_for_call, LPVOID lpReserved)
{
	return TRUE;
}

extern "C"
{
	int HelloWorld(void)
	{
		return 1;
	}
}

Code: Select all

Let>Lib=D:\ArgoDev\trunk\ArgoEmpiCppScriptingTools\x64\Release\ArgoEmpiCppScriptingTools.dll
LibLoad>Lib,hLib
LibFunc>hLib,HelloWorld,r
LibFree>hLib
Even the C++ DLL won't load. Any other ideas on what I'm missing with that?

kevinkalexander67
Newbie
Posts: 8
Joined: Tue Jul 11, 2017 2:36 pm

Re: Trying to load a C# DLL for Macro Scheduler, won't load

Post by kevinkalexander67 » Tue Jul 11, 2017 3:38 pm

I found the solution to my problem. It was to compile the C# DLL as x86. I guess because Macro Scheduler is x86 it wants to load x86 DLL's(?). But once I compiled my C# DLL as x86, it loaded and successfully called the HideWnd and ShowWnd functions from the Macro Scheduler script.

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts