小编Muh*_*mar的帖子

C++在具有不同字符集的项目中链接错误

我在VS 2005中编译我的C++项目解决方案时遇到链接错误.以下是该场景.

我有一个解决方案,让我们说MySolution有2个项目名称

MyTestLib是一个静态库类型的项目,具有字符集Use Multi-Byte Character Set,没有CLR支持

MyTestApp是一个.exe应用程序使用上面的lib与字符集Use Unicode Character SetCLR支持

MyTestLib没有与下面的定义两个重载函数

int Class1::test1(int a)
{
    return a+4; 
}

bool Class1::test1(LPCTSTR param)
{
    return true;
}
Run Code Online (Sandbox Code Playgroud)

MyTestApp 从它的代码中调用它们

Class1 objcl1;
int a = objcl1.test1(12); //Works fine

Class1 objcl2;
string abc = "adsad";
bool t = objcl2.test1(abc.c_str()); //Error
Run Code Online (Sandbox Code Playgroud)

调用test1(LPCTSTR)版本会出错

Error 1 error C2664: 'int TestLib::Class1::test1(int)' : cannot convert parameter 1 from 'const char *' …

c++ exe character-encoding

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

ListBox SelectedItem绑定已损坏

我正在使用SelectedItem数据绑定的WPF一个奇怪的问题RadListBox,试图找出但没有运气.以下是我的情景

  1. 我正在使用TelerikControls(RadListBox,和RadButton)
  2. RadButton放在一个内部ItemsControl,RadListBoxItemsControl绑定到同一个ItemsSource.
  3. 我正在使用PRISMMVVM.
  4. 我想要的是当我点击按钮时,RadListBox自动选择相同的项目,(这部分工作正常).
  5. 问题:只要我点击任何项目,RadListBox然后单击任何按钮,项目选择就会停止工作.
  6. 编辑:我尝试使用标准WPF ListBox通过为选择更改事件和Command和CommandParameter的附加属性添加附加行为来做同样的事情,它工作正常,所以它看起来像Telerik的问题RadListBox

现在让我来编码.

ViewModel类

public class MainViewModel : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;

    // Create the OnPropertyChanged method to raise the event 
    protected void OnPropertyChanged(string name)
    {
        PropertyChangedEventHandler handler = PropertyChanged;
        if (handler != null)
        {
            handler(this, new PropertyChangedEventArgs(name));
        }
    } …
Run Code Online (Sandbox Code Playgroud)

data-binding wpf prism telerik mvvm

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

WPF中的DataValidation使用ValidatesOnExceptions

我想在WPF中使用运行基本数据验证示例ValidatesOnException,但它根本不起作用,并且一旦我viewmodel抛出ValidationException,我的程序崩溃说,ValidationException未被用户代码处理.

我的视图模型是

public class MainViewModel : INotifyPropertyChanged
{
    //INotifyPropertyChaned implementation
    //////////////////////////////////////
    private string stringValue;

    public string StringValue
    {
        get { return stringValue; }
        set
        {
            if (value.Length > 6)
            {
                //The below line throws unhandled exception error??
                throw new ValidationException(String.Format("Value's length is greater than {0}.", value.Length));
            }
            stringValue = value;
            this.OnPropertyChanged("StringValue");
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我的XAML是

<StackPanel x:Name="LayoutRoot" Background="White">
<TextBox x:Name="radMaskedTextInput1" 
                                Width="200"
                                Margin="10"
                                Text="{Binding Path=StringValue, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True, UpdateSourceTrigger=PropertyChanged}" />
</StackPanel>
Run Code Online (Sandbox Code Playgroud)

data-binding validation wpf exception-handling exception

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

使用删除时引发错误Debug Assertion失败_BLOCK_TYPE_IS_VALID

我在C++中尝试一个简单的代码,但是Debug Assertion Failed _BLOCK_TYPE_IS_VALID当我删除指针时出现错误.我不知道我错了什么.这是我的代码.

hash_map<string,string> m_hashDetails;
    m_hashDetails.insert(hash_map<string,string>::value_type("test",*(new string("test123"))));


    hash_map<string,string>::iterator myIterator;
    myIterator = m_hashDetails.find("test");
    if(myIterator == m_hashDetails.end())
    {
        printf("not found");
    }
    else
    {
        printf(myIterator->second.c_str());
        //this is where I get Debug Assertion Failed _BLOCK_TYPE_IS_VALID
        delete &(myIterator->second);
    }
Run Code Online (Sandbox Code Playgroud)

当我删除我得到错误的second字段.我错了什么?我用运营商分配了这个字段?有一件事我注意到,如果我将hash_map定义更改为 并插入类似的值hash_mapDebug Assertion Failed _BLOCK_TYPE_IS_VALIDsecondnewhash_map<string,string *> m_hashDetails;

m_hashDetails.insert(hash_map<string,string>::value_type("test",new string("test123")));
Run Code Online (Sandbox Code Playgroud)

然后delete不给出错误..并且工作正常?这个错误的实际原因是什么?

c++ assertions new-operator delete-operator

0
推荐指数
1
解决办法
3689
查看次数