Click here to Skip to main content
15,914,767 members
Home / Discussions / C#
   

C#

 
GeneralRe: Capturing VB6 event in C#.Net Pin
Paul Conrad30-Dec-07 6:41
professionalPaul Conrad30-Dec-07 6:41 
GeneralRe: Capturing VB6 event in C#.Net Pin
Michael Sync30-Dec-07 19:02
Michael Sync30-Dec-07 19:02 
GeneralRe: Capturing VB6 event in C#.Net Pin
Paul Conrad30-Dec-07 19:06
professionalPaul Conrad30-Dec-07 19:06 
GeneralInvoke function into mail body in an email Pin
zafax_30-Dec-07 0:12
zafax_30-Dec-07 0:12 
GeneralRe: Invoke function into mail body in an email Pin
Paul Conrad30-Dec-07 6:42
professionalPaul Conrad30-Dec-07 6:42 
GeneralRe: Invoke function into mail body in an email Pin
Skippums31-Dec-07 8:09
Skippums31-Dec-07 8:09 
GeneralRe: Invoke function into mail body in an email Pin
zafax_31-Dec-07 8:14
zafax_31-Dec-07 8:14 
QuestionTransferring arrays from C++ library to C# application Pin
Yooval29-Dec-07 22:28
Yooval29-Dec-07 22:28 
Hi,
I'm having trouble in transferring arrays of short integers from C++ library to C# application.
I got the sources of a library, written in C++, that defines interface in IDL file.
The original methods transfer "basic" objects, such as BOOL and BSTR.
I need to add a new method to the interface for transferring two arrays of short integers.
For that purpose, I create two safe arrays and populate them with the numbers.
However, when I try to invoke the C# method I get TypeMismatch error code (when I pass only the string objects, it works OK).

The C++ code includes the following definition in IDL file:
library CodecLib
{
...
dispinterface _ILiveEvents
{
properties:
methods:
...
[id(4), helpstring("method DataReady")] HRESULT DataReady([in] BSTR strForward, [in] SAFEARRAY(short) FwdBuffer,
[in] BSTR strReturn, [in] SAFEARRAY(short) RetBuffer);
};
...
};

The following C# code implements the interface defined in the IDL file:
private void DataReady(string sForward, Array ForwardData,
string sRetrun, Array ReturnData)
{
...
}

The following C++ code prepares the data in the safe arrays:
void CLive::DataReady(short *pFwdBuf, short *pRetBuf, int nBufferSize)
{
long lIndex;

SAFEARRAYBOUND ArrayBound[2];
ArrayBound[0].cElements = nBufferSize;
ArrayBound[0].lLbound = 0;
ArrayBound[1].cElements = nBufferSize;
ArrayBound[1].lLbound = 0;

m_pFwdBuffer = SafeArrayCreate(VT_I2, 1, &ArrayBound[0]);
m_pRetBuffer = SafeArrayCreate(VT_I2, 1, &ArrayBound[1]);

// Set data in safe arrays
for (lIndex=0; lIndex<nBufferSize; lIndex++)
{
SafeArrayPutElement(m_pFwdBuffer, &lIndex, &pFwdBuf[lIndex]);
SafeArrayPutElement(m_pRetBuffer, &lIndex, &pRetBuf[lIndex]);
}

// Send data to clients
Fire_DataReady(m_strForward, m_pFwdBuffer, m_strReturn, m_pRetBuffer);

// Release safe arrays
SafeArrayDestroy(m_pFwdBuffer);
SafeArrayDestroy(m_pRetBuffer);
m_pFwdBuffer = NULL;
m_pRetBuffer = NULL;
}

The following C++ code distributes the data to the clients.
However, calling Invoke() returns TypeMismatch error, with uArgErr equals to 3:
HRESULT Fire_DataReady(BSTR strForward, SAFEARRAY *pFwdBuf,
BSTR strReturn, SAFEARRAY *pRetBuf)
{
HRESULT hr = S_OK;
T * pThis = static_cast<T *>(this);
int cConnections = m_vec.GetSize();

for (int iConnection = 0; iConnection < cConnections; iConnection++)
{
pThis->Lock();
CComPtr<IUnknown> punkConnection = m_vec.GetAt(iConnection);
pThis->Unlock();

IDispatch * pConnection = static_cast<IDispatch *>(punkConnection.p);

if (pConnection)
{
CComVariant avarParams[4];
avarParams[0] = strForward;
avarParams[0].vt = VT_BSTR;
avarParams[1] = pFwdBuf;
avarParams[1].vt = VT_ARRAY;
avarParams[2] = strReturn;
avarParams[2].vt = VT_BSTR;
avarParams[3] = pRetBuf;
avarParams[3].vt = VT_ARRAY;

CComVariant varResult;
unsigned int uArgErr;

DISPPARAMS params = { avarParams, NULL, 4, 0 };
hr = pConnection->Invoke(4, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &params, &varResult, NULL, &uArgErr);
}
}
return hr;
}
GeneralRe: Transferring arrays from C++ library to C# application Pin
ashukasama31-Dec-07 4:56
ashukasama31-Dec-07 4:56 
Generalinserting image to database sqlserver Pin
yemen_programmer29-Dec-07 19:44
yemen_programmer29-Dec-07 19:44 
GeneralRe: inserting image to database sqlserver Pin
Michael Sync29-Dec-07 22:19
Michael Sync29-Dec-07 22:19 
GeneralArray of objects Pin
eric_tran29-Dec-07 19:27
eric_tran29-Dec-07 19:27 
GeneralRe: Array of objects Pin
Michael Sync29-Dec-07 22:24
Michael Sync29-Dec-07 22:24 
GeneralRe: Array of objects [modified] Pin
eric_tran30-Dec-07 0:07
eric_tran30-Dec-07 0:07 
GeneralRe: Array of objects Pin
Michael Sync30-Dec-07 5:33
Michael Sync30-Dec-07 5:33 
Generalproblem usinf usercontrol object in HTML page Pin
samy10029-Dec-07 14:32
samy10029-Dec-07 14:32 
GeneralRe: problem usinf usercontrol object in HTML page Pin
Michael Sync29-Dec-07 22:27
Michael Sync29-Dec-07 22:27 
AnswerRe: problem usinf usercontrol object in HTML page Pin
dipak.dipak30-Dec-07 2:19
dipak.dipak30-Dec-07 2:19 
GeneralRe: problem usinf usercontrol object in HTML page Pin
samy10030-Dec-07 11:39
samy10030-Dec-07 11:39 
GeneralBinding to a property Pin
peterchen29-Dec-07 14:30
peterchen29-Dec-07 14:30 
GeneralMySql & C# Question ... pulling data Pin
shadowhazard29-Dec-07 9:59
shadowhazard29-Dec-07 9:59 
GeneralRe: MySql & C# Question ... pulling data [modified] Pin
shadowhazard29-Dec-07 11:27
shadowhazard29-Dec-07 11:27 
GeneralRe: MySql & C# Question ... pulling data Pin
Justin Perez29-Dec-07 14:00
Justin Perez29-Dec-07 14:00 
GeneralRe: MySql & C# Question ... pulling data Pin
shadowhazard29-Dec-07 17:16
shadowhazard29-Dec-07 17:16 
GeneralRe: MySql & C# Question ... pulling data Pin
Mark Churchill30-Dec-07 15:59
Mark Churchill30-Dec-07 15:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.