在VC++2005中使用Pwlib和Opal库,界面使用WinForm进行开发,编译选项为 /clr

编译、链接都没有问题,但启动程序时,出现运行时错误:


VC++2005 (CLI-C++) 中使用Pwlib和Opal时,运行时报错_CrtIsValidHeapPointer问题的解决!!


在网上搜了很久,发现很少有人提到该问题的解决办法,后来看到微软的论坛上,有人提出过这个bug,详情请看我的另外一篇文章:

The reason why you get this error is that a winforms application has a managed entry point. The initialization of the native global objects is done by the CRT (C RunTime) startup routine. Since in this case there is no CRT startup routine the MyBoard global object fails to initialize correctly.

VC++开发组的人给出了一种折中的办法,

1. Set Linker\Advanced\Entry Point to "" (empty string)
2. Set Linker\System\Subsystem to Not Set

Step 1: Makes sure that the CRT startup code is invoked. This is because, if no entry point is specified, the linker will automatically use mainCRTStartup, which is defined in the CRT libraries. mainCRTStartup will make sure that the global object is initialized correctly.

Step 2: Makes sure that the linker will look for the symbol “main”. The linker looks for “main” because mainCRTStartup calls main() in its body. The default option for a Winforms application is Subsystem:Windows and this makes the linker look for WinMain().



虽然程序可以正常启动,但是却会在程序显示Winform的同时,出现一个console窗口,很是不爽。

不服输的我,继续到处找资料,查找了几乎网上所有的资源,在微软的官方文档中,该问题被定义为 load lock,即CLI和CRT的初始化死锁问题,
详见 我的另外一篇文章:

ManagedWrapper.cpp,定义如下:

VC++2005 (CLI-C++) 中使用Pwlib和Opal时,运行时报错_CrtIsValidHeapPointer问题的解决!!// ManagedWrapper.cpp
VC++2005 (CLI-C++) 中使用Pwlib和Opal时,运行时报错_CrtIsValidHeapPointer问题的解决!!
VC++2005 (CLI-C++) 中使用Pwlib和Opal时,运行时报错_CrtIsValidHeapPointer问题的解决!!
// This code verifies that DllMain is not called by the Loader
VC++2005 (CLI-C++) 中使用Pwlib和Opal时,运行时报错_CrtIsValidHeapPointer问题的解决!!
// automatically when linked with /noentry. It also checks some
VC++2005 (CLI-C++) 中使用Pwlib和Opal时,运行时报错_CrtIsValidHeapPointer问题的解决!!
// functions that the CRT initializes.
VC++2005 (CLI-C++) 中使用Pwlib和Opal时,运行时报错_CrtIsValidHeapPointer问题的解决!!

VC++2005 (CLI-C++) 中使用Pwlib和Opal时,运行时报错_CrtIsValidHeapPointer问题的解决!!#include 
<windows.h>
VC++2005 (CLI-C++) 中使用Pwlib和Opal时,运行时报错_CrtIsValidHeapPointer问题的解决!!#include 
<stdio.h>
VC++2005 (CLI-C++) 中使用Pwlib和Opal时,运行时报错_CrtIsValidHeapPointer问题的解决!!#include 
<string.h>
VC++2005 (CLI-C++) 中使用Pwlib和Opal时,运行时报错_CrtIsValidHeapPointer问题的解决!!#include 
<stdlib.h>
VC++2005 (CLI-C++) 中使用Pwlib和Opal时,运行时报错_CrtIsValidHeapPointer问题的解决!!#include 
<math.h>
VC++2005 (CLI-C++) 中使用Pwlib和Opal时,运行时报错_CrtIsValidHeapPointer问题的解决!!#include 
"_vcclrit.h"
VC++2005 (CLI-C++) 中使用Pwlib和Opal时,运行时报错_CrtIsValidHeapPointer问题的解决!!
VC++2005 (CLI-C++) 中使用Pwlib和Opal时,运行时报错_CrtIsValidHeapPointer问题的解决!!#
using <mscorlib.dll>
VC++2005 (CLI-C++) 中使用Pwlib和Opal时,运行时报错_CrtIsValidHeapPointer问题的解决!!
using namespace System;
VC++2005 (CLI-C++) 中使用Pwlib和Opal时,运行时报错_CrtIsValidHeapPointer问题的解决!!
VC++2005 (CLI-C++) 中使用Pwlib和Opal时,运行时报错_CrtIsValidHeapPointer问题的解决!!
public ref class ManagedWrapper 
;

经过测试,一切OK!!!!

太爽了,终于可以抛开MFC那笨拙的界面开发工具!!
我现在可以充分利用Winform的快速界面开发功能,底层调用Pwli和Opal来开发视频会议了!

呵呵,我已经连续3天没有睡觉了,今晚终于可以做个好梦了!!

好开心!!!

相关文章:

  • 2021-07-04
  • 2021-07-31
  • 2022-12-23
  • 2021-06-22
  • 2021-07-07
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-01-14
  • 2022-12-23
  • 2021-11-07
  • 2021-05-07
  • 2022-12-23
  • 2021-06-23
  • 2021-07-26
相关资源
相似解决方案