Skip to content

Instantly share code, notes, and snippets.

@baiyanhuang
Created October 29, 2011 09:45
Show Gist options
  • Save baiyanhuang/1324285 to your computer and use it in GitHub Desktop.
Save baiyanhuang/1324285 to your computer and use it in GitHub Desktop.
#include "Win32DLL.h"
#include <iostream>
#ifdef UNICODE
#define tcout std::wcout
#else
#define tcout std::cout
#endif
EXTERN_C IMAGE_DOS_HEADER __ImageBase;
tstring WIN32DLL_API GetThisDLLName()
{
//// and then, anywhere you need it:
TCHAR szDLLPath[_MAX_PATH];
::GetModuleFileName((HINSTANCE)&__ImageBase, szDLLPath, _MAX_PATH);
tcout << szDLLPath;
return tstring(szDLLPath);
}
#ifdef WIN32DLL_EXPORTS
#define WIN32DLL_API __declspec(dllexport)
#else
#define WIN32DLL_API __declspec(dllimport)
#endif
#include <string>
typedef std::basic_string<TCHAR> tstring;
tstring WIN32DLL_API GetThisDLLName();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment