小编Mar*_*ram的帖子

WndProc中的64位异常默默地失败

在Windows 7 32位下运行时,以下代码将导致硬故障:

void CTestView::OnDraw(CDC* /*pDC*/)
{
    *(int*)0 = 0; // Crash

    CTestDoc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);
    if (!pDoc)
        return;

    // TODO: add draw code for native data here
}
Run Code Online (Sandbox Code Playgroud)

但是,如果我在Windows 7 64bit上尝试这个,我只是在输出窗口中得到这个:

Test.exe中0x13929384处的第一次机会异常:0xC0000005:访问冲突写入位置0x00000000.
Test.exe中0x77c6ee42的第一次机会异常:0xC0150010:当前执行的线程未激活的激活上下文无效.

这是什么原因?我知道这是一个硬件异常(http://msdn.microsoft.com/en-us/library/aa363082.aspx),但为什么在32位和64位下运行时有区别?我能做些什么来正确处理这些错误?因为它们应该被捕获和修复,而不是目前发生的事情,Windows只是继续向应用程序发送消息并让它运行(因此用户和开发人员完全没有意识到实际发生了任何问题).

更新: 我们的常规崩溃报告软件使用SetUnhandledExceptionFilter但不会在x64上调用WndProc中的硬件异常.有没有人有关于此的任何信息,或解决方法?

Update2: 我在Microsoft Connect上报告了这个问题:https:
//connect.microsoft.com/VisualStudio/feedback/details/550944/hardware-exceptions-on-x64-machines-are-silently-caught-in-wndproc-消息

c++ windows 64-bit exception-handling seh

7
推荐指数
1
解决办法
3076
查看次数

内存分配给C++中的函数

我还是一个C++新手.刚刚开始读到类的静态成员函数不是特定于对象的 - 所有对象的成员函数都有一个副本.

现在我脑子里出现了两个问题:

  1. 普通函数和静态函数"仅在内存分配方面"有什么区别?

  2. 如果成员函数包含一些局部变量怎么办?在这种情况下,函数"应该"具有该变量的单独副本 - 特定于调用该函数的对象...如何在C++中解决此问题?

谢谢 !

c++ static function

7
推荐指数
1
解决办法
3780
查看次数

C++结构模板

我试图使用模板和结构,但它们不起作用.我搜索了很多,但我找不到解决方案.

#include <iostream>

using namespace std;

template<struct S>
int add(S s) {
    return s.num + s.num2;
}

int main() {

    struct {
        int num = 10;
        int num2 = 20;
    } test;

    cout << add(test) << endl;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

使用gcc时,错误是:

test.cpp:5:17: error: ‘struct S’ is not a valid type for a template non-type parameter
test.cpp: In function ‘int add(S)’:
test.cpp:6:5: error: ‘s’ has incomplete type
test.cpp:5:17: error: forward declaration of ‘struct S’
test.cpp: In function ‘int main()’:
test.cpp:13:19: warning: …
Run Code Online (Sandbox Code Playgroud)

c++ templates struct

7
推荐指数
2
解决办法
1万
查看次数

如何在Silverlight的组合框中为选定和下拉状态使用不同的模板?

我似乎无法为ComboBoxItem设置ContentTemplate.我试图这样做的原因是我希望在组合框中有2次出现我的数据.当组合框打开(菜单关闭)时,我想要一个文本框(带有图像名称)和它下面的图像控件.当我选择项目时,我希望组合框只显示一个带有图像名称的文本框.

我想我可以通过修改ComboBox的ItemTemplate和ItemContainerStyle来实现这一点.ItemContainerStyle包含以下ContentPresenter:

<ContentPresenter HorizontalAlignment="Left" Margin="{TemplateBinding Padding}" x:Name="contentPresenter" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}"/>
Run Code Online (Sandbox Code Playgroud)

所以我假设我可以在这里设置ContentTemplate,它会起作用.但我似乎无法让它工作:

<DataTemplate x:Key="ComboBoxDataTemplate">
            <Grid>
                <TextBlock Text="{Binding Path='Name'}"/>
            </Grid>
        </DataTemplate>

<DataTemplate x:Key="ComboBoxItemTemplate">
            <StackPanel>
                <TextBlock Text="{Binding Path='Name'}"/>
                <Image Source="{Binding Path='Source'}" Width="64" Height="64"/>
            </StackPanel>
        </DataTemplate>

        <Style x:Key="ComboBoxItemStyle1" TargetType="ComboBoxItem">
...
            <Setter Property="ContentTemplate" Value="{StaticResource ComboBoxItemTemplate}"/>

...
Run Code Online (Sandbox Code Playgroud)

这是我的组合框:

<ComboBox Width="70" Margin="3,0,0,0"
                        ItemsSource="{StaticResource Source}"
                        ItemTemplate="{StaticResource ComboBoxDataTemplate}"
                        ItemContainerStyle="{StaticResource ComboBoxItemStyle1}"
                        />
Run Code Online (Sandbox Code Playgroud)

我能让它工作的唯一方法是从ItemContainerStyle中删除ContentPresenter,并将其替换为我的自定义模板(ComboBoxItemTemplate)的内容.但我不认为我应该使用这种方法,因为它意味着ContentPresenter不再存在(ComboBox中的代码可能依赖于它存在).

任何有关显示具有不同下拉列表和选定模板的组合框的帮助将不胜感激!

.net silverlight wpf xaml combobox

6
推荐指数
1
解决办法
4349
查看次数

如何在Windows上发送邮件(MAPI除外)

查看MSDN MAPI文档页面时,它表示API现已弃用.如果是这种情况,这些天发送邮件的建议API是什么?

http://msdn.microsoft.com/en-us/library/dd296734.aspx

编辑:感谢所有的建议,管理的路线不适合我,因为我们正在使用MFC.

windows email mapi winapi

6
推荐指数
1
解决办法
3759
查看次数

不能包含Android NDK r5的STL头文件

我有一个非常简单的应用程序:

#include <vector>

void android_main(struct android_app* state)
{

}
Run Code Online (Sandbox Code Playgroud)

当我构建它时,我收到以下错误:

test/jni/main.c:14:18:错误:vector:没有这样的文件或目录

我该怎么包括STL头文件?我找到了stlport,我可以看到它的目录中存在头文件,但是如何包含它们呢?

编辑:我的Application.mk文件包含以下行:

APP_STL := stlport_static
Run Code Online (Sandbox Code Playgroud)

c++ android cygwin android-ndk android-ndk-r5

6
推荐指数
1
解决办法
4640
查看次数

在NativeActivity中创建OpenGL着色器

我已经调整了本机活动NDK示例以合并来自hello-gl2示例的OpenGL代码.我处理APP_CMD_INIT_WINDOW消息然后尝试创建着色器.着色器创建失败,我尝试通过getShaderInfoiv获取信息,但是它也会无声地失败.

所以我的问题是 - 如何在纯原生Android应用程序中创建OpenGL ES 2.0着色器?

PS我知道如果使用Java GLSurfaceView并且不在正确的线程中创建它们,则着色器创建可能会失败,但是查看本机活动示例,它似乎只有一个线程!

shader android native opengl-es-2.0

6
推荐指数
1
解决办法
3509
查看次数

模板类方法的专业化

假设我有以下课程:

template <typename T>
class MyClass
{
public:
    void SetValue(const T &value) { m_value = value; }

private:
    T m_value;
};
Run Code Online (Sandbox Code Playgroud)

如何为T = float(或任何其他类型)编写函数的专用版本?

注意:一个简单的重载是不够的,因为我只希望函数可用于T = float(即MyClass :: SetValue(float)在这个实例中没有任何意义).

c++ templates

6
推荐指数
1
解决办法
6293
查看次数

阻止显示Silverlight ListBox垂直滚动条

我有一个ListBox,显示可变高度的项目.我希望显示尽可能多的项目以适应可用空间,而不显示垂直滚动条.除了ListBox项目模板上的外科手术之外,有没有办法只显示不适合滚动的项目数量?

silverlight silverlight-2-rc0

5
推荐指数
1
解决办法
6630
查看次数

如何从自定义属性中确定附加类型?

我有一个可以分配给类的自定义属性[FooAttribute].我想在属性中做的是确定哪种类型实际使用了我.如果我有:

[FooAttribute]
public class Bar
{
}
Run Code Online (Sandbox Code Playgroud)

在FooAttribute的代码中,我如何确定添加了我的Bar类?我不是专门寻找Bar类型,我只是想用反射设置一个友好的名字.例如

[FooAttribute(Name="MyFriendlyNameForThisClass")]
public class Bar
{
}

public class FooAttribute()
{
  public FooAttribute()
  {
    // How do I get the target types name? (as a default)
  }
}
Run Code Online (Sandbox Code Playgroud)

.net c# reflection custom-attributes

5
推荐指数
1
解决办法
2151
查看次数