return hr;
}
-
-#ifndef CROSSGEN_COMPILE
-// ---------------------------------------------------------------------------
-// %%Function: CoInitializeCor
-//
-// Parameters:
-// fFlags - Initialization flags for the engine. See the
-// COINITICOR enumerator for valid values.
-//
-// Returns:
-// S_OK - On success
-//
-// Description:
-// Reserved to initialize the Cor runtime engine explicitly. This currently
-// does nothing.
-// ---------------------------------------------------------------------------
-STDAPI CoInitializeCor(DWORD fFlags)
-{
- WRAPPER_NO_CONTRACT;
-
- BEGIN_ENTRYPOINT_NOTHROW;
-
- // Since the CLR doesn't currently support being unloaded, we don't hold a ref
- // count and don't even pretend to try to unload.
- END_ENTRYPOINT_NOTHROW;
-
- return (S_OK);
-}
-
-// ---------------------------------------------------------------------------
-// %%Function: CoUninitializeCor
-//
-// Parameters:
-// none
-//
-// Returns:
-// Nothing
-//
-// Description:
-// Function to indicate the client is done with the CLR. This currently does
-// nothing.
-// ---------------------------------------------------------------------------
-STDAPI_(void) CoUninitializeCor(void)
-{
- WRAPPER_NO_CONTRACT;
-
- BEGIN_ENTRYPOINT_VOIDRET;
-
- // Since the CLR doesn't currently support being unloaded, we don't hold a ref
- // count and don't even pretend to try to unload.
- END_ENTRYPOINT_VOIDRET;
-
-}
-
-// Undef LoadStringRC & LoadStringRCEx so we can export these functions.
-#undef LoadStringRC
-#undef LoadStringRCEx
-
-// ---------------------------------------------------------------------------
-// %%Function: LoadStringRC
-//
-// Parameters:
-// none
-//
-// Returns:
-// Nothing
-//
-// Description:
-// Function to load a resource based on it's ID.
-// ---------------------------------------------------------------------------
-STDAPI LoadStringRC(
- UINT iResourceID,
- __out_ecount(iMax) __out_z LPWSTR szBuffer,
- int iMax,
- int bQuiet
-)
-{
- WRAPPER_NO_CONTRACT;
-
- HRESULT hr = S_OK;
-
- if (NULL == szBuffer)
- return E_INVALIDARG;
- if (0 == iMax)
- return E_INVALIDARG;
-
- BEGIN_ENTRYPOINT_NOTHROW;
- hr = UtilLoadStringRC(iResourceID, szBuffer, iMax, bQuiet);
- END_ENTRYPOINT_NOTHROW;
- return hr;
-}
-
-// ---------------------------------------------------------------------------
-// %%Function: LoadStringRCEx
-//
-// Parameters:
-// none
-//
-// Returns:
-// Nothing
-//
-// Description:
-// Ex version of the function to load a resource based on it's ID.
-// ---------------------------------------------------------------------------
-#ifdef FEATURE_USE_LCID
-STDAPI LoadStringRCEx(
- LCID lcid,
- UINT iResourceID,
- __out_ecount(iMax) __out_z LPWSTR szBuffer,
- int iMax,
- int bQuiet,
- int *pcwchUsed
-)
-{
- WRAPPER_NO_CONTRACT;
- HRESULT hr = S_OK;
-
- if (NULL == szBuffer)
- return E_INVALIDARG;
- if (0 == iMax)
- return E_INVALIDARG;
-
- BEGIN_ENTRYPOINT_NOTHROW;
- hr = UtilLoadStringRCEx(lcid, iResourceID, szBuffer, iMax, bQuiet, pcwchUsed);
- END_ENTRYPOINT_NOTHROW;
- return hr;
-}
-#endif
-// Redefine them as errors to prevent people from using these from inside the rest of the compilation unit.
-#define LoadStringRC __error("From inside the CLR, use UtilLoadStringRC; LoadStringRC is only meant to be exported.")
-#define LoadStringRCEx __error("From inside the CLR, use UtilLoadStringRCEx; LoadStringRC is only meant to be exported.")
-
-#endif // CROSSGEN_COMPILE
-
-
// Replacement for legacy shim API GetCORRequiredVersion(...) used in linked libraries.
// Used in code:TiggerStorage::GetDefaultVersion#CallTo_CLRRuntimeHostInternal_GetImageVersionString.
HRESULT
//*****************************************************************************
-#if defined(_MSC_VER) && !defined(USE_DEPRECATED_CLR_API_WITHOUT_WARNING)
-#define DEPRECATED_CLR_API_MESG "This API has been deprecated. Refer to http://go.microsoft.com/fwlink/?LinkId=143720 for more details."
-#define DECLARE_DEPRECATED __declspec(deprecated(DEPRECATED_CLR_API_MESG))
-#define DEPRECATED_CLR_STDAPI EXTERN_C DECLARE_DEPRECATED HRESULT STDAPICALLTYPE
-#define DEPRECATED_CLR_STDAPI_(type) EXTERN_C DECLARE_DEPRECATED type STDAPICALLTYPE
-#else // _MSC_VER && !USE_DEPRECATED_CLR_API_WITHOUT_WARNING
-#define DECLARE_DEPRECATED
-#define DEPRECATED_CLR_STDAPI STDAPI
-#define DEPRECATED_CLR_STDAPI_(type) STDAPI_(type)
-#endif // _MSC_VER && !USE_DEPRECATED_CLR_API_WITHOUT_WARNING
-
#ifdef __cplusplus
extern "C" {
#endif
#define INVALID_TASK_ID 0x0
#define MAX_CONNECTION_NAME MAX_PATH
-//*****************************************************************************
-//*****************************************************************************
-//
-// D L L P U B L I C E N T R Y P O I N T D E C L A R A T I O N S
-//
-//*****************************************************************************
-//*****************************************************************************
-
-BOOL STDMETHODCALLTYPE _CorDllMain(HINSTANCE hInst, DWORD dwReason, LPVOID lpReserved);
-__int32 STDMETHODCALLTYPE _CorExeMain();
-__int32 STDMETHODCALLTYPE _CorExeMainInternal();
-__int32 STDMETHODCALLTYPE _CorExeMain2( // Executable exit code.
- PBYTE pUnmappedPE, // -> memory mapped code
- DWORD cUnmappedPE, // Size of memory mapped code
- _In_ LPWSTR pImageNameIn, // -> Executable Name
- _In_ LPWSTR pLoadersFileName, // -> Loaders Name
- _In_ LPWSTR pCmdLine); // -> Command Line
-
-STDAPI _CorValidateImage(PVOID *ImageBase, LPCWSTR FileName);
-STDAPI_(VOID) _CorImageUnloading(PVOID ImageBase);
-
-DEPRECATED_CLR_STDAPI CoInitializeEE(DWORD fFlags);
-DEPRECATED_CLR_STDAPI_(void) CoUninitializeEE(BOOL fFlags);
-DEPRECATED_CLR_STDAPI_(void) CoEEShutDownCOM(void);
-
-
#define MAIN_CLR_MODULE_NAME_W W("coreclr")
#define MAIN_CLR_MODULE_NAME_A "coreclr"
#define MAIN_CLR_DLL_NAME_A MAKEDLLNAME_A(MAIN_CLR_MODULE_NAME_A)
-
#define MSCOREE_SHIM_W MAIN_CLR_DLL_NAME_W
#define MSCOREE_SHIM_A MAIN_CLR_DLL_NAME_A
#define SWITCHOUT_HANDLE_VALUE ((HANDLE)(LONG_PTR)-2)
-
-//
-// CoInitializeCor flags.
-//
-typedef enum tagCOINITCOR
-{
- COINITCOR_DEFAULT = 0x0 // Default initialization mode.
-} COINITICOR;
-
//
// CoInitializeEE flags.
//
COINITEE_MAIN = 0x2 // Initialize prior to entering the main routine
} COINITIEE;
-//
-// CoInitializeEE flags.
-//
-typedef enum tagCOUNINITEE
-{
- COUNINITEE_DEFAULT = 0x0, // Default uninitialization mode.
- COUNINITEE_DLL = 0x1 // Uninitialization mode for unloading DLL.
-} COUNINITIEE;
-
//*****************************************************************************
//*****************************************************************************
//
//*****************************************************************************
//*****************************************************************************
-//
-// D L L P U B L I C E N T R Y P O I N T D E C L A R A T I O N S
-//
-//*****************************************************************************
-//*****************************************************************************
-
-DEPRECATED_CLR_STDAPI CoInitializeCor(DWORD fFlags);
-DEPRECATED_CLR_STDAPI_(void) CoUninitializeCor(void);
-
-//
-//*****************************************************************************
-//*****************************************************************************
// CLSID_Cor: {bee00000-ee77-11d0-a015-00c04fbbb884}
EXTERN_GUID(CLSID_Cor, 0xbee00010, 0xee77, 0x11d0, 0xa0, 0x15, 0x00, 0xc0, 0x4f, 0xbb, 0xb8, 0x84);
#endif // __cplusplus
-#undef DEPRECATED_CLR_STDAPI_
-#undef DEPRECATED_CLR_STDAPI
-#undef DECLARE_DEPRECATED
-#undef DEPRECATED_CLR_API_MESG
-
#endif // _COR_H_
// EOF =======================================================================
//*****************************************************************************
// Handle accessing localizable resource strings
//*****************************************************************************
-// NOTE: Should use locale names as much as possible. LCIDs don't support
-// custom cultures on Vista+.
-// TODO: This should always use the names
-#ifdef FEATURE_USE_LCID
-typedef LCID LocaleID;
-typedef LCID LocaleIDValue;
-#else
typedef LPCWSTR LocaleID;
typedef WCHAR LocaleIDValue[LOCALE_NAME_MAX_LENGTH];
-#endif
// Notes about the culture callbacks:
// - The language we're operating in can change at *runtime*!
// Callback to obtain both the culture name and the culture's parent culture name
typedef HRESULT (*FPGETTHREADUICULTURENAMES)(__inout StringArrayList* pCultureNames);
-#ifdef FEATURE_USE_LCID
-// Callback to return the culture ID.
-const LCID UICULTUREID_DONTCARE = (LCID)-1;
-#else
const LPCWSTR UICULTUREID_DONTCARE = NULL;
-#endif
typedef int (*FPGETTHREADUICULTUREID)(LocaleIDValue*);
BOOL CLRFreeLibrary(HMODULE hModule);
-// Prevent people from using LoadStringRC & LoadStringRCEx from inside the product since it
-// causes issues with having the wrong version picked up inside the shim.
-#define LoadStringRC __error("From inside the CLR, use UtilLoadStringRC; LoadStringRC is only meant to be exported.")
-#define LoadStringRCEx __error("From inside the CLR, use UtilLoadStringRCEx; LoadStringRC is only meant to be exported.")
-
// Load a string using the resources for the current module.
STDAPI UtilLoadStringRC(UINT iResouceID, __out_ecount (iMax) LPWSTR szBuffer, int iMax, int bQuiet=FALSE);
-#ifdef FEATURE_USE_LCID
-STDAPI UtilLoadStringRCEx(LCID lcid, UINT iResourceID, __out_ecount (iMax) LPWSTR szBuffer, int iMax, int bQuiet, int *pcwchUsed);
-#endif
-
// Specify callbacks so that UtilLoadStringRC can find out which language we're in.
// If no callbacks specified (or both parameters are NULL), we default to the
// resource dll in the root (which is probably english).
_ASSERTE(m_hInst != NULL || m_fMissing);
if (id == UICULTUREID_DONTCARE)
return FALSE;
-
-#ifdef FEATURE_USE_LCID
- return id == m_LangId;
-#else
+
return wcscmp(id, m_LangId) == 0;
-#endif
}
HRESOURCEDLL GetLibraryHandle()
private:
void SetId(LocaleID id)
{
-#ifdef FEATURE_USE_LCID
- m_LangId = id;
-#else
if (id != UICULTUREID_DONTCARE)
{
wcsncpy_s(m_LangId, NumItems(m_LangId), id, NumItems(m_LangId));
{
m_LangId[0] = W('\0');
}
-#endif
}
};
#endif
}
CONTRACTL_END;
-#if FEATURE_USE_LCID
- int langId=0;
- static PFNGETUSERDEFAULTUILANGUAGE pfnGetUserDefaultUILanguage=NULL;
- if( NULL == pfnGetUserDefaultUILanguage )
- {
- PFNGETUSERDEFAULTUILANGUAGE proc = NULL;
-
- HMODULE hmod = GetModuleHandleA(WINDOWS_KERNEL32_DLLNAME_A);
-
- if( hmod )
- proc = (PFNGETUSERDEFAULTUILANGUAGE)
- GetProcAddress(hmod, "GetUserDefaultUILanguage");
-
- if(proc == NULL)
- proc = (PFNGETUSERDEFAULTUILANGUAGE) -1;
-
- PVOID value = InterlockedExchangeT(&pfnGetUserDefaultUILanguage,
- proc);
- }
-
- // We should never get NULL here, the function is -1 or a valid address.
- _ASSERTE(pfnGetUserDefaultUILanguage != NULL);
-
-
- if( pfnGetUserDefaultUILanguage == (PFNGETUSERDEFAULTUILANGUAGE) -1)
- langId = GetSystemDefaultLangID();
- else
- langId = pfnGetUserDefaultUILanguage();
-
- *pResult= langId;
-#else // FEATURE_USE_LCID
_ASSERTE(sizeof(LocaleID)/sizeof(WCHAR) >=LOCALE_NAME_MAX_LENGTH);
return ::GetSystemDefaultLocaleName(*pResult, LOCALE_NAME_MAX_LENGTH);
-#endif //FEATURE_USE_LCID
- return 1;
}
static void BuildMUIDirectory(int langid, __out SString* pResult)
LocaleIDValue langid;
GetMUILanguageID(&langid);
- int lcid;
-#ifdef FEATURE_USE_LCID
- lcid=langid;
-#else
- lcid=::LocaleNameToLCID(langid,0);
-#endif
-
+ int lcid = ::LocaleNameToLCID(langid,0);
return BuildMUIDirectory(lcid, pResult);
}
DWORD dwFlags = FORMAT_MESSAGE_FROM_SYSTEM;
dwFlags |= FORMAT_MESSAGE_MAX_WIDTH_MASK;
-#if FEATURE_USE_LCID
- fHaveDescr = strDescr.FormatMessage(dwFlags, 0, hr, LANG_USER_DEFAULT);
-#else
fHaveDescr = strDescr.FormatMessage(dwFlags, 0, hr, 0);
-#endif
}
LPCSTR name = Exception::GetHRSymbolicName(hr);
return retVal;
}
-#ifdef FEATURE_USE_LCID
-STDAPI UtilLoadStringRCEx(
- LCID lcid,
- UINT iResourceID,
- __out_ecount(iMax) LPWSTR szBuffer,
- int iMax,
- int bQuiet,
- int *pcwchUsed
-)
-{
- CONTRACTL
- {
- DISABLED(NOTHROW);
- GC_NOTRIGGER;
- }
- CONTRACTL_END;
-
- HRESULT retVal = E_OUTOFMEMORY;
-
- EX_TRY
- {
- SString::Startup();
- CCompRC *pResourceDLL = CCompRC::GetDefaultResourceDll();
-
- if (pResourceDLL != NULL)
- {
- retVal = pResourceDLL->LoadString(bQuiet? CCompRC::Optional : CCompRC::Required,lcid, iResourceID, szBuffer, iMax, pcwchUsed);
- }
- }
- EX_CATCH
- {
- // Catch any errors and return E_OUTOFMEMORY;
- retVal = E_OUTOFMEMORY;
- }
- EX_END_CATCH(SwallowAllExceptions);
-
- return retVal;
-}
-#endif //FEATURE_USE_LCID
-
//*****************************************************************************
// Format a Runtime Error message.
//*****************************************************************************
// find the text for it.
else
{
-#ifdef FEATURE_USE_LCID
- if (WszFormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
- 0, hrRpt, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
- rcMsg, cchMsg, 0/*<TODO>@todo: marker</TODO>*/))
-#else
if (WszFormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
0, hrRpt, 0,
rcMsg, cchMsg, 0/*<TODO>@todo: marker</TODO>*/))
-#endif
{
hr = S_OK;
#ifndef FEATURE_PAL
-#ifdef FEATURE_USE_LCID
- int iRet = WszLCMapString(MAKELCID(LOCALE_INVARIANT, SORT_DEFAULT), dwFlags, &wc, 1, &wTmp, 1);
-#else
int iRet = ::LCMapStringEx(LOCALE_NAME_INVARIANT, dwFlags, &wc, 1, &wTmp, 1, NULL, NULL, 0);
-#endif
if (!iRet) {
// This can fail in non-exceptional cases becauseof unknown unicode characters.
wTmp = wc;
#endif
}
-// ---------------------------------------------------------------------------
-// %%Function: CoEEShutdownCOM()
-//
-// Parameters:
-// none
-//
-// Returns:
-// Nothing
-//
-// Description:
-// COM Objects shutdown stuff should be done here
-// ---------------------------------------------------------------------------
-void STDMETHODCALLTYPE CoEEShutDownCOM()
-{
-
- CONTRACTL
- {
- NOTHROW;
- GC_TRIGGERS;
- MODE_PREEMPTIVE;
- ENTRY_POINT;
- } CONTRACTL_END;
-
- if (g_fEEStarted != TRUE)
- return;
-
- HRESULT hr;
- BEGIN_EXTERNAL_ENTRYPOINT(&hr)
-
- InnerCoEEShutDownCOM();
-
- END_EXTERNAL_ENTRYPOINT;
-
- // API doesn't allow us to communicate a failure HRESULT. MDAs can
- // be enabled to catch failure inside CanRunManagedCode.
- // _ASSERTE(SUCCEEDED(hr));
-}
-
#endif // FEATURE_COMINTEROP
// ---------------------------------------------------------------------------
}
#include <optdefault.h>
-
-// ---------------------------------------------------------------------------
-// %%Function: CoInitializeEE(DWORD fFlags)
-//
-// Parameters:
-// fFlags - Initialization flags for the engine. See the
-// COINITIEE enumerator for valid values.
-//
-// Returns:
-// Nothing
-//
-// Description:
-// Initializes the EE if it hasn't already been initialized. This function
-// no longer maintains a ref count since the EE doesn't support being
-// unloaded and re-loaded. It simply ensures the EE has been started.
-// ---------------------------------------------------------------------------
-HRESULT STDAPICALLTYPE CoInitializeEE(DWORD fFlags)
-{
- CONTRACTL
- {
- NOTHROW;
- GC_TRIGGERS;
- MODE_PREEMPTIVE;
- }
- CONTRACTL_END;
-
- HRESULT hr = S_OK;
- BEGIN_ENTRYPOINT_NOTHROW;
- hr = InitializeEE((COINITIEE)fFlags);
- END_ENTRYPOINT_NOTHROW;
-
- return hr;
-}
-
-// ---------------------------------------------------------------------------
-// %%Function: CoUninitializeEE
-//
-// Parameters:
-// BOOL fIsDllUnloading :: is it safe point for full cleanup
-//
-// Returns:
-// Nothing
-//
-// Description:
-// Must be called by client on shut down in order to free up the system.
-// ---------------------------------------------------------------------------
-void STDAPICALLTYPE CoUninitializeEE(BOOL fIsDllUnloading)
-{
- LIMITED_METHOD_CONTRACT;
- //BEGIN_ENTRYPOINT_VOIDRET;
-
- // This API is unfortunately publicly exported so we cannot get rid
- // of it. However since the EE doesn't currently support being unloaded
- // and re-loaded, it is useless to do any ref counting here or to pretend
- // to unload it. The proper way to shutdown the EE is to call CorExitProcess.
- //END_ENTRYPOINT_VOIDRET;
-
-}
-
//*****************************************************************************
BOOL ExecuteDLL_ReturnOrThrow(HRESULT hr, BOOL fFromThunk)
{
int tmp; tmp = GetThreadUICultureId(&id); // TODO: We should use the name instead
_ASSERTE(tmp!=0 && id != UICULTUREID_DONTCARE);
SIZE_T cchParentCultureName=LOCALE_NAME_MAX_LENGTH;
-#ifdef FEATURE_USE_LCID
- SIZE_T cchCultureName=LOCALE_NAME_MAX_LENGTH;
- if (!::LCIDToLocaleName(id, sCulture.OpenUnicodeBuffer(static_cast<COUNT_T>(cchCultureName)), static_cast<int>(cchCultureName), 0))
- {
- hr = HRESULT_FROM_GetLastError();
- }
- sCulture.CloseBuffer();
-#else
sCulture.Set(id);
-#endif
#ifndef FEATURE_PAL
if (!::GetLocaleInfoEx((LPCWSTR)sCulture, LOCALE_SPARENT, sParentCulture.OpenUnicodeBuffer(static_cast<COUNT_T>(cchParentCultureName)),static_cast<int>(cchParentCultureName)))
// Impl for UtilLoadStringRC Callback: In VM, we let the thread decide culture
// Return an int uniquely describing which language this thread is using for ui.
// ---------------------------------------------------------------------------
-// TODO: Callers should use names, not LCIDs
-#ifdef FEATURE_USE_LCID
-static int GetThreadUICultureId(__out LocaleIDValue* pLocale)
-{
- CONTRACTL{
- NOTHROW;
- GC_NOTRIGGER;
- MODE_ANY;
- } CONTRACTL_END;
-
-
-
- int Result = UICULTUREID_DONTCARE;
-
- Thread * pThread = GetThread();
-
-#if 0 // Enable and test if/once the unmanaged runtime is localized
- // When fatal errors have occured our invariants around GC modes may be broken and attempting to transition to co-op may hang
- // indefinately. We want to ensure a clean exit so rather than take the risk of hang we take a risk of the error resource not
- // getting localized with a non-default thread-specific culture.
- // A canonical stack trace that gets here is a fatal error in the GC that comes through:
- // coreclr.dll!GetThreadUICultureNames
- // coreclr.dll!CCompRC::LoadLibraryHelper
- // coreclr.dll!CCompRC::LoadLibrary
- // coreclr.dll!CCompRC::GetLibrary
- // coreclr.dll!CCompRC::LoadString
- // coreclr.dll!CCompRC::LoadString
- // coreclr.dll!SString::LoadResourceAndReturnHR
- // coreclr.dll!SString::LoadResourceAndReturnHR
- // coreclr.dll!SString::LoadResource
- // coreclr.dll!EventReporter::EventReporter
- // coreclr.dll!EEPolicy::LogFatalError
- // coreclr.dll!EEPolicy::HandleFatalError
- if (pThread != NULL && !g_fFatalErrorOccuredOnGCThread)
- {
- // Switch to cooperative mode, since we'll be looking at managed objects
- // and we don't want them moving on us.
- GCX_COOP();
-
- CULTUREINFOBASEREF pCurrentCulture = (CULTUREINFOBASEREF)Thread::GetCulture(TRUE);
-
- if (pCurrentCulture != NULL)
- {
- STRINGREF cultureName = pCurrentCulture->GetName();
- _ASSERT(cultureName != NULL);
-
- if ((Result = ::LocaleNameToLCID(cultureName->GetBuffer(), 0)) == 0)
- Result = (int)UICULTUREID_DONTCARE;
- }
- }
-#endif
-
- if (Result == (int)UICULTUREID_DONTCARE)
- {
- // This thread isn't set up to use a non-default culture. Let's grab the default
- // one and return that.
-
- Result = COMNlsInfo::CallGetUserDefaultUILanguage();
-
- if (Result == 0 || Result == (int)UICULTUREID_DONTCARE)
- Result = GetUserDefaultLangID();
-
- _ASSERTE(Result != 0);
- if (Result == 0)
- {
- Result = (int)UICULTUREID_DONTCARE;
- }
-
- }
- *pLocale=Result;
- return Result;
-}
-#else
-// TODO: Callers should use names, not LCIDs
static int GetThreadUICultureId(__out LocaleIDValue* pLocale)
{
CONTRACTL{
return Result;
}
-#endif // FEATURE_USE_LCID
-
-
#ifdef ENABLE_CONTRACTS_IMPL
// Returns TRUE if any contract violation suppressions are in effect.
#ifndef DACCESS_COMPILE
extern void STDMETHODCALLTYPE EEShutDown(BOOL fIsDllUnloading);
-extern HRESULT STDAPICALLTYPE CoInitializeEE(DWORD fFlags);
extern void PrintToStdOutA(const char *pszString);
extern void PrintToStdOutW(const WCHAR *pwzString);
extern BOOL g_fEEHostedStartup;