Attempted to split out the STA code from the rest of the build. This is a mess. MSBuild might not be sufficient here.
This commit is contained in:
parent
c01c676130
commit
9cd70d294a
|
@ -0,0 +1,35 @@
|
|||
// 25 november 2015
|
||||
#include "../windows/winapi.h"
|
||||
#include "../ui.h"
|
||||
|
||||
// If we don't set up the current thread otherwise, the first time .net tries to call out to unmanaged code, it will automatically set up a MTA for COM.
|
||||
// This is not what we want; we need a STA instead.
|
||||
// Since we're not in control of main(), we can't stick a [STAThread] on it, so we have to do it ourselves.
|
||||
// This is a separate .c file for two reasons:
|
||||
// 1) To avoid the unmanaged jump that a call to CoInitialize() would do (it seems to detect a call to CoInitialize()/CoInitializeEx() but let's not rely on it)
|
||||
// 2) To avoid mixing Windows API headers with .net
|
||||
// See also http://stackoverflow.com/questions/24348205/how-do-i-solve-this-com-issue-in-c
|
||||
|
||||
extern void initWPF(void);
|
||||
//extern void uninitWPF(void);
|
||||
|
||||
void wpfInit(void)
|
||||
{
|
||||
HRESULT hr;
|
||||
|
||||
// TODO https://msdn.microsoft.com/en-us/library/5s8ee185%28v=vs.71%29.aspx use CoInitializeEx()?
|
||||
hr = CoInitialize(NULL);
|
||||
if (hr != S_OK && hr != S_FALSE)
|
||||
DebugBreak();
|
||||
|
||||
// now do the rest of initialization on the managed side
|
||||
initWPF();
|
||||
}
|
||||
|
||||
/*TODO
|
||||
void uiUninit(void)
|
||||
{
|
||||
uninitWPF();
|
||||
CoUninitialize();
|
||||
}
|
||||
*/
|
17
wpf/wpf.cpp
17
wpf/wpf.cpp
|
@ -1,7 +1,4 @@
|
|||
// 24 november 2015
|
||||
#define UNICODE
|
||||
#define _UNICODE
|
||||
#include <windows.h>
|
||||
#include <vcclr.h>
|
||||
#define EXPORT __declspec(dllexport)
|
||||
#include "wpf.h"
|
||||
|
@ -61,25 +58,15 @@ void wpfWindowOnClosing(wpfWindow *w, void (*f)(wpfWindow *w, void *data), void
|
|||
|
||||
static gcroot<Application ^> app;
|
||||
|
||||
void wpfInit(void)
|
||||
// wpfInit() is in sta.c; see that or details.
|
||||
extern "C" void initWPF(void)
|
||||
{
|
||||
HRESULT hr;
|
||||
|
||||
// see http://stackoverflow.com/questions/24348205/how-do-i-solve-this-com-issue-in-c
|
||||
// we MUST be running STA
|
||||
// .net initializes as MTA for some stupid reason
|
||||
// TODO https://msdn.microsoft.com/en-us/library/5s8ee185%28v=vs.71%29.aspx use CoInitializeEx()?
|
||||
hr = CoInitialize(NULL);
|
||||
if (hr != S_OK && hr != S_FALSE)
|
||||
DebugBreak();
|
||||
|
||||
app = gcnew Application();
|
||||
}
|
||||
|
||||
void wpfRun(void)
|
||||
{
|
||||
app->Run();
|
||||
CoUninitialize();
|
||||
}
|
||||
|
||||
void wpfQuit(void)
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
<!-- DO NOT EDIT IN VISUAL STUDIO! -->
|
||||
|
||||
<!-- TODO go through all possible command line options and make sure the ones we want are enabled -->
|
||||
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
|
@ -38,17 +40,19 @@
|
|||
<LinkIncremental>false</LinkIncremental>
|
||||
<TargetName>libui</TargetName>
|
||||
<!-- TODO will these work from any directory? -->
|
||||
<OutDir>..\out</OutDir>
|
||||
<IntDir>..\.obj</IntDir>
|
||||
<OutDir>..\out\</OutDir>
|
||||
<IntDir>..\.obj\</IntDir>
|
||||
<EnableManagedIncrementalBuild>false</EnableManagedIncrementalBuild>
|
||||
<!-- <CustomBuildBeforeTargets>Link</CustomBuildBeforeTargets>-->
|
||||
<CustomBuildBeforeTargets>Link</CustomBuildBeforeTargets>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>EnableAllWarnings</WarningLevel>
|
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
<!-- <AdditionalOptions>additional compiler options %(AdditionalOptions)</AdditionalOptions>-->
|
||||
<!-- TODO there's a better way for this -->
|
||||
<!-- do not warn about unreferended parameters -->
|
||||
<AdditionalOptions>/wd4100</AdditionalOptions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
|
@ -57,8 +61,14 @@
|
|||
<!--TODO <MinimumRequiredVersion>600</MinimumRequiredVersion>-->
|
||||
<!-- <AdditionalOptions>additional linker options %(AdditionalOptions)</AdditionalOptions>-->
|
||||
</Link>
|
||||
<!-- TODO convert to a build rule -->
|
||||
<!-- TODO use /Wall instead of /W4 -->
|
||||
<CustomBuildStep>
|
||||
<Command>extra command</Command>
|
||||
<!-- TODO /MDd, /MTd, /EHa? -->
|
||||
<!-- TODO /RTC1 /RTCc /RTCs /RTCu /sdl -->
|
||||
<Command>cl sta.c /c /TC /analyze /bigobj /nologo /W4 /Wp64 /Zi /wd4100 /Fo$(IntDir)sta.obj</Command>
|
||||
<Inputs>sta.c</Inputs>
|
||||
<Outputs>$(IntDir)sta.obj</Outputs>
|
||||
</CustomBuildStep>
|
||||
</ItemDefinitionGroup>
|
||||
|
||||
|
@ -71,6 +81,8 @@
|
|||
<ClInclude Include="wpf.h" />
|
||||
|
||||
<ClCompile Include="wpf.cpp" />
|
||||
|
||||
<Link Include="$(IntDir)sta.obj" />
|
||||
</ItemGroup>
|
||||
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
|
|
Loading…
Reference in New Issue