我一直在努力编写一个从 c++ win32console 和 c++ dll 中提取的解决方案。我终于设法让他们在没有链接器错误的情况下交谈(所以我假设两者都是完全托管的 c++/CLI 项目)但是当我运行控制台时,我得到以下错误。
Company.Pins.Bank.Win32Console.exe 中 0x03f71849 处的未处理异常:0xC0000005:访问冲突写入位置 0x00000001。
控制台还显示以下内容
未处理的异常:System.NullReferenceException:对象引用未设置为对象的实例。在 c:...\win32console.cpp 中的 wmain: _wmainCRTStartup() 处的第 20 行
但我假设这是因为未处理的异常。
跟踪此错误以及在下面的代码块中执行返回时会发生错误。(返回链接的方法似乎可以通过,只是返回时似乎变坏了。)以防万一您没有注意到,我自己没有编写以下代码,它是由Visual Studio生成的。
#ifdef WPRFLAG
int wmainCRTStartup(
#else /* WPRFLAG */
int mainCRTStartup(
#endif /* WPRFLAG */
#endif /* _WINMAIN_ */
void
)
{
/*
* The /GS security cookie must be initialized before any exception
* handling targetting the current image is registered. No function
* using exception handling can be called in the current image until
* after __security_init_cookie has been called.
*/
__security_init_cookie();
return __tmainCRTStartup();
}
#include "stdafx.h"
#include "UInstruction.h"
#define DllExport __declspec(dllexport)
#define DllImport __declspec(dllimport)
using namespace System;
编辑:win32console.cpp 代码如下。
//int main(array<System::String ^> ^args)
int _tmain(int argc, _TCHAR* argv[])
{
auto P2 = (TCHAR *)"3 Barrowstead";
TCHAR* P3 = (TCHAR *)"3 Barrowstead";
double* P1;
P1[0] = 13;
UserInstruction(P1, P2, P3);
}