标签: variant

如何建立一个指向VARIANTs的SAFEARRAY指针?

我正在尝试使用以下方法的COM组件:

HRESULT _stdcall Run(
    [in] SAFEARRAY(BSTR) paramNames,
    [in] SAFEARRAY(VARIANT *) paramValues
    );
Run Code Online (Sandbox Code Playgroud)

如何在C/C++中创建paramValues数组?

c++ com variant safearray

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

boost ::变量用法

我正在通过wxWidgets开发GUI应用程序.它有两部分:GUI部分和"逻辑"部分.我希望Logic部分完全独立于wxWidgets.但GUI中的一个组件返回wxVariant,我需要在逻辑部分使用它.

所以我正在寻找一种方法将wxVariant"转换"为boost :: variant

wxVariant的工作原理如下:

wxVariant v("37");
int i = v.GetInteger(); //i==37
Run Code Online (Sandbox Code Playgroud)

所以我在想类似的东西

string s = methodReturningWxVariant().GetString();
boost::variant bV(s);

//later in code e.g
bV.GetInt();
bV.GetBool();
Run Code Online (Sandbox Code Playgroud)

可以像这样使用boost :: Variant(或boost :: Any)吗?

c++ variant boost-variant

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

如何从Delphi中的指针获取变量?

我需要能够将裸指针转换为变体.我知道指针指向一个变体,但我似乎无法将它取回.一个直接演员(我几乎认为)失败了:

Result := Variant(FAddress)^
Run Code Online (Sandbox Code Playgroud)

返回编译器错误:[DCC错误] E2089无效的类型转换

我也在搜索variants.pas单元,但没有任何东西跳出来.

显然我错过了一些东西.这样做的方法是什么?

delphi pointers variant

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

从PHP的COM的DOTNET类调用RNGCrypto

我试图通过COM层从PHP调用RNGCryptoServiceProvider-> GetBytes().我可以让它连接到类,但每次调用方法时,我都会得到两个错误之一(与参数有关).我认为GetBytes通过引用采用固定大小的字节数组这一事实是有原因的.由于PHP不支持固定大小的字符串,因此它很有趣:

错误1:

$util    = new \DOTNET(
    'mscorlib',
    'System.Security.Cryptography.RNGCryptoServiceProvider'
);
$data = new \Variant(str_repeat(chr(46), $size), VT_UI1 | VT_ARRAY);
$util->GetBytes($data);
Run Code Online (Sandbox Code Playgroud)

错误[0x80070057]参数不正确

这是由->GetBytes()线引起的.

如果我不使用变体,但只使用普通字符串,我仍然会得到相同的错误.

但是,如果我传入一个这样的数组:

$data = array('');
$util->GetBytes($data);
Run Code Online (Sandbox Code Playgroud)

参数0:类型不匹配.

所以我认为变量/字符串方法是正确的(因为它通过参数类型检查).但我无法弄清楚如何让它发挥作用.

方法C#接口是:

public override void GetBytes(
    byte[] data
)
Run Code Online (Sandbox Code Playgroud)

谢谢

.net php com reference variant

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

将<T>类型的值转换为Variant,是否可能?

这是一个片段,展示了我想要实现的目标:

type
  TMyObject<T> = class (TObject)
    function GetVarType(Value: T): TVarType;
  end;


function TMyObject<T>.GetVarType(Value: T): TVarType;
var
  TmpValue: Variant;
begin
  TmpValue := Variant(Value); //Invalid typecast
  Result := VarType(TmpValue);
end;
Run Code Online (Sandbox Code Playgroud)

我知道上面的类型转换是天真的,但我希望你能得到这个想法.我想用一些转换机制替换它.

TMyObject将始终是简单类型,如Integer,String,Single,Double.

这种转换的目的是函数VarType为每个我可以存储在其他地方的简单类型提供整数常量.

我想知道这种转换是否可行?

谢谢你的时间.

delphi generics delphi-2009 variant

6
推荐指数
2
解决办法
3416
查看次数

Boost变种失败了

我有这样的代码:

boost::variant<b2DistanceJointDef, b2FrictionJointDef,
       b2GearJointDef, b2MouseJointDef, b2PrismaticJointDef, b2PulleyJointDef,
       b2RevoluteJointDef, b2RopeJointDef, b2WeldJointDef, b2WheelJointDef> prmJointDef;

b2DistanceJointDef &prmDistaceJointDef = boost::get<b2DistanceJointDef>(prmJointDef);
Run Code Online (Sandbox Code Playgroud)

错误是:

source\Scene\Components\JointComponent.cpp:51:96: error: no matching function for call to 'get(boost::variant<b2DistanceJointDef, b2FrictionJointDef, b2GearJointDef, b2MouseJointDef, b2PrismaticJointDef, b2PulleyJointDef, b2RevoluteJointDef, b2RopeJointDef, b2WeldJointDef, b2WheelJointDef>&)'
\source\Scene\Components\JointComponent.cpp:51:96: note: candidates are:
boost/optional/optional.hpp:626:30: note: template<class T> typename boost::optional::reference_const_type boost::get(const boost::optional<T>&)
boost/optional/optional.hpp:634:24: note: template<class T> typename boost::optional::reference_type boost::get(boost::optional<T>&)
boost/optional/optional.hpp:644:30: note: template<class T> typename boost::optional::pointer_const_type boost::get(const boost::optional<T>*)
boost/optional/optional.hpp:652:24: note: template<class T> typename boost::optional::pointer_type boost::get(boost::optional<T>*)
Run Code Online (Sandbox Code Playgroud)

这里有什么不对?

c++ boost variant

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

将COM对象接口从C转换为Delphi

我试图将以下两个接口从C头文件转换为Delphi PAS单元,但在使用我自己做的那些时遇到了奇怪的问题.我需要帮助了解如何在Delphi中实现这些.

来自c头文件的源接口:

interface IParamConfig: IUnknown
{        
    HRESULT SetValue([in] const VARIANT* pValue, [in] BOOL bSetAndCommit);
    HRESULT GetValue([out] VARIANT* pValue, [in] BOOL bGetCommitted);
    HRESULT SetVisible(BOOL bVisible);
    HRESULT GetVisible(BOOL* bVisible);
    HRESULT GetParamID(GUID* pParamID);
    HRESULT GetName([out] BSTR* pName);
    HRESULT GetReadOnly(BOOL* bReadOnly);
    HRESULT GetFullInfo([out] VARIANT* pValue, [out] BSTR* pMeaning, [out] BSTR* pName, [out] BOOL* bReadOnly, [out] BOOL* pVisible);
    HRESULT GetDefValue([out] VARIANT* pValue);
    HRESULT GetValidRange([out] VARIANT* pMinValue, [out] VARIANT* pMaxValue, [out] VARIANT* pDelta);
    HRESULT EnumValidValues([in][out] long* pNumValidValues, [in][out] VARIANT* pValidValues,[in][out] BSTR* pValueNames);
    HRESULT ValueToMeaning([in] const …
Run Code Online (Sandbox Code Playgroud)

delphi com translation header variant

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

VBA:如何将Variant归零?

我有以下Variant:

Dim comboitems() As Variant
Run Code Online (Sandbox Code Playgroud)

我在所有代码中用作包含ComboBox控件值的数组.

在代码的某个点上,我需要清除/ empty/null comboitems().我能怎么做?我尝试了以下所有选项但没有成功.

comboitems = ""
comboitems = Null
comboitems = Nothing
Set comboitems = ""
Set comboitems = Null
Set comboitems = Nothing
comboitems() = ""
comboitems() = Null
comboitems() = Nothing
Set comboitems() = ""
Set comboitems() = Null
Set comboitems() = Nothing
Run Code Online (Sandbox Code Playgroud)

我得到的错误是这样的:

在此输入图像描述

vba variant

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

std :: variant并在GCC8中移动构造函数Bug

我有这段代码在GCC7.2,clang 7和MSVC中运行得非常好,但在GCC 8.0中没有.显然,它涉及复制构造函数......

#include <iostream>
#include <variant>
#include <memory>
#include <type_traits>

struct EmptyTree{};

struct Node {
    using node = std::unique_ptr<Node>;
    using Tree = std::variant<node, EmptyTree>;

    Node(int v) : value(v){}
    template<typename left, typename right>
    Node(int v, left &&l, right &&r) : value(v), left(std::move(l)), right(std::move(r)){}
    int value;
    Tree left = EmptyTree{};
    Tree right = EmptyTree{};
};

using Tree = Node::Tree;

auto make_node(int v) {
    return std::make_unique<Node>(v);
}

int main() {
    Tree a;
    a = Tree{make_node(5)};
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

用于测试代码的wandbox https://wandbox.org/permlink/Z8yXCen0fqbV3PDD

这是Gcc 8的错误还是我的代码中的错误? …

c++ variant c++17

6
推荐指数
0
解决办法
432
查看次数

为什么VS2017上的get_index实现失败?

巴里给我们这个华丽get_index的变种:

template <typename> struct tag { };

template <typename T, typename V>
struct get_index;

template <typename T, typename... Ts> 
struct get_index<T, std::variant<Ts...>>
    : std::integral_constant<size_t, std::variant<tag<Ts>...>(tag<T>()).index()>
{ };
Run Code Online (Sandbox Code Playgroud)

使用如下:

using V = variant<A, B, C>;
constexpr const size_t N = get_index<B, V>::value;  // 1
Run Code Online (Sandbox Code Playgroud)

它在Clang(OSX)中运行良好.

但在Visual Studio 2017中,我得到以下内容:

<source>(10): error C2039: 'index': is not a member of 'std::variant<tag<Ts>...>'
<source>(10): note: see declaration of 'std::variant<tag<Ts>...>'
<source>(11): note: see reference to class template instantiation 'get_index<T,std::variant<_Types...>>' being compiled …
Run Code Online (Sandbox Code Playgroud)

c++ variant visual-studio c++17 visual-studio-2017

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