Skip to content

Commit be8e486

Browse files
Improve wchar
1 parent 7efaa9c commit be8e486

File tree

1 file changed

+33
-4
lines changed

1 file changed

+33
-4
lines changed

runtime/src/CoreClr.cpp

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -369,31 +369,60 @@ bool CoreClr::PrintError(alt::IServer* server, int errorCode) {
369369
return false;
370370
}
371371

372+
#ifdef _WIN32
373+
const char_t *GetWC(const char *c)
374+
{
375+
const size_t cSize = strlen(c)+1;
376+
char_t* wc = new wchar_t[cSize];
377+
mbstowcs (wc, c, cSize);
378+
379+
return wc;
380+
}
381+
#endif
382+
372383
void CoreClr::CreateManagedHost(alt::IServer* server) {
373384
auto wd = server->GetRootDirectory().CStr();
374385
auto hostCfgPath = alt::String(wd) + HostCfg;
386+
const char_t* hostCfgPathCStr;
387+
#ifdef _WIN32
388+
hostCfgPathCStr = GetWC(hostCfgPath.CStr());
389+
#else
390+
hostCfgPathCStr = hostCfgPath.CStr();
391+
#endif
375392
auto hostDllPath = alt::String(wd) + HostDll;
393+
const char_t* hostDllPathCStr;
394+
#ifdef _WIN32
395+
hostDllPathCStr = GetWC(hostCfgPath.CStr());
396+
#else
397+
hostDllPathCStr = hostDllPath.CStr();
398+
#endif
399+
376400
auto hostExePath = alt::String(wd) + HostExe;
377-
auto load_assembly_and_get_function_pointer = get_dotnet_load_assembly(STR(hostCfgPath.CStr()));
401+
auto load_assembly_and_get_function_pointer = get_dotnet_load_assembly(hostCfgPathCStr);
378402
if (load_assembly_and_get_function_pointer == nullptr) {
379-
server->LogInfo(alt::String("coreclr-module: config:") + hostCfgPath.CStr());
403+
server->LogInfo(alt::String("coreclr-module: config:") + hostCfgPathCStr);
380404
server->LogInfo(alt::String("coreclr-module: host exe:") + hostExePath.CStr());
381405
return;
382406
}
383407

384408
int rc = load_assembly_and_get_function_pointer(
385-
STR(hostDllPath.CStr()),
409+
hostDllPathCStr,
386410
STR("AltV.Net.Host.Host, AltV.Net.Host"),
387411
STR("ExecuteResource"),
388412
nullptr /*delegate_type_name*/,
389413
nullptr,
390414
(void**) &ExecuteResourceDelegate);
391415

392416
if (ExecuteResourceDelegate == nullptr || rc != 0) {
393-
server->LogInfo(alt::String("coreclr-module: host path:") + hostDllPath);
417+
server->LogInfo(alt::String("coreclr-module: host path:") + hostDllPathCStr);
394418
PrintError(server, rc);
395419
return;
396420
}
421+
422+
#ifdef _WIN32
423+
delete[] hostCfgPathCStr;
424+
delete[] hostDllPathCStr;
425+
#endif
397426
}
398427

399428
void CoreClr::ExecuteManagedResource(alt::IServer* server, const char* resourcePath, const char* resourceName,

0 commit comments

Comments
 (0)