Here is my code -
#include "main.h"
#include <fstream>
using namespace std;
extern "C" __declspec(dllexport) BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
ofstream outfile;
outfile.open("E:\\temp\\DllMain.txt");
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
// attach to process
// return FALSE to fail DLL load
break;
case DLL_PROCESS_DETACH:
// detach from process
break;
case DLL_THREAD_ATTACH:
// attach to thread
break;
case DLL_THREAD_DETACH:
// detach from thread
break;
}
return TRUE; // succesful
}
So the issues is, if Visual Studio is installed, this function is working fine, I am able to create DllMain.txt in e:\temp\ folder, but if Visual studio is not installed, problem with the function call. Explorer is unable to call this function. More information is given in edited section of what I am trying.
I am building a dll file with the following settings, check this link
Editted Information ::
I am implementing "Send To" protocol of windows for mail client. So I need to build a dll and I have to register my application as a email client in windows. So if user selects my app for default email client like outlook and thunderbird, I needed a dll to do some task.
Example - select a file -> (right click) send to -> mail recipient.
Here explorer calls dll file. If visual studio is installed works perfect. Tried in a pc where Visual studio is not installed, Result error message and after that I tried after installing Visual studio and got a result I wanted.
I don't want to force my user to install MSVC runtime. Because If you are aware about thunderbird (Mozilla product), thunderbird is able to do this thing without MSVC runtime.
To run a dll in windows without MSVC, One need to build a dll with Release Configuration.
You can change this from select Project -> properties -> Configuration manager -> Active Solution Configuration and change to Release (If it is not selected).
If MSVC is not installed and dll is of Debug configuration, then explorer is unable to read a dll, so dll must be of Release configuration only.