Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Com 从Borland C+传递字符串数组+;到C# 我想把Borland C++的电子邮件地址字符串列表传递给我的C库。在我的C#代码下面。我可以调用PrintName()方法,它就可以工作了。现在我想打印电子邮件地址,但如果调用printma_Com_Borland C++ - Fatal编程技术网

Com 从Borland C+传递字符串数组+;到C# 我想把Borland C++的电子邮件地址字符串列表传递给我的C库。在我的C#代码下面。我可以调用PrintName()方法,它就可以工作了。现在我想打印电子邮件地址,但如果调用printma

Com 从Borland C+传递字符串数组+;到C# 我想把Borland C++的电子邮件地址字符串列表传递给我的C库。在我的C#代码下面。我可以调用PrintName()方法,它就可以工作了。现在我想打印电子邮件地址,但如果调用printma,com,borland-c++,Com,Borland C++,从Borland C+传递字符串数组+;到C# 我想把Borland C++的电子邮件地址字符串列表传递给我的C库。在我的C#代码下面。我可以调用PrintName()方法,它就可以工作了。现在我想打印电子邮件地址,但如果调用printmails()函数,什么都不会发生。您能建议我如何将多个电子邮件地址传递给C#lib吗 我将上面C库的TLB文件导入RAD Studio,我的C++侧代码如下: interface ITestConnector : public IUnknown

从Borland C+传递字符串数组+;到C#

我想把Borland C++的电子邮件地址字符串列表传递给我的C库。在我的C#代码下面。我可以调用PrintName()方法,它就可以工作了。现在我想打印电子邮件地址,但如果调用printmails()函数,什么都不会发生。您能建议我如何将多个电子邮件地址传递给C#lib吗

我将上面C库的TLB文件导入RAD Studio,我的C++侧代码如下:

interface ITestConnector  : public IUnknown
{
public:
  virtual HRESULT STDMETHODCALLTYPE PrintEmails(LPSAFEARRAY* emails/*[in,out]*/) = 0; // [-1]
  virtual HRESULT STDMETHODCALLTYPE PrintName(WideString name/*[in]*/) = 0; // [-1]
};


C++侧代码在我的例子中起作用。< /P>
SAFEARRAYBOUND saBound[1];

saBound[0].cElements = nElements;
saBound[0].lLbound = 0;

SAFEARRAY *pSA = SafeArrayCreate(VT_BSTR, 1, saBound);

if (pSA == NULL)
{
    return NULL;
}

for (int ix = 0; ix < nElements; ix++)
{
    BSTR pData = SysAllocString(elements[ix]);

    long rgIndicies[1];

    rgIndicies[0] = saBound[0].lLbound + ix;

    HRESULT hr = SafeArrayPutElement(pSA, rgIndicies, pData);

    _tprintf(TEXT("%d"), hr);
}
SAFEARRAYBOUND saBound[1];
saBound[0]。cElements=NeElements;
saBound[0].lLbound=0;
SAFEARRAY*pSA=SafeArrayCreate(VT_BSTR,1,saBound);
如果(pSA==NULL)
{
返回NULL;
}
对于(int ix=0;ix
SafeArrayCreate()调用与C代码不匹配。VT#u变量的安全数组应该是C#端的object[]。改用VT_BSTR。谢谢Hans。成功了。在回答部分看到我的C++侧。看起来你应该接受你的答案,而且你得到了我的答案,记录了解决方案。
TTestConnector *connector = new TTestConnector(this);

SAFEARRAYBOUND bounds[] = {{2, 0}}; //Array Contains 2 Elements starting from Index '0'
LPSAFEARRAY pSA = SafeArrayCreate(VT_VARIANT,1,bounds); //Create a one-dimensional SafeArray of variants
long lIndex[1];
VARIANT var;

lIndex[0] = 0; // index of the element being inserted in the array
var.vt = VT_BSTR; // type of the element being inserted
var.bstrVal = ::SysAllocStringLen( L"abc@xyz.com", 11 ); // the value of the element being inserted
HRESULT hr= SafeArrayPutElement(pSA, lIndex, &var); // insert the element

// repeat the insertion for one more element (at index 1)
lIndex[0] = 1;
var.vt = VT_BSTR;
var.bstrVal = ::SysAllocStringLen( L"pqr@xyz.com", 11 );
hr = SafeArrayPutElement(pSA, lIndex, &var);

connector->PrintEmails(pSA);
delete connector;
SAFEARRAYBOUND saBound[1];

saBound[0].cElements = nElements;
saBound[0].lLbound = 0;

SAFEARRAY *pSA = SafeArrayCreate(VT_BSTR, 1, saBound);

if (pSA == NULL)
{
    return NULL;
}

for (int ix = 0; ix < nElements; ix++)
{
    BSTR pData = SysAllocString(elements[ix]);

    long rgIndicies[1];

    rgIndicies[0] = saBound[0].lLbound + ix;

    HRESULT hr = SafeArrayPutElement(pSA, rgIndicies, pData);

    _tprintf(TEXT("%d"), hr);
}