0
votes

I am writing\compiling a DLL that(currently) only exports a blank function. Source code:

DLLMain.cpp-

LIBRARYEXPORT LRESULT CALLBACK KeyboardProc(
int code,
WPARAM wParam,
LPARAM lParam
){



    return 0;


} 

Everything is okay so far, and here is my DLLMain.h-

using namespace std;

#include <iostream>
#include <fstream>
#include <string>
#include <Windows.h>
#define LIBRARYEXPORT __declspec(dllexport)



LIBRARYEXPORT LRESULT CALLBACK KeyboardProc(
    int code,
    WPARAM wParam,
    LPARAM lParam
);

I plan to use this DLL with windows hooks to detect key presses, but when I call LoadLibrary from a separate executable, it returns with a runtime error saying

"DLL 'C:\Users\Orin\Documents\Visual Studio 2010\Projects\winmain\Debug\winmain.dll' is attempting managed execution inside OS Loader lock. Do not attempt to run managed code inside a DllMain or image initialization function since doing so can cause the application to hang."

That's great, but here's the catch: I'm not running any code at all in my KeyboardProc function, and I don't even have a DllMain routine

What I've tried(and hasn't worked):

  • Disabling CLR in project properties
  • Removing my "DllMain" routine
  • Using '#pragma unmanaged' when declaring functions

Suggestions and comments are really appreciated!

1
Debug + Exceptions, expand the "Managed Debugging Assistants" node, untick LoaderLock. - Hans Passant
@HansPassant I tried that, and then it comes up with a runtime error saying that I am attempting to run MSIL code during native code initialization. :-/ - user191125
Clearly you are doing something very wrong, it is utterly unclear what that might be. Start again and do not pick the project template from the CLR node this time. Use the "Win32 Project" template to create an unmanaged DLL. - Hans Passant
Thank you so much! That fixed it. I forgot that I used the Common Language Runtime support when I first created the library. - user191125

1 Answers

0
votes

Found Answer:

When using Visual Studio, you must not choose a CLR Library project. Instead use the "Win32 Project" template. I can't believe I missed that!