Hi all,
I am dot net new user.I am trying to use active x control from vc 6.0 in dot net.I have data marshaling problem in combination dot net and ocx from vc 6.0.
The following is the function in vc 6.0 ocx.Function name is myRetrieve Image.
BOOL CICACtrl::Retri eveImage(long iEventID, long iImageID, const VARIANT FAR& Image, short FAR* iWidth, short FAR* iHeight, short FAR* iDepth)
{
if(switchFlag == 0)
{
return false;
}
// TODO: Add your dispatch handler code here
TRY
{
TRY
{
LPCTSTR Address = "localhost" ;
LPCTSTR DBName = "TeleIntdb" ;
LPCTSTR UserName = "root";
//LPCTSTR PassWord = "cambridge" ;
LPCTSTR PassWord = "12345678";
//UINT Port = UINT(iPort);
UINT Port = 0;
m_connGetImg.Op en(Address, DBName, UserName, PassWord, Port);
}
CATCH(CSQLExcep tion, e)
{
//e->ReportError( );
return false;
}
END_CATCH;
int i;
long ImgIDArr[6] = {0,0,0,0,0,0};
CSQLResult res1(m_connGetI mg);
SQLValueArray arrValues1;
arrValues1.SetS ize(1); //number of columns
res1.QueryV(_T( "SELECT ImageID FROM ImageTbl WHERE EventImgID = %d"), iEventID);
i=0;
while (res1.Fetch(arr Values1))
{
ImgIDArr[i] = arrValues1.GetA t(0);
++i;
}
// check
if (iImageID > i)
{
m_connGetImg.Cl ose();
return false;
}
CSQLResult res(m_connGetIm g);
SQLValueArray arrValues;
arrValues.SetSi ze(1); //number of columns
unsigned char* buff;
SafeArrayAccess Data (Image.parray, (void**)&buff);
res.QueryV(_T(" SELECT Image FROM ImageTbl WHERE EventImgID = %d AND ImageID = %d"), iEventID, ImgIDArr[iImageID-1]);
while (res.Fetch(arrV alues))
{
memcpy(buff, arrValues.GetAt (0), arrValues.GetAt (0).m_nLength); //22035, 82726
}
SafeArrayUnacce ssData (Image.parray);
*iWidth = 10;
*iHeight = 10;
*iDepth = 10;
m_connGetImg.Cl ose();
return true;
}
CATCH(CSQLExcep tion, e)
{
//AfxMessageBox(" catch 2");
m_connGetImg.Cl ose();
//e->ReportError( );
return false;
}
END_CATCH;
}
The data type ( VARIANT FAR& ) is changed in RCW as System.Object.
I call this function in vb.net as
Private Sub Button3_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button3.Click
Dim image1 As New Object
Dim Img(3000000) As Byte
Dim w As Integer
Dim h As Integer
Dim d As Integer
Dim RetrieveImageRe tVal As Boolean
Dim EventID As Long
Dim ImageID As Long
Dim i As Integer
gdViewer1.Clear ()
gdViewer1.Close Picture()
EventID = CLng(TextBox4.T ext)
ImageID = CLng(TextBox5.T ext)
RetrieveImageRe tVal = AxICA1.Retrieve Image(EventID, ImageID, image1, w, h, d)
TextBox6.Text = w
TextBox7.Text = h
TextBox8.Text = d
Dim objMS As New MemoryStream()
Dim objBinaryFormat ter As New BinaryFormatter ()
objBinaryFormat ter.Serialize(o bjMS, image1)
Img = objMS.GetBuffer ()
Dim fs As FileStream
fs = New FileStream("c:\ ICATmpPic.jpg", FileMode.Create , FileAccess.Read Write)
For i = 0 To Img.Length - 1
fs.WriteByte(Im g(i))
Next
fs.Close()
gdViewer1.Displ ayFromFile("c:\ ICATmpPic.jpg")
End Sub
Error occured in call of RetrieveImage.
Width(w),Height (h) and Depth(d) is Ok but Image(image1) is not Ok.
What should I do.Please inform me about this problem.My email is kyawkoko.ko@gma il.com.