Reputation: 41
I have a simple Visual Studio 2017 solution set up with two projects. The first project is an executable that links (load-time linking) to a DLL generated from the second project. The second project is a simple test DLL that exports a single function, and contains an empty DllMain entry point.
If I try to debug the solution, I get an error that says "The application was unable to start correctly (0xc0000142). Click OK to close the application." I tried searching for the meaning of 0xc0000142, but couldn't find anything useful from a development point of view.
If I remove the DllMain entry point from the DLL and rebuild, everything works fine.
Here is the DLL header (MyMath.h):
#pragma once
#ifdef THE_DLL_EXPORT
#define API __declspec(dllexport)
#else
#define API __declspec(dllimport)
#endif
#ifdef __cplusplus
extern "C" {
#endif
API int AddNumbers(int a, int b);
#ifdef __cplusplus
}
#endif
Here is the DLL code file (MyMath.cpp):
#include "MyMath.h"
#include <stdio.h>
#include <Windows.h>
extern "C" BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD fdwReason, LPVOID lpvReserved)
{
}
int AddNumbers(int a, int b)
{
return a + b;
}
And here is the main code file from the first project that uses the DLL (Source.cpp):
#include <iostream>
#include "MyMath.h"
using namespace std;
int main()
{
int x = 3;
int y = 4;
cout << x << " + " << y << " = " << AddNumbers(x, y) << endl;
cin.get();
return 0;
}
What is going on here?
Upvotes: 0
Views: 2219
Reputation: 41
DllMain wasn't returning TRUE
. Returning FALSE
or 0 causes the application to fail with error code 0xc0000142.
Upvotes: 4