我在.net2005 中C#建一个很简单的工程,就一个主窗体,主窗体上放了一个用vb写的控件,该控件已经注册,在我的开发环境中能编译后运行成功,弹出主窗体,但是拷贝到其他电脑(xp操作系统,开发环境也是xp)就会报无法获取“***"控件的窗口句柄,不支持无窗口的ActiveX控件错误,我在其他电脑上的控件也已经注册,请问是什么原因。

解决方案 »

  1.   

    怎么样用C#不注册调用C++写的DLL控件
    http://topic.csdn.net/u/20100524/23/6f1e41a3-a3ce-4a6c-8003-4a862631adff.html有两种方法:
    1、简单的方法是用配置清单来指定如何激活(免注册的)COM对象,步骤和例子见MSDN文章:
    Registration-Free Activation of COM Components: A Walkthrough
    2、另外一种是自己模拟COM激活的过程。ComClass都会导出DllGetClassObject 函数,自己DllImport并调用该函数,然后转换为COM接口。
      

  2.   

    窗口创建失败
    dllimort应用问题
      

  3.   

    编译环境: VS2008 
    编程语言:CSharp 
    系统版本:Windows7 
    OCX控件:无窗口的OCX控件    根据微软官方的说法,导致这个错误是由于Windows的保护机制,在编译后的exe的PE头部,有一个DEP(Data Execution Prevention)的功能。需要将这个功能关闭,就能正常运行了,我试了一把,果然如此。 附原文: The C# compiler in Visual Studio 2008 and the .NET 3.5 Framework (csc.exe) is now generating PE files with the NXCOMPAT bit set. What is that bit and who cares, you ask? You may very well care if your application interops with native binaries or exposes a plugin model to 3rd parties. First, some background...DEP is short for Data Execution Prevention. It is a technology that exists in Microsoft operating systems which prevents execution of code from memory pages which are not ed as executable. DEP exists to reduce the attack surface available to malicious software that is trying to hijack a process, and it has been acknowledged to be very helpful in that regard. In Windows Vista, the set of processes and applications to which DEP is applied is configurable by administrators, but there is also a role for application developers.In the header of a PE file there is a flag called IMAGE_DLLCHARACTERISTICS_NX_COMPAT. This flag affects whether or not the OS enables DEP for a process. Setting this flag tells the OS that the image is compatible with DEP. For executable images, if this flag is set, the process is run with DEP enabled unless the machine is configured with the DEP policy set to AlwaysOff. If the image is a DLL and the flag is set, the OS skips checking the DLL against a compatibility database which results in a small performance improvement. All of this applies to x86, 32-bit processes only. On a 64-bit OS, DEP is always enabled for 64-bit processes, but 32-bit processes are configured by the PE flag and system policy as described above. So how does one control the flag in the PE header?Since the C# compiler emits PE files which are MSIL only and therefore compatible with DEP, the output binaries from the VS 2008 and .NET 3.5 C# compilers have this flag set. Our expectation is that the vast majority of C# executables produced by these compilers will be part of a DEP-compatible application. For that reason we did not surface a compiler switch to configure the NXCOMPAT setting. Of course you can write a C# application that uses a native or mixed binary which is not compatible with DEP. Some ATL types in 7.1 and earlier used to do simple code generation into data pages which is a DEP no-no. If your application is generating IP_ON_HEAP exceptions, then you may need to clear the IMAGE_DLLCHARACTERISTICS_NX_COMPAT flag for your executable. To do this you can use EDITBIN.EXE from the VC toolset like so: editbin.exe /NXCOMPAT:NO If you're using Visual Studio, you can add a post build step to your executable's project. You'll need to setup the environment so that EDITBIN's dependencies can be resolved. Since the post build steps you author in Visual Studio's properties page are written into a batch file that is launched by the build process, you can use Visual Studio's VSVARS32.BAT to establish the right environment. My post build step looks like this:call $(DevEnvDir)..\tools\vsvars32.bat 
    editbin.exe /NXCOMPAT:NO $(TargetPath) If you sign the binary in Visual Studio, flipping the IMAGE_DLLCHARACTERISTICS_NX_COMPAT flag in the post build step after the binary has been signed will result in an assembly that will fail strong name validation. To work around this you'll need to begin signing your binary as part of the post build steps. To do this, use SN.EXE from the Windows SDK. The .NET 2.0 and VS 2005 compilers are also affected
    We like DEP so much that when you install .NET Framework 2.0 SP1 your C# compilers in VS 2005 and .NET Framework 2.0 will also begin to emit binaries with the IMAGE_DLLCHARACTERISTICS_NX_COMPAT bit set. This will undoubtedly surprise a few developers...download a framework service pack, recompile, run your app, and you're now getting IP_ON_HEAP exceptions. Obviously this is not ideal, but aggressively building a computing ecosystem filled with DEP-enabled applications and their accompanying security benefits is very beneficial to Windows users. If you begin to encounter IP_ON_HEAP exceptions after installing .NET Framework 2.0 SP1, you can use the same technique described above to clear the IMAGE_DLLCHARACTERISTICS_NX_COMPAT bit in VS 2005. The only difference I'm aware of is that the SDK (and therefore the location of SN.EXE) has moved. 
    原文链接地址: http://blogs.msdn.com/ed_maurer/archive/2007/12/14/nxcompat-and-the-c-compiler.aspx 本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/pendle/archive/2010/05/01/5548342.aspx
      

  4.   

    你好,楼主 ,我也碰到这个问题,在WIN7,VISTA,还有SP3都碰到这个问题,但是现在解决方案不让关闭DEP这个功能,说是会影响电脑安全,请问 你找到什么解决方案了吗
      

  5.   

    楼主参考一下这个吧http://blog.sina.com.cn/s/blog_6ca907a60100lxar.html