I have a native dll (bar.dll
) that does almost nothing:
It exports one function foo
that opens calc.exe
.
And it does the same on DLL_PROCESS_ATTACH
.
I've read here that once everything else fails
The directories that are listed in the PATH environment variable
are searched.
I've placed bar.dll
in a folder that's in PATH (and when I use the where
it's located successfully).
But when I try to run
rundll32 bar.dll,foo
It fails with
There was a problem starting bar.dll
bar.dll is not a valid Win32 application.
(I've tried compiling it both as 32 and 64 bit) It does work if I'm in the same directory.
The source code
bar.cpp
#include "stdafx.h"
#include "bar.h"
#include <iostream>
BAR_API void __stdcall foo(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow)
{
system("calc");
}
bar.h
#ifdef BAR_EXPORTS
#define BAR_API __declspec(dllexport)
#else
#define BAR_API __declspec(dllimport)
#endif
#pragma comment(linker, "/EXPORT:foo=_foo@0")
extern "C" {
BAR_API void __stdcall foo(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow);
}
dllmain.cpp
#include "stdafx.h"
#include "bar.h"
#include <iostream>
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}